应用到一个api getCheckboxProps
效果图:
只允许勾选状态为 ‘使用中’ 的数据
代码:
注意:涉及勾选一定要定义rowKey唯一值
<a-table
ref="table"
size="middle"
:scroll="{x:true}"
bordered
:rowKey="rowKey"
:columns="columns"
:dataSource="dataSource"
:pagination="ipagination"
:loading="loading"
:rowSelection="rowSelection"
class="j-table-force-nowrap"
@change="handleTableChange">
</a-table>
computed: {
rowSelection() {
return {
selectedRowKeys: this.selectedRowKeys,
onChange: this.onSelectChange,
getCheckboxProps: record => ({
props: {
// 这里的'使用中'的crowdStatus为'2'
disabled: record.crowdStatus != '2'
}
}),
}
},
},
跨行勾选:
onSelectChange (selectedRowKeys, selectionRows) {
this.selectedRowKeys = selectedRowKeys;
const arr = Array.from(new Set([...this.selectionRows, ...selectionRows]))
const list = this.selectedRowKeys.map(item => arr.filter(aItem => aItem[this.rowKey] == item)[0])
this.selectionRows = list
},