0

我想修改搜索react-bootstrap-table multiColumnSearch以要求来自两列或多列的数据,而不是匹配表中的所有数据。

例子:

ID   FAMILY     YEAR
---------------------
1   FAMILY-1    2010
2   FAMILY-1    2011
3   FAMILY-2    2010
4   FAMILY-2    2011

询问:FAMILY-1 2010

当前结果:

ID   FAMILY     YEAR
---------------------
1   FAMILY-1    2010
2   FAMILY-1    2011
3   FAMILY-2    2010

期望的结果:

ID   FAMILY     YEAR
---------------------
1   FAMILY-1    2010

当前代码:

options: Options = {
    defaultSortName: 'Id',
    defaultSortOrder: 'desc', 
    noDataText: 'Empty data',
    onRowClick: this.onRowClick.bind(this)
};
render() {
    return (
        <div>
            <BootstrapTable containerStyle={{ marginTop: '10px' }} data={this.state.tableCases} options={this.options} striped={true} hover={true} search multiColumnSearch>
                <TableHeaderColumn dataField='Id' isKey={true} dataSort={true}>Case ID</TableHeaderColumn>
                <TableHeaderColumn dataField='CompanyName' dataSort={true}>Company Name</TableHeaderColumn>
                <TableHeaderColumn dataField='Title' dataSort={true}>Title</TableHeaderColumn>
                <TableHeaderColumn dataField='Family' dataSort={true}>Family</TableHeaderColumn>
                <TableHeaderColumn dataField='ApplicationDate' dataSort={true}>Application Date</TableHeaderColumn>
            </BootstrapTable>
        </div>
    );
}

https://allenfang.github.io/react-bootstrap-table/docs.html#multiColumnSearch

更新:

感谢@FiriceNguyen,我能够解决它。添加了对 distinctlyTyped 的拉取请求,strictSearch以便其他人将来可以使用它。代码:

<div>
    <BootstrapTable containerStyle={{ marginTop: '10px' }} data={this.state.tableCases} options={this.options} striped={true} hover={true} search multiColumnSearch strictSearch>
        <TableHeaderColumn dataField='Id' isKey={true} dataSort={true}>Case ID</TableHeaderColumn>
        <TableHeaderColumn dataField='CompanyName' dataSort={true}>Company Name</TableHeaderColumn>
        <TableHeaderColumn dataField='Title' dataSort={true}>Title</TableHeaderColumn>
        <TableHeaderColumn dataField='Family' dataSort={true}>Family</TableHeaderColumn>
        <TableHeaderColumn dataField='ApplicationDate' dataSort={true}>Application Date</TableHeaderColumn>
    </BootstrapTable>
</div>

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/19629

4

1 回答 1

1

In your case, I think you want an AND operator rather than apply 2/3 columns. Your query is to search for FAMILY-1 OR 2010, so that your current results are correct.

Anyway, the strictSearch can fit your need. You can refer here for details of search mode. In your case the configuration should be strict && !multiColumn

于 2017-09-07T14:28:58.480 回答