mui-x
mui-x copied to clipboard
Overwriting `filterOperators` for string column not working if type is not defined
Duplicates
- [X] I have searched the existing issues
Latest version
- [X] I have tested the latest version
Current behavior 😯
We overwrite the filterOperators
of almost all default columns using the columnTypes
, but if we don't define the column type that we pass to the DataGrid it's not using the overwritten definition of the column.
Expected behavior 🤔
That when we don't define the column type the default column type (which is string?) should use the overwritten column definition.
Steps to reproduce 🕹
Link to live example: https://codesandbox.io/s/removebuiltinoperators-demo-mui-x-forked-d6rkyd?file=/demo.js
Steps:
- Add
columnTypes
that overwrites thestring
type - Filter out a certain filter operator
- Don't define the
type
of the column in the columns definition - Still see the filter
Context 🔦
No response
Your environment 🌎
npx @mui/envinfo
System: OS: macOS 12.4 Binaries: Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node Yarn: 3.1.1 - ~/.nvm/versions/node/v16.14.0/bin/yarn npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm Browsers: Chrome: 104.0.5112.79 Edge: Not Found Firefox: Not Found Safari: 15.5 npmPackages: @emotion/react: 11.7.1 => 11.7.1 @emotion/styled: 11.6.0 => 11.6.0 @mui/base: 5.0.0-alpha.68 @mui/lab: ^5.0.0-alpha.54 => 5.0.0-alpha.68 @mui/material: ^5.5.3 => 5.5.3 @mui/private-theming: 5.5.3 @mui/styled-engine: 5.4.1 @mui/styled-engine-sc: ^5.5.2 => 5.5.2 @mui/styles: ^5.5.3 => 5.5.3 @mui/system: 5.4.1 @mui/types: 7.1.3 @mui/utils: 5.4.1 @mui/x-data-grid: ^5.15.1 => 5.15.1 @mui/x-date-pickers: ^5.0.0-beta.2 => 5.0.0-beta.2 @types/react: 17.0.39 => 17.0.39 react: 17.0.2 => 17.0.2 react-dom: 17.0.2 => 17.0.2 styled-components: ^5.3.3 => 5.3.3 typescript: ~4.5.5 => 4.5.5
Order ID 💳 (optional)
No response
Hi, @TriPSs thanks for raising this.
Can you help me understand something - are you looking to disable specific filter operators for the string
column type or do you want to create your own custom column type based on the string
type and set its filter operators?
If it's the first case then you can just edit the filterOperators
without extending the column type. You can check it here -> https://mui.com/x/react-data-grid/filtering/#remove-an-operator.
It's indeed the first point, since we already overwrite almost all of them I thought that would be the nicest place to add it.
Ok, then yes you can just remove the contains
filter operator from the string
column type. The default column type is string
so if no type is set then the grid will assume that that column is of type string
. I've prepped a small demo to showcase how to remove that operator from all string
columns -> https://codesandbox.io/s/removebuiltinoperators-demo-mui-x-forked-u26k77?file=/demo.tsx hope that helps.
Okay, but should it not also work with the columnTypes
? As when I do define the column type to be a string it works as expected.