Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting and filtering the full paginated Antd Table

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>                
     )
   }
  }
like image 600
Roman Haivaronski Avatar asked Jul 18 '18 09:07

Roman Haivaronski


People also ask

How do I sort in antd table?

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.

How do you use antd pagination?

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.

How do I make an antd table responsive?

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.

How do I select rows in antd table?

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.


1 Answers

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.

like image 173
Alex Avatar answered Nov 01 '22 17:11

Alex