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

🐛[BUG]ProTable请求查询过滤后没有数据时Pagination不会重置 #8496

Closed
godcong opened this issue Jun 14, 2024 · 8 comments
Closed

Comments

@godcong
Copy link

godcong commented Jun 14, 2024

提问前先看看:

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

🐛 bug 描述

请求查询过滤后没有数据时Pagination不会重置

📷 复现步骤

  1. 先正常显示数据.(数据符合分页条件,显示分页栏)
  2. 添加查询条件.(条件不符合分页条件,无数据返回)
  3. 条件不符合时,会触发onRequestError,但是分页不会重置,onChange回调不会触发.
    image
    image
  4. 此时页面显示数据为空,但Pagination显示为前一次搜索时的状态

🏞 期望结果

没有数据时,Pagination分页显示最初设置的状态(1或隐藏)

💻 复现代码

<ProTable<API.History, API.PaginationParam>
        onSizeChange={(size: any) => {
          log('size change', size);
        }}
        defaultData={historyList}
        columns={columns}
        actionRef={actionRef}
        request={listHistoryList}
        rowKey="id"
        cardBordered
        search={{
          collapseRender: false,
          collapsed: false,
          span: 8,
          labelWidth: 120,
        }}
        scroll={{ x: 'auto' }}
        pagination={{
          hideOnSinglePage: true,
          pageSize: pageSize,
          showSizeChanger: true,
          position: ['bottomCenter'],
        }}
        headerTitle={statisticTotal}
        onChange={(params: TablePaginationConfig) => {
          log('change', params);
          if (params) {
            const total = params.total ?? 0;
            const size = params.pageSize ?? 15;
            setStatisticTotal(total);
            setPageSize(size);
            return;
          }
          setStatisticTotal(0);
          setPageSize(15);
        }}

        options={{
          density: false, //密度
          // setting: false, //设置
          fullScreen: false,
          reload: false,
        }}
        onReset={onClear}
        beforeSearchSubmit={(params: any) => {
          const created_at_start = searchPickerDate[0] ? searchPickerDate[0].valueOf() : undefined;
          const created_at_end = searchPickerDate[1] ? searchPickerDate[1].valueOf() : undefined;
          if (created_at_start && created_at_end) {
            params.created_at_start = created_at_start;
            params.created_at_end = created_at_end;
          }
          const status = state != 0 ? state : undefined;
          if (status) {
            params.status = status;
          }
          return params;
        }}
        dateFormatter="string"
        toolBarRender={() => []}
      />

© 版本信息

  • ProComponents 版本: [e.g. 4.0.0] "@ant-design/pro-components": "^2.7.9",
  • umi 版本 "@umijs/max": "^4.2.8",
  • 浏览器环境 edge
  • 开发环境 [e.g. mac OS] win 10

🚑 其他信息

@godcong
Copy link
Author

godcong commented Jun 14, 2024

或者有什么方法可以,可以在data是null的时候重置Pagination?

@godcong godcong changed the title 🐛[BUG]请求查询过滤后没有数据时Pagination不会重置 🐛[BUG]ProTable请求查询过滤后没有数据时Pagination不会重置 Jun 17, 2024
@kikcmime
Copy link

兄弟这个问题解决了吗,我这也是,我的是假如当前是第三页,然后把这条数据删除,给后端的current是3,然后肯定是没有数据的,但是table的页码自动变为了2,但是其实2页应该是有数据的,这个时候哪怕在第三页展示个空数据也行

@godcong
Copy link
Author

godcong commented Jun 24, 2024

没解决...想用state监听errors时控制Pagination显示,但是这样正常搜索又不对了...因为false的时候又没法设置pageSize这些参数.

@godcong
Copy link
Author

godcong commented Jun 28, 2024

额...没人看看么?

@jszyy
Copy link

jszyy commented Jul 4, 2024

我很早就遇到了这个问题,很无奈也没找到很好的解决办法,我的做法是自己写 search 组件,分别通过 重置和查询 按钮来控制搜索参数,然后在 portable 的 onChange 事件里 处理 pageNum和pageSize,这种写法导致我的代码存在大量冗余,希望有好的解决方案的时候能踢我一脚

@godcong
Copy link
Author

godcong commented Jul 4, 2024

发现异常后,重新获取数据不会触发onChange
Pagination=false的时候好像也不会触发.
可能和这部分逻辑有关系

@jszyy
Copy link

jszyy commented Jul 5, 2024

发现异常后,重新获取数据不会触发onChange Pagination=false的时候好像也不会触发. 可能和这部分逻辑有关系

image

我是这样解决的,可以参考下,有问题一起交流

@godcong
Copy link
Author

godcong commented Jul 5, 2024

@jszyy 谢谢.
我本来只是想用ProTable的request,可以自动控制条件查询. 然后,发现这东西不能用,用了就出了这么个问题.

现在又封了一层,不管什么状态,都会返回数据了.
image

@godcong godcong closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2024
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