Element-ui表格跨页勾选
<el-table
ref="table"
:data="dataList"
row-key="primaryKey"
@select="select"
@select-all="selectAll"
>
data () {
return {
selectedRowsTransPage: [], // 跨分页勾选
dataList: [],
}
},
methods: {
/** 翻页之后将跨页选中的行同步勾选,在qrydata(param).then()里调用,保证每次都同步 */
syncSelectRows() {
for(let i in this.dataList) {
if (this.selectedRowsTransPage.indexOf(this.dataList[i].primaryKey)!==-1){
this.$nextTick(()=>{
this.$refs.table.toggleRowSelection(this.dataList[i], true)
})
}
else {
this.$nextTick(()=>{
this.$refs.table.toggleRowSelection(this.dataList[i], false)
})
}
}
},
select(selection,row) {
if(this.selectedRowsTransPage.indexOf(row.primaryKey)===-1) {
this.selectedRowsTransPage.push(row.primaryKey)
}
else {
this.selectedRowsTransPage.splice(this.selectedRowsTransPage.indexOf(row.primaryKey),1)
}
},
selectAll(selection) {
let rowDataNo = this.dataList.map(item => item.primaryKey)
let selectionNo = selection.map(item => item.primaryKey)
for (let i in rowDataNo) {
if (selectionNo.indexOf(rowDataNo[i])!==-1
&&this.selectedRowsTransPage.indexOf(rowDataNo[i])===-1) {
this.selectedRowsTransPage.push(rowDataNo[i])
}
else if (selectionNo.indexOf(rowDataNo[i])===-1
&&this.selectedRowsTransPage.indexOf(rowDataNo[i])!==-1) {
this.selectedRowsTransPage.splice(this.selectedRowsTransPage.indexOf(rowDataNo[i]),1)
}
}
},
}
每次搜索、重置、批量操作成功后都要清selectedRowsTransPage
this.selectedRowsTransPage = []