问题描述
我正在尝试使用 antd 制作一个 table 允许排序和行选择(使用复选框).
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.
为了解决这个问题,我尝试制作一个自定义排序函数,它可以像对表格行进行排序一样对 selectedRowKeys
进行排序,但是我无法在回调中检索我需要的信息功能来做到这一点.
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.
以前有人做过吗?
任何帮助将不胜感激!
推荐答案
您还没有设置行的键.您有两种方法可以做到:
You have not set the key of rows.You have two ways to do it:
- 在列数组的对象中添加
key
属性(带有表示行标识符的属性) - 为表设置
rowKey
道具,其属性名称表示列对象中的行标识符
- 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
这篇关于对启用了选择的 antd(Ant Design)表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!