SlimenTN
SlimenTN

Reputation: 3564

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?

Upvotes: 3

Views: 2104

Answers (1)

Deepak Biswal
Deepak Biswal

Reputation: 4320

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
     }
]

Upvotes: 1

Related Questions