Search code examples
angularag-gridag-grid-angular

Ag-grid predicate function is not executing


I am trying to create a custom filter option using the predicate function provided by ag-grid :https://www.ag-grid.com/angular-data-grid/filter-provided-simple/#reference-IFilterOptionDef-predicate

 {
                field: 'createdBy',
                filter: 'agTextColumnFilter',
                filterParams: {
                    filterOptions: [
                        'contains',
                        'notContains',
                        'blank',
                        {
                            displayKey: 'Active',
                            displayName: 'Active Users',
                            predicate: (cellValue) => {
                                console.log('test')    <------ this console never gets printed
                                cellValue == null || /active/gm.test(cellValue.toLowerCase())
                            },
                            numberOfInputs: 0,
                        },
                    ],
                    debounceMs: 200,
                },
            },

As you can see above in the code above test never gets printed which means the predicate function never gets executed

Ui

But as you can see in the image above Active key is present in the Ui but the predicate function is not working.

We are using the following version of ag-grid:

"@ag-grid-community/angular": "^25.3.0",
"@ag-grid-enterprise/all-modules": "^25.3.0" 

Solution

  • Edited - if using ag-grid v25

    test: function (filterValue, cellValue) {
      console.log('test');
        return null || /active/gm.test(cellValue.toLowerCase());
    },
    

    If using ag-grid v27

    Please can you try your predicate like this?

    predicate: function (filterValue, cellValue) {
        console.log('test');
        return null || /active/gm.test(cellValue.toLowerCase());
    }
    

    Does the console.log work then?