I have a custom filter component on a column in my grid. I've noticed that the filter component is not constructed until I click on the filter icon in the column header. This means that the data is not filtered according to my default settings (e.g., filter out records where status == StatusEnum.Complete
).
As a workaround, I've found that I can get a filter instance in the onGridReady
event by calling api.getFilterInstance('status')
, and this causes the filter component to be created and thereby apply default filtering.
This workaround seems a bit clunky. The filter
variable is unused in the onGridReady
event, which causes warnings in the IDE / build. Another developer may come along and delete this line of code, thinking it is unnecessary.
Is there a better way to force my custom filter to be instantiated when the grid is created? I'm using AgGrid 17.1 and Angular 4.4.
The grid is configured like so:
gridOptions: GridOptions = {
enableFilter: true,
onGridReady: (event) => {
let filter = event.api.getFilterInstance("status"); // forces the filter component to be constructed
let data = this.loadAsyncData();
event.api.setRowData(data);
},
columnDefs: [
...
{
headerName: "Status",
field: "status",
filterFramework: MyCustomStatusFilterComponent,
filterParams: {
valueGetter: (obj) => { return obj.data.statusEnum; },
hideCompleteByDefault: true,
...
}
},
....
]
}
I've set up an example that demonstrates the issue. Note the "hack" on line 63 of app.component.ts
.