官方给的解释是:选择框的默认属性配置
官方要求的参数是一个方法
看一个官方示例:
getCheckboxProps: (record: DataType) => {
console.log("getCheckboxProps",record)
return {
disabled: record.name === 'Disabled User', // Column configuration not to be checked
name: record.name,
}},
我们这里的console.log出来可以看到就是记录的当前表格的每一行的数据
再结合一下示例,就能知道,这几行代码的意思就是,每一行checkBox的name参数与表格中对应行数据的name参数一致,且当表格中对应行数据的name为'Disabled User'
时,checkbox设为不可用
所以总结来说,是为了配置CheckBox的默认属性
这句话描述的非常准确,只是我们可能看不太懂而已
需求
写一个表格,表格中的条目,当其属性disable为true的时候,checkbox也给它禁用掉,请问怎么做?
方案
const rowSelection = {
getCheckboxProps: (record: DataType) => {
return {
disabled: record.disable, // Column configuration not to be checked
name: record.name,
}},
};