vue 表格分页选中数据

vue iview 表格分页选中数据

项目引入lodash

import _ from 'lodash';
<Table border ref="table"
                       :columns="resultTitle"
                       @on-selection-change="selectedChange"
                       @on-select="handleSelect"
                       @on-select-cancel="handleCancel"
                       @on-select-all-cancel="handleCancelSelectAll"
                       @on-select-all="handleSelectAll"
                       :data="statData"
                       style="margin-bottom: 20px">
</Table>
data(){
	return{
		selectedData: [],
		selected: [],
	}	
}
methods:{
			// 表格选中数据
            selectedChange(selection) {
                this.selectedData = selection;
            },
            // 取消选中
            handleCancel(selection, row) {
                //从已选项中去除取消项
                _.remove(this.selected, n => {
                    return n.id === row.id;
                });
            },
            // 选中
            handleSelect(selection, row) {
                //添加到已选项
                this.selected.push(row);
            },
            // 全选
            handleSelectAll(selection) {
                //数组合并,有可能用户先选择了某几项,已经被我们push进去,因此数组合并需要去重一下
                this.selected = _.uniqBy(this.selected.concat(selection), "id");
            },
            // 取消全选
            handleCancelSelectAll(selection) {
                //从已选项中移除当页数据
                this.selected = _.differenceBy(this.selected, this.statData, "id");
            },
            //把源数据加上_checked字段,遍历已选项数据,更新选中状态
            updateChecked() {
                for (var i = 0; i < this.statData.length; i++) {
                    this.statData[i]._checked = false;
                    for (var j = 0; j < this.selected.length; j++) {
                        if (this.selected[j].id === this.statData[i].id) {
                            this.statData[i]._checked = true;
                        }
                    }
                }
            },
            // 重复检测取值
            getRepeatNum() {
                if (this.selected.length != 0) {
                   console.log(this.selected)
            },
}		
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值