I have an Ionic/Angular
app using ag-grid
. I would like certain grids to have a filter automatically applied when the grid is loaded - without the user having to do anything.
I tried the following:
onGridReady(params) {
params.api.sizeColumnsToFit();
// get filter instance
var filterComponent = params.api.getFilterInstance("isActive");
// OR set filter model and update
filterComponent.setModel({
type: "greaterThan",
filter: 0
});
filterComponent.onFilterChanged();
}
but it did nothing. Any ideas?
Reproduced your problem in a couple of their example plunks, seemed to be alleviated by adding a small delay. Just venturing a guess that maybe the DOM isn't completely ready yet, although the grid is.
Fix:
onGridReady(params) {
params.api.sizeColumnsToFit();
setTimeout(() => {
var filterComponent = params.api.getFilterInstance("isActive");
filterComponent.setModel({
type: "greaterThan",
filter: 0
});
filterComponent.onFilterChanged();
},150)
}