简体   繁体   中英

Sort an antd (Ant Design) table that has selection enabled

I am trying to make a table with antd that allows sorting and row selection (using checkboxes).

Right now I have both enabled, however, when I sort by ascending/descending order, the selection does not sort. The checked boxes just stay at the same index as before.

To fix this I tried making a custom sort function that could possibly sort the selectedRowKeys the same way it is sorting the table rows, but I am not able to retrieve the information I need in the callback function to do this.

Has anyone ever done this before?

Any help would be appreciated!

You have not set the key of rows. You have two ways to do it:

  • in the objects of the columns array add the key properties (with a property that represents a row identifier)
  • set rowKey props for the table with the name of the property that represents a row identifier in the columns objects

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM