[英]Ag-Grid filter does not show up unless floating filter is on
I am building a grid with ag-grid
and react I am trying to add a text filter to my grid but the filter does not show up on the grid.我正在用
ag-grid
构建一个网格并做出反应我正在尝试向我的网格添加一个文本过滤器,但过滤器没有显示在网格上。 If I turn on floating filter it is there but not regularly.如果我打开浮动过滤器,它就在那里,但不是定期的。
Here is the code这是代码
type Props = {
gridData: Array<any>;
}
type State = {}
class filteredGrid extends PureComponent<Props, State> {
private gridOptions = {};
static propsType = {
gridData: ImmutablePropTypes.list
}
constructor(props) {
super(props);
gridOptions = {
defaultColDef: { filter: true },
columnDefs: [
{ headerName: "Location", field: 'location', filter: "agTextColumnFilter" },
],
suppressMenuHide: true,
suppressMovableColumns: true,
enableSorting: true,
rowSelection: 'single',
rowDeselection: true,
onGridReady: debounce(function (params) {
params.api.sizeColumnsToFit();
window.addEventListener('resize', function () {
setTimeout(function () {
params.api.sizeColumnsToFit();
});
});
}),
pagination: true,
paginationPageSize: 10,
rowClass: 'grid-row',
gridAutoHeight: true,
headerHeight: 50,
rowHeight: 50,
overlayNoRowsTemplate: '<span>No Data</span>',
};
}
render(): ReactNode {
const { gridData } = this.props;
return (
<div>
<div className="ag-theme-material">
<AgGridReact
gridOptions={this.gridOptions}
rowData={gridData}
/>
</div>
</div>
);
}
}
The grid has no filter and looks like this:网格没有过滤器,如下所示:
How can I get the filter icon that opens the filter to show up?如何让打开过滤器的过滤器图标显示出来?
I solved the issue, In order to make the filters appear I had to set the grid option enableFilter: true
.我解决了这个问题,为了使过滤器出现,我必须设置网格选项
enableFilter: true
。 I did not know this as it was never mentioned in the documentation.我不知道这一点,因为它从未在文档中提及。
我今天遇到了这个问题,我的问题是我的默认列定义中有suppressMenu: true
。
I have declared in filter: true in defaultColDef
but the filer column not enabled in the grid after that I have directly declared enableFilter={true}
with the <AgGridReact>
then the filter is enabled.我已经在 filter: true in
defaultColDef
中声明,但是在网格中未启用过滤器列之后,我直接使用<AgGridReact>
声明enableFilter={true}
然后启用了过滤器。
Error:错误:
const defaultColDef = useMemo(() => {
return {
cellStyle: {
'border-right': '1px dotted',
'padding-left': 0,
textAlign: 'center'
},
editable: false,
filter: true,
flex: 1,
floatingFilter: true,
floatingFilterComponentParams: { suppressFilterButton: true },
resizable: true,
sortable: true,
suppressMenu: true
}
}, [])
<AgGridReact
defaultColDef={defaultColDef}
</AgGridReact>
Solution:解决方案:
<AgGridReact
enableFilter={true}
defaultColDef={defaultColDef}
</AgGridReact>
在 gridOptions 中设置 enableFilter: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.