I am using the Ant Design library for the project and the table element, in particular.
The question is how to make the sorters and filters work for the whole table, not just the first paginated page?
I am looking for the front-end solution because creating the back-end methods isn't suitable for the project.
export default class BookTable extends React.PureComponent<BooksTableProps>
{
private readonly columns: ColumnProps<Book>[] = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
defaultSortOrder: 'descend',
sorter: (a, b) => {return a.name.localeCompare(b.name)},
render: (text, record) => <span>{record.name}</span>,
},...
]
render() {
const {
loading,
pagination,
books,
} = this.props;
return (
<div>
<Table
bordered
columns={this.columns}
dataSource={books}
loading={loading}
pagination={pagination}
onChange={this.handleTableChange}
/>
</div>
)
}
}
Adding the sorting functionality in the table is very easy. We just have to use the sorter prop one of the column props provided to us by the Antd, which when used in any column gives us the ability to sort the data of that column alphanumerically.
Change pageSize . Jump to a page directly. import type { PaginationProps } from 'antd'; import { Pagination } from 'antd'; import React from 'react'; const onChange: PaginationProps['onChange'] = pageNumber => { console. log('Page: ', pageNumber); }; const App: React.
You can make use of the responsive property on the column that you want to control for screen sizes. Just add a From To column with a custom render function, and set the responsive property on that column to only show on xs screens. The From and To columns will have the responsive property set to show on md and above.
Rows can be selectable by making first column as a selectable column. You can use rowSelection.type to set selection type. Default is checkbox . selection happens when clicking checkbox by default.
It's supported out of the box. Once you define sorter
it's used for all the dataSource
. So, once you click on sorted column - all your data gets sorted.
Not very obvious, but you can take a look at this example. If you sort by age
- the whole table data gets sorted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With