react使用antd组件,实现表格的跨页多选和全选

React antd table组件中的跨页选择记录解决方案

首先要求定义好rowSelection:
const rowSelection = {
selectedRowKeys, selectedRows,
onSelect: (record:TableListItem , selected:boolean) => {
let arr = [];
let list = [];
if (selected) {
arr = Array.from(new Set([…selectedRowKeys, record.id]));
list = Array.from(new Set([…selectedRows, record]));
} else {
arr = selectedRowKeys.filter(item => {
return item !== record.id
});
list = selectedRows.filter(item => item.id !== record.id)
}
setSelectedRowKeys(arr);
setSelectedRows(list);
},

/*当前页用户手动选择/取消选择所有行的回调*/
onSelectAll: (selected:boolean, currentPage:number, changeRows:TableListItem[]) => {
  if (selected && currentPage) {
    let addSelected:number[] = [];
    let addRows: TableListItem[] = [];
    for (co

你可能感兴趣的:(前端开发,react.js,javascript,前端)