Search code examples
reactjsdatagrid

react DataGrid: append custom filter operator without erasing the other operators


I'm using MaterialUI's DataGrid for React and I have created a custom filter operator for one of the columns.
I was able to add it to the column as mentioned in the documentation and it's working fine, however, this removed the other default operators (contains, equal, etc...).
This is how I did it:

columns: GridColDef[] = [
    {
        field: 'myFieldName',
        headerName: 'Column name',
        filterOperators: [MyCustomOperator],// this is the custom operator I have created
    }
]

How to append my custom operator and keep other operators?

Solution

  • I tried with ...getGridStringOperators() and it's adding new filter at the end of all existing filter. So for your case it will be something like below:

    columns: GridColDef[] = [
         ...getGridStringOperators(),
         {
            field: 'myFieldName',
            headerName: 'Column name',
            filterOperators: [MyCustomOperator],// this is the custom operator I have created
         }
    ]