我在 Gatsby 站点中实现了 Ant 设计表。我正在从 graphql 中提取数据。到目前为止,一切都运行良好。数据显示正确,分页正常等。
现在我想添加对列进行排序的功能。为此,我设置了表和列,如下所示:
<Table
dataSource={data.allNewsFeed.edges}
onChange={onChange}
rowSelection={rowSelection}
rowKey="id"
>
<Column
title="Title"
dataIndex="node.title"
key="title"
sorter={(a, b) => a.node.title - b.node.title}
sortDirections={["descend", "ascend"]}
/>
</Table>
现在,确实显示了用于对列进行排序的图标,但当我单击它时没有任何反应。
如果我删除也会发生同样的事情.node
从排序器功能:sorter={(a, b) => a.title - b.title}
.
所以,我被困住了——知道为什么这不起作用以及如何解决它吗?
Thanks.
@norbiTrial 的回答是正确的,作为参考,这里是一个通用排序器(用于数字和字符串):
const sorter = (a, b) => (isNaN(a) && isNaN(b) ? (a || '').localeCompare(b || '') : a - b);
// Usage example with antd table column
[
{
title: 'Status',
dataIndex: 'status',
key: 'status',
width: '10%',
// status can be Number or String
sorter: (a, b) => sorter(a.status, b.status),
render: Name
}
]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)