【问题标题】:Antd table to filter one input against multiple dataIndex?Antd表过滤多个dataIndex的一个输入?
【发布时间】:2019-10-02 22:35:24
【问题描述】:

我有一个 antd 表,它有一个简单的数据集。您可以指定一个 dataIndex 来执行过滤。 但是我需要做的是只提供一个搜索字段,它将使用两个不同的 dataIndex 进行搜索。

IE: 在我的数据示例中,name 和 lastname 是两个不同的属性。

{
  name: 'Ricardo',
  lastname: 'Buquet',
}

我只想拥有一个名为“全名”的过滤器字段 用户可以在其中输入姓名或姓氏并按其中任何一个进行过滤。

【问题讨论】:

    标签: react-redux antd


    【解决方案1】:

    您可以通过在您的状态中存储搜索输入值(其他过滤器和分页参数)并相应地过滤您的数据(在 redux 或组件中)来做到这一点,如下面的代码。

    如果您分享您的源代码,我可以提供更具体的答案。

    handleSearchInputChange = (e) => {
        const { params } = this.state;
        params.search = e.target.value;
        this.setState({params});
    };
    handleSearch(){
        if(this.state.params.search !== ''){
            const { columns } = this.state;
            columns.forEach(column => {
                if (column.key === 'id'){
                    column.filterIcon = <Icon
                        type="search"
                        style={{ color: '#108ee9' }}
                    />;
                }
            });
            this.setState({columns});
        }
        this.props.listUsers(this.state.params);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-19
      • 1970-01-01
      • 2021-10-27
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多