I’ve been researching this topic for almost a week, but unfortunately, I wasn’t able to find a satisfying solution. Therefore, I had to come up with my own workaround.
Due to the complexity of my project, I can't share the entire code structure related to this topic, as it would be too confusing and hard to follow. However, I’d like to share the core idea of the solution I developed, which might help others facing a similar issue.
```
const onGridReady = async (gridParams: GridReadyEvent) => {
// Define your initial filters as key-value pairs
const initialFilters: Record<string, { type: string; filter: any }> = {
name: { type: 'equals', filter: 'Michael 222' },
status: { type: 'equals', filter: 'active' },
};
// Iterate over each column and apply the filter model
for (const [colKey, filterModel] of Object.entries(initialFilters)) {
const filterInstance = await
gridParams.api.getColumnFilterInstance(colKey);
if (filterInstance) {
filterInstance.setModel(filterModel);
}
}
// Notify AG Grid that filter model has changed
gridParams.api.onFilterChanged();
// Optionally: set your data source here
const dataSource: IDatasource = {
rowCount: null, // can be set dynamically
getRows: async (params) => {
// Fetch and return rows here
},
};
gridParams.api.setGridOption('datasource', dataSource);
};
```
I’ve been researching this topic for almost a week, but unfortunately, I wasn’t able to find a satisfying solution. Therefore, I had to come up with my own workaround.
Due to the complexity of my project, I can't share the entire code structure related to this topic, as it would be too confusing and hard to follow. However, I’d like to share the core idea of the solution I developed, which might help others facing a similar issue.
const onGridReady = async (gridParams: GridReadyEvent) => {
// Define your initial filters as key-value pairs
const initialFilters: Record<string, { type: string; filter: any }> = {
name: { type: 'equals', filter: 'Michael 222' },
status: { type: 'equals', filter: 'active' },
};
// Iterate over each column and apply the filter model
for (const [colKey, filterModel] of Object.entries(initialFilters)) {
const filterInstance = await
gridParams.api.getColumnFilterInstance(colKey);
if (filterInstance) {
filterInstance.setModel(filterModel);
}
}
// Notify AG Grid that filter model has changed
gridParams.api.onFilterChanged();
// Optionally: set your data source here
const dataSource: IDatasource = {
rowCount: null, // can be set dynamically
getRows: async (params) => {
// Fetch and return rows here
},
};
gridParams.api.setGridOption('datasource', dataSource);
};