Ag-grid does not give a react example on how to use external filters with React .无论如何,我都遵循了这个例子,并尝试像我一样以声明方式使用 gridOptions:
<AgGridReact
rowData={this.state.rowData}
columnDefs={this.state.columnDefs}
defaultColDef={this.state.defaultColDef}
groupDefaultExpanded={this.state.groupDefaultExpanded}
masterDetail={true}
detailRowHeight={this.state.detailRowHeight}
detailCellRendererParams={this.state.detailCellRendererParams}
onGridReady={this.onGridReady}
enableRangeSelection={true}
pagination={true}
sideBar={this.state.sideBar}
isExternalFilterPresent={true}
doesExternalFilterPass={(node) => {
alert(node);
}}
/>
我像示例一样手动触发 filterChanged:
<Col xs='3'>
<Field
component={renderSelectField}
name="relatorio-filtro"
hintText='100'
variant="outlined"
selectStyle={relatorioFiltro}
disable={() => { }}
onChange={(e) => {
this.gridApi.onFilterChanged()
}}
>
<div value="15" key="15">{"15"}</div>
<div value="25" key="25">{"25"}</div>
<div value="50" key="50">{"50"}</div>
<div value="100" key="100">{"100"}</div>
<div value="200" key="200">{"200"}</div>
</Field>
</Col>
但这没有用,警报永远不会发生。我怀疑这种功能不适用于 React。
最佳答案
从您提供的页面:
isExternalFilterPresent is called exactly once every time the grid senses a filter change. It should return true if external filtering is active, otherwise false. If you return true, then doesExternalFilterPass() will be called while filtering, otherwise doesExternalFilterPass() will not be called.
所以在我看来你应该尝试这样的事情:
isExternalFilterPresent={()=> {return true;} }
关于javascript - 如何在 React 中使用外部过滤器? (农业网格),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56349230/