Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👑 ProTable 多列服务器端排序指定初始字段方向和排序顺序 #8165

Closed
yclgkd opened this issue Feb 8, 2024 · 4 comments
Closed

Comments

@yclgkd
Copy link

yclgkd commented Feb 8, 2024

🔩 所属模块或组件

ProTable

🥰 需求描述

https://procomponents.ant.design/components/table#columns-%E5%88%97%E5%AE%9A%E4%B9%89

在定义 table 的 columns 时,可以配置 defaultSortOrder 来控制该列的默认排序方向(升降序)

但是在服务器多列排序时,没有字段可以设置初始化时的排序优先级

⛰ 功能需求适用场景

服务器端多列排序时,我通过 ProTable 组件的 onChange 事件的回调来同步排序状态至 url,我的处理类似于这样的拼接 &sort=name__ascend%2Cemail__ascend%2Cmobile__ascend

在重新刷新页面时,我通过解析 url,把排序的字段写入对应列的 defaultSortOrder

当预期排序顺序与 table 字段排序顺序一致时,则 ProTable 的 request 函数中能拿到预期顺序的 sort 参数;当预期排序顺序与 table 字段排序顺序不一致时,则 ProTable 的 request 函数中的 sort 参数顺序和 table 的字段顺序一致;

🧐 解决方案

  • 是否可以添加 columns 的配置,设置服务器端排序时的初始优先级
  • 将排序字段的方向和顺序,在初始化时写入 sort 对象

🚑 其他信息

🈚️

Copy link

github-actions bot commented Feb 8, 2024

以下的 Issues 可能会帮助到你 / The following issues may help you

@yclgkd
Copy link
Author

yclgkd commented Feb 22, 2024

问题已解决,单独维护一份 sort 和组件内的 sort 做同步

@yclgkd yclgkd closed this as completed Feb 22, 2024
@slcnx
Copy link

slcnx commented Feb 26, 2024

column.sorter 支持 multiple 字段以配置多列排序优先级。通过 sorter.compare 配置排序逻辑,你可以通过不设置该函数只启动多列排序的交互形式。
https://ant.design/components/table-cn#components-table-demo-multiple-sorter

@yclgkd
Copy link
Author

yclgkd commented Feb 29, 2024

column.sorter 支持 multiple 字段以配置多列排序优先级。通过 sorter.compare 配置排序逻辑,你可以通过不设置该函数只启动多列排序的交互形式。 https://ant.design/components/table-cn#components-table-demo-multiple-sorter

这个字段 multiple 是针对客户端排序来讲的,multiple 需要和 compare 搭配使用,对于服务端排序时的初始化没有用。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants