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 request和pagination.onChange会重复请求 #7423

Open
canqi0 opened this issue Jul 26, 2023 · 5 comments
Open

🧐[问题]ProTable request和pagination.onChange会重复请求 #7423

canqi0 opened this issue Jul 26, 2023 · 5 comments

Comments

@canqi0
Copy link

canqi0 commented Jul 26, 2023

提问前先看看:

https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md

🧐 问题描述

我想在ProTable中进行排序
onChangeSort会将sorter塞到state.queryCondition 并请求接口
onChangePage会更新state.queryCondition中的current pageSize 并请求接口

  pagination={{
     showSizeChanger: true,
     current: state.queryCondition.current,
     pageSize: state.queryCondition.pageSize,
     total: state.tableDatas.total,
     showTotal: (total) => `共 ${total} 条记录`,
     onChange: onChangePage,
  }}
  request={onChangeSort}

场景1:
如果我点击过排序 且当前 current = 1 时
再点击第二页会先调用onChangePage 设置 current = 2
更新后又调用了一次onChangeSort 此时 current = 2
共请求两次

场景2:
如果我点击过排序 且当前 current = 1 时
再点击第二页会先调用onChangePage 设置 current = 2
更新后又调用了一次onChangeSort 此时 我想在onChangeSort中设置current = 1 回到第一页 此时current = 1
再次触发onChangePage 此时 current = 1
再次触发onChangeSort 此时 current = 1
共请求四次

尝试解决

  1. 去掉onChange -> onChangePage 点击分页无反应
  2. onChangePage中不再请求,只更新current pageSize -> 正常触发onChangeSort 只请求一次 但不能在排序时设置current = 1 回到第一页
  3. 注释掉pagination 使用组件绑定onChangePage 解决

🚑 其他信息

版本更新前pagination.onChange 和 request 并不会互相影响
Table中的排序和筛选是使用onChange实现的,并指定了触发类型action

参数 说明 类型 默认值 版本
onChange 分页、排序、筛选变化时触发 function(pagination, filters, sorter, extra: { currentDataSource: [], action: paginate | sort | filter }) -

ProTable中pagination.onChange和request是否有些冲突,以及希望request中可以指定当前触发类型

@github-actions
Copy link

github-actions bot commented Jul 26, 2023

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

@canqi0 canqi0 changed the title 🧐[问题]ProTable request和pagination.onChange会重复调用 🧐[问题]ProTable request和pagination.onChange会重复请求 Jul 26, 2023
@chenshuai2144
Copy link
Contributor

听起还挺合理的,你要不加个去抖?

@canqi0
Copy link
Author

canqi0 commented Jul 28, 2023

听起还挺合理的,你要不加个去抖?

治标不治本啊

@canqi0 canqi0 closed this as completed Jul 28, 2023
@canqi0 canqi0 reopened this Jul 28, 2023
@chenshuai2144
Copy link
Contributor

理论上就应该多次发送的,有参数变化了嘛

@phoema
Copy link

phoema commented Aug 5, 2023

我们系统也出现这个问题了,
我们procompent升级到2.6.8以后,目前还没有回滚。

刚开始我们没有实现onChange,表现为,有的排序页面当表格列仅有自定义筛选,没有内置筛选时,自定义筛选无效,有的页面有内置筛选,自定义筛选就有效。
我们将封装的表格组件加了onChange事件,无效的那个页面就可以了。
然后发现在【有的页面有内置筛选,自定义筛选就有效】原来这种检索正常的页面,就重复触发后台检索两次。

我们在codeBox中没有复现,没有定义明确的再现现象,所以还没有提Issue
初步考虑,是否是ProTable在有和没有filter内置筛选列两种情况,内部机制有差异,或者触发onChange的规则由差异?

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

3 participants