filterag-grid

AG Grid v34 agSetColumnFilter – "Select all" with defaultToNothingSelected: true no longer filters out empty/NULL values


After upgrading AG Grid from version 33 to 34, I noticed a change in the behavior of the agSetColumnFilter.

Setup:

Observed behavior:

Expected behavior (based on v33):
Clicking "Select all" should still exclude rows with empty/NULL values.

Example:

https://stackblitz.com/edit/vitejs-vite-bvct5hqp?file=src%2FGridExample.jsx

import { useState } from 'react';
import { AllCommunityModule, ModuleRegistry } from 'ag-grid-community';
import { AllEnterpriseModule } from 'ag-grid-enterprise';
import { AgGridReact } from 'ag-grid-react';

ModuleRegistry.registerModules([AllCommunityModule, AllEnterpriseModule]);

export const GridExample = () => {
  const [rowData, setRowData] = useState([
    { id: '1', category: 'A' },
    { id: '2', category: 'B' },
    { id: '3', category: 'C' },
    { id: '4', category: 'D' },
    { id: '5', category: null },
  ]);

  const [colDefs, setColDefs] = useState([
    { field: 'id', width: 100 },
    {
      field: 'category',
      flex: 1,
      filter: true,
      filterParams: {
        defaultToNothingSelected: true,
        values: ['A', 'B', 'C'],
      },
    },
  ]);

  return (
    <div style={{ width: '100%', height: '100%' }}>
      <AgGridReact
        rowData={rowData}
        columnDefs={colDefs}
        domLayout="autoHeight"
      />
    </div>
  );
};

Question:


Solution

  • I am having the same issue and apparently you can add suppressClearModelOnRefreshValues: true to filterParams to fix it.

    Fun fact: it works for you but not for me 😅

    https://www.ag-grid.com/javascript-data-grid/filter-set/#reference-ISetFilterParams-suppressClearModelOnRefreshValues