[英]For react-bootstrap-table2, how do you default all the checkbox items to selected?
[英]How to dynamically disable a row's checkbox in react-bootstrap-table2?
您可以创建一个函数来为您以编程方式生成 nonSelectable 数组。 例如
function getNonSelectableRows(rows, userLoginId) {
return rows
.filter((r) => r.createdByID !== userLoginId)
.reduce((acc, r) => {
acc.push(r.fileID);
return acc;
}, []);
}
然后调用 selectRow.nonSelectable 的函数
function App() {
...
// I don't see the user login id in your code.
// Thus I just add it as a constant at the top.
const userLoginId = '200201';
const [files] = useState([
{
fileID: 1,
fileName: "Cardio Care Awareness Month",
createdByID: "100101"
},
{
fileID: 2,
fileName: "MEMO COMPULSORY TO",
createdByID: "100101"
},
{
fileID: 3,
fileName: "MEMO 2021 Covid19 Vaccination Leave",
createdByID: "200201"
},
{
fileID: 4,
fileName: "Human Cell",
createdByID: "200201"
}
]);
const selectRow = {
mode: "checkbox",
// nonSelectable = [1, 2]
nonSelectable: getNonSelectableRows(files, userLoginId),
...
<BootstrapTable
keyField='id'
columns={columns}
rowStyle={rowStyle}
data={data}
/>
const rowStyle = (row) => {
if (row.your_col_name=== 'your_condition') {
return { backgroundColor: 'gray', color: '#999999', pointerEvents: 'none', cursor: 'not-allowed' };
}
return {};
};
这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.