![](/img/trans.png)
[英]How to dynamically disable a row's checkbox in react-bootstrap-table2?
[英]For react-bootstrap-table2, how do you default all the checkbox items to selected?
如果我有一个数据项表,并且我想选中所有复选框?
以此类推,当页面加载并显示表格时,应选中所有带有复选框的表格项目。
<BootstrapTable selectRow={{ mode: 'checkbox', clickToSelect: true}} />
经过一番挖掘,我找到了答案。
react-bootstrap-table2 有一个 function...selectRow.onSelectAll - [功能]
const selectRow = {
mode: 'checkbox',
onSelectAll: (isSelect, rows, e) => {
if (isSelect && SOME_CONDITION) {
return [1, 3, 4]; // finally, key 1, 3, 4 will being selected
}
}
};
onSelectAll = ( isSelected ) => {
if ( isSelected ) {
return this.props.myReducer.myDataItems.map( row => row.DATA_TABLE1 );
} else {
return [];
}
}
然后 selectRow.selected - [Array] selectRow.selected 允许您在表上进行默认选择。 我使用了这个 function 并传入 'isSelected: true'
<BootstrapTable
classes={styles.myDataGrid}
striped hover
keyField="DATA_TABLE1"
data={invalidCrashes}
selectRow={{ mode: 'checkbox', clickToSelect: true, selected: this.onSelectAll( {
isSelected: true } ) }}
/>
传入 'isSelected: true' 默认所有复选框呈现为 'selected'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.