79589170

Date: 2025-04-23 17:36:57
Score: 1.5
Natty:
Report link

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);
};
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): facing a similar issue
  • Low reputation (0.5):
Posted by: Mümin ZEHİR