gpt4 book ai didi

javascript - 如何在react-bootstrap-table中选择所有带分页的原始数据?

转载 作者:行者123 更新时间:2023-11-28 04:01:24 25 4
gpt4 key购买 nike

import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
export default class StudentTable extends React.Component {


render() {
const selectRowProp = {
mode: 'checkbox'
};

return (
<BootstrapTable ref='table' data={ this.state.studentData } selectRow={ selectRowProp } pagination>
<TableHeaderColumn dataField='id' isKey={ true }>Student ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Student Name</TableHeaderColumn>
<TableHeaderColumn dataField='city'>City</TableHeaderColumn>
</BootstrapTable>
);
}
}

当我实现时,它在表中显示分页,并在所有原始数据中显示复选框以供选择。

但是当我点击全选时,它只会选择当前页面大小的记录。当我从分页控件转到下一页时,其他记录不会被选择。

我想在单击全选复选框时选择所有记录。我该怎么做?

最佳答案

我从 Here 找到了解决方案

import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
export default class StudentTable extends React.Component {
onSelectAll = (isSelected) => {
if (isSelected) {
return this.state.studentData.map(row => row.id);
} else {
return [];
}
}

render() {
const selectRowProp = {
mode: 'checkbox',
onSelectAll: this.onSelectAll
};

return (
<BootstrapTable ref='table' data={ this.state.studentData } selectRow={ selectRowProp } pagination>
<TableHeaderColumn dataField='id' isKey={ true }>Student ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Student Name</TableHeaderColumn>
<TableHeaderColumn dataField='city'>City</TableHeaderColumn>
</BootstrapTable>
);
}
}

关于javascript - 如何在react-bootstrap-table中选择所有带分页的原始数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47090251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com