element 跨分页操作选择

9 篇文章 0 订阅

业务需求:在批量导出或者批量删除的时候 会涉及到跨分页导出或者批量删除 这是你会发现 当你选择后 点击分页 发现之前选择的数据已经没有了 现在就是要满足分页点击分页后 原始数据保留

<template>
    <div>
        <el-table
            :data="tableData"
            tooltip-effect="dark"
            style="width: 100%;"
            header-align="left"
            border
            ref="table"
            row-key="serviceDateId"
            @selection-change="handleSelectionChange"
            @row-dblclick="toDetail"
            @sort-change="sortChange"
        >
        <el-table-column type="selection" el-table-column width="50" fixed="left"></el-table-column>
        <el-table-column label="序号" width="80" fixed="left">
            <template slot-scope="{row,$index}">
                <span>{{$index + 1}}</span>
            </template>
        </el-table-column>
        <el-table-column label="服务日期" prop="serviceDate"  sortable="custom" min-width="120" ></el-table-column>
        <el-table-column label="服务对象" prop="vsoName" min-width="120"></el-table-column>
        <el-table-column label="身份证号" prop="idCard" sortable="custom" min-width="200"></el-table-column>
        <el-table-column label="服务内容" prop="serviceContentName" min-width="200"></el-table-column>
        <el-table-column label="服务结果" prop="serviceResultName" min-width="100"></el-table-column>
        <el-table-column label="志愿者" prop="volunteerName" sortable="custom"  min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="志愿者所属组织" prop="objName" min-width="200" show-overflow-tooltip></el-table-column>
        <el-table-column fixed="right" label="操作" width="150" header-align="center">
            <template slot-scope="{row,$index}">
                <span @click="handleEdit(row)" class="table-btn" v-has="{class: '编辑'}">编辑</span>
                <span @click="handleRemove($index, row)" class="table-btn"
                    v-has="{class: '删除'}">删除</span>
            </template>
        </el-table-column>
    </el-table>
    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="form.pageNum"
        :limit.sync="form.pageSize"
        @pagination="getData(form)"
    />
    </div>
</template>
<script>
export default {
    data(){
        return{
            ruleForm: {
                username: '',
                password:''
            },
            form: {
                pageNum: 1, // 分页页数
                pageSize: 10, // 分页数量
            },
            multipleSelection: [], //多选的行数据
            multipleSelectionAll:[],// 当前页选中的数据
            idKey: 'idCard',
        }
    },
    methods: {
      setSelectRow() {
            if (!this.multipleSelectionAll || this.multipleSelectionAll.length <= 0) {
                return;
            }
            // 标识当前行的唯一键的名称
            let idKey = this.idKey;
            let selectAllIds = [];
            let that = this;
            this.multipleSelectionAll.forEach(row=>{
                selectAllIds.push(row[idKey]);
            })
            this.$refs.table.clearSelection();
            for(var i = 0; i < this.tableData.length; i++) {   
                if (selectAllIds.indexOf(this.tableData[i][idKey]) >= 0) {
                // 设置选中,记住table组件需要使用ref="table"
                    this.$refs.table.toggleRowSelection(this.tableData[i], true);
                }
            }
        },
            // 记忆选择核心方法
        changePageCoreRecordData () {
            // 标识当前行的唯一键的名称
            let idKey = this.idKey;
            let that = this;
            //如果总记忆中还没有选择的数据,那么就直接取当前页选中的数据,不需要后面一系列计算
            if (!this.multipleSelectionAll.length) {
                this.multipleSelectionAll = this.multipleSelection;
                return;
            }
            // 总选择里面的key集合
            let selectAllIds = [];
            this.multipleSelectionAll.forEach(row=>{
                selectAllIds.push(row[idKey]);
            })
            let selectIds = []
            // 获取当前页选中的id
            this.multipleSelection.forEach(row=>{
                selectIds.push(row[idKey]);
                // 如果总选择里面不包含当前页选中的数据,那么就加入到总选择集合里
                if (selectAllIds.indexOf(row[idKey]) < 0) {
                    that.multipleSelectionAll.push(row);
                }
            })
            let noSelectIds = [];
            // 得到当前页没有选中的id
            this.tableData.forEach(row=>{
                if (selectIds.indexOf(row[idKey]) < 0) {
                    noSelectIds.push(row[idKey]);
                }
            })
            noSelectIds.forEach(id=>{
                if (selectAllIds.indexOf(id) >= 0) {
                    for(let i = 0; i< that.multipleSelectionAll.length; i ++) {
                        if (that.multipleSelectionAll[i][idKey] == id) {
                        // 如果总选择中有未被选中的,那么就删除这条
                        that.multipleSelectionAll.splice(i, 1);
                        break;
                        }
                    }
                }
            })
        },
        // 多选的行数据
        handleSelectionChange(val) {
            this.multipleSelection = val
                setTimeout(()=>{
            this.changePageCoreRecordData();
            }, 50)
        },
        // 获取表格数据
        getData(form) {
            let parmas = _.cloneDeep(form);
            parmas.liveArea = typeof(parmas.liveArea) === 'object'?parmas.liveArea.join(''):parmas.liveArea;
            recordSearch(form).then(res => {
                if (res.rows) {
                    this.tableData = res.rows;
                    this.total = res.total;
                    this.exportData = _.cloneDeep(form);
                    setTimeout(()=>{
                        this.setSelectRow();
                    }, 50)
                }
                else {
                    this.tableData = [];
                    this.total = 0;
                }
            })
        }
    },
    mounted(){
        this.getData(this.form)
    }
}
</script>
<style lang="sass" scoped>
    
</style>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Element UI是一套基于Vue.js的桌面端组件库,提供了丰富的UI组件,其中包括分页组件。分页组件可以实现对大量数据进行分页展示和快速导航的功能。根据引用中的描述,element ui分页多选,翻页记忆的实例可以实现在分页时进行多项选择,并且在翻页时能够记住之前已选择的项,具有很好的参考价值。根据引用中的描述,分页可以采用前端分页和后端分页两种方式。前端分页是指在前端一次请求获取所有数据后进行分页处理,适用于数据量不大的情况。后端分页是指在每次点击分页时,向后端请求分页数据,避免一次性获取大量数据,适用于数据量较大的情况。Element UI提供了相应的API和样式,可以方便地实现分页功能。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [element ui分页多选,翻页记忆的实例](https://download.csdn.net/download/weixin_38589168/12937648)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [elementUI实现分页](https://blog.csdn.net/m0_49993061/article/details/108875130)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沫熙瑾年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值