下面是我的示例代码,当我在公司上使用过滤器选项时,我想要的全部内容也将被过滤。
但是当我这样做时,即使在部门过滤器上也会被触发,并且它会重新呈现该公司过滤器上的表,然后再次调用它,然后再调用
这是一个循环,company-> deptt-> company-> deptt-> company ...,依此类推。
导出类CustomSelectFilter扩展了React.Component { filterOptions = Reflect.ownKeys(this.props.options).map(key =>({this.props.options [key] .label}));
render(){ 返回( filter(e.target.value,this.props.filterHandler,this.props.nestedSearchKey)}> 选择... { this.filterOptions } ); } }
const getCustomFilterElement = (filterHandler, nestedSearchKey) => <CustomFilter filterHandler={filterHandler} nestedSearchKey={nestedSearchKey} />;
const customFilter = useCallback((searchKey) => ({
type: 'CustomFilter',
getElement: filterHandler => this.getCustomFilterElement(filterHandler, searchKey)
}), []);
return (
<>
<h3 className="mt-4 mb-4 pb-1">Projects</h3>
<BootstrapTable
data={projects}
tableStyle={{background: '#fafafa'}}
pagination
options={options}
condensed
hover
>
<TableHeaderColumn
dataField="name"
dataSort
filter={regexFilter}
>
Name
</TableHeaderColumn>
<TableHeaderColumn
dataField="Company"
sortFunc={customSortFunc('Company.name')}
dataFormat={formatCompany}
dataSort
filter={customFilter('company')}
>
Company
</TableHeaderColumn>
<TableHeaderColumn
dataField="assetType"
dataSort
dataFormat={formatAssetType}
filter={customFilter('deptt')}
>
Department
</TableHeaderColumn>
</BootstrapTable>
</>
);
}