想要实现table checkbox 分页选中记忆功能,网上看了很多,总是有一些小问题.
自己写了一个demo,供大家参考.
思路是:把选中的数据用二维数组记录下来,二位数组的key是页码,value是当前页码选中数据的id集合.每次点击
下面附上代码
template模板:
<el-table :data="tableData" style="width: 100%" border
empty-text="暂无数据" @select="checkedList"
@select-all="checkedList" ref="multipleTable">
<el-table-column type="selection" width="40"></el-table-column>
<el-table-column prop="indexNum" label="序号"></el-table-column>
<el-table-column prop="name" label="名称"></el-table-column>
</el-table>
data 数据
dossierSelectId:[],//选中表格数据
pageIndex:1,//当前页码
js 代码
//选中或者反选
checkedList(val){
console.log(val);
this.dossierSelectId[0]=[];
this.dossierSelectId[this.pageIndex]=[];
if(val.length>0) {
val.forEach(item => {
this.dossierSelectId[this.pageIndex].push(item.id);
});
console.log(this.dossierSelectId);
}
},
//每次翻页后根据数据
toggleSelection(rows){
console.log(rows);
if(rows){
rows.forEach(row=>{
this.$refs.multipleTable.toggleRowSelection(row);
})
}else{
this.$refs.multipleTable.clearSelection();
}
},