当前开发场景:单页表格
<el-table :data="tableData" @selection-change="handleSelect" ref="elTable">
<el-table-column type="selection"/>
</el-table>
设置好属性,在确保表格已经渲染完成的情况下,做如下操作
let list = []
this.tableData.forEach((row) => {
if (true) {/*筛选条件*/
list.push(row)
}
})
if (list.length != 0) {
list.forEach((row) => {
this.$refs.elTable.toggleRowSelection(row, true)/*选中数据*/
})
}
遍历筛选表格数据,调用方法选中,同时会触发事件
handleSelect(val) {
console.log("当前选择:")
console.log(val)
}
可在此进行逻辑处理,顺便提一下禁用选项的方法
<el-table-column type="selection" :selectable="displayAble" />
通过selectable属性的回调判断
displayAble(row,index) {
}
需要return布尔值