选不中原因分析:row-key对应的是列表里的对象,勾选的是咱们自己传的,表格认为你传回的 选中集合跟列表row的对象不是同一个
解决方案: 用传入的数据与表格数据比对然后在进行回显
如果是动态数据也要回显,需要设置row-key与:reserve-selection=“true”
// listData 表格数据----数组
// array 传入数据----数组
<el-table
:data="listData"
:height="tableHeight"
ref="multipleTable"
class="order-table"
size="mini"
style="width: 100%"
v-if="listData.length"
stripe
row-key="emplOaAccount"
@selection-change="handleSelectionChange">
<el-table-column
type="selection"
:reserve-selection="true"
align="center"
width="40">
</el-table-column>
<el-table-column
type="index"
:index="indexMethod"
width="50"
label="序号"
align="center"
></el-table-column>
</el-table>
toggleSelection(array) { // 设置默认选中
this.$refs.multipleTable.clearSelection()
array.length && this.listData.forEach(row => {
if (array.some(item => item.emplOaAccount === row.emplOaAccount)) {
// 判断回传的数组与表格数据是不是同一个对象
this.$nextTick(() => {
this.$refs.multipleTable.toggleRowSelection(row, true)
})
}
})
}
多级表头固定导致显示不全:
解决方法:只要涉及到多级表头左固定或者右固定,必须设置宽度,不然展示不全