antd table筛选如何对所有数据进行筛选而不是当前页的某一列进行筛选?

1.目前数据是前端分页的,分页功能正常,按照antd 官方筛选的例子,只能对每页的某一列进行筛选,想要实现对所有数据进行筛选而不是当前页面筛选,该如何改造呢?
官方例子,链接:https://codesandbox.io/s/n90m...

clipboard.png

目前自己实现的效果:

clipboard.png

搜索“谭超”时效果:

clipboard.png
实际谭超应该只有一条数据,但是页面还是有8个页码(后面的页码都没有数据),该如何调整筛选出来后重新进行分页,想问下getColumnSearchProps应该如何调整?

getColumnSearchProps = dataIndex => ({
    filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => (
      <div style={{ padding: 8 }}>
        <Input
          ref={node => {
            this.searchInput = node;
          }}
          placeholder={`Search ${dataIndex}`}
          value={selectedKeys[0]}
          onChange={e => setSelectedKeys(e.target.value ? [e.target.value] : [])}
          onPressEnter={() => this.handleSearch(selectedKeys, confirm)}
          style={{ width: 188, marginBottom: 8, display: 'block' }}
        />
        <Button
          type="primary"
          onClick={() => this.handleSearch(selectedKeys, confirm)}
          icon="search"
          size="small"
          style={{ width: 90, marginRight: 8 }}
        >
          Search
        </Button>
        <Button onClick={() => this.handleReset(clearFilters)} size="small" style={{ width: 90 }}>
          Reset
        </Button>
      </div>
    ),
    filterIcon: filtered => (
      <Icon type="search" style={{ color: filtered ? '#1890ff' : undefined }} />
    ),
    onFilter: (value, record) =>
      record[dataIndex]
        .toString()
        .toLowerCase()
        .includes(value.toLowerCase()),
    onFilterDropdownVisibleChange: visible => {
      if (visible) {
        setTimeout(() => this.searchInput.select());
      }
    },
    render: text => (
      <Highlighter
        highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
        searchWords={[this.state.searchText]}
        autoEscape
        textToHighlight={text.toString()}
      />
    ),
  });

  handleSearch = (selectedKeys, confirm) => {
    confirm();
    this.setState({ searchText: selectedKeys[0] });
  };

  handleReset = clearFilters => {
    clearFilters();
    this.setState({ searchText: '' });
  };
阅读 10.2k
4 个回答

没明白你的问题,不过我感觉大概思路就是
通过函数操作数据,数据来驱动视图

新手上路,请多包涵

想知道这个this.searchInput是哪里来的?

所有数据查询应该在table外面添加个输入框,然后过滤之后的数据传给table

  可以尝试通过查看antd远程加载的方案,找到一点解决的方法
截屏2021-11-17 上午10.00.21.png
  不是所有的功能都能在前端实现的,或者说不方便。

  如果坚持在前端实现,给你指条路:
  可以尝试通过table标签的onChange()监控分页、筛选、排序。
  在里面可以尝试解决你的需求。
截屏2021-11-17 下午3.12.58.png
  我确实在这里解决了问题。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题