Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I write a controlled filter for a boolean field? #12937

Closed
ayhid opened this issue Apr 29, 2024 · 2 comments
Closed

How can I write a controlled filter for a boolean field? #12937

ayhid opened this issue Apr 29, 2024 · 2 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information support: commercial Support request from paid users support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ support: question Community support but can be turned into an improvement

Comments

@ayhid
Copy link

ayhid commented Apr 29, 2024

The problem in depth

Hello It's not really a problem but more a need for an example to write a custom filter that uses a boolean field.

Your environment

`npx @mui/envinfo`
System:
    OS: macOS 14.4.1
  Binaries:
    Node: 20.11.0 - ~/.volta/tools/image/node/20.11.0/bin/node
    npm: 10.5.0 - ~/projects/assess-manager-dash/frontend/node_modules/.bin/npm
    pnpm: Not Found
  Browsers:
    Chrome: 124.0.6367.92
    Edge: Not Found
    Safari: 17.4.1
  npmPackages:
    @emotion/react: ^11.11.1 => 11.11.4 
    @emotion/styled: ^11.10.5 => 11.11.0 
    @mui/base:  5.0.0-beta.40 
    @mui/core-downloads-tracker:  5.15.14 
    @mui/icons-material: ^5.14.15 => 5.15.14 
    @mui/lab: ^5.0.0-alpha.137 => 5.0.0-alpha.169 
    @mui/material: ^5.14.12 => 5.15.14 
    @mui/material-nextjs: ^5.15.3 => 5.15.11 
    @mui/private-theming:  5.15.14 
    @mui/styled-engine:  5.15.14 
    @mui/system: ^5.14.7 => 5.15.14 
    @mui/types:  7.2.14 
    @mui/utils:  5.15.14 
    @mui/x-data-grid: ^7.0.0 => 7.1.0 
    @mui/x-data-grid-pro: ^7.1.0 => 7.1.0 
    @mui/x-date-pickers:  7.2.0 
    @mui/x-date-pickers-pro: ^7.2.0 => 7.2.0 
    @mui/x-license:  7.0.0 
    @mui/x-license-pro: ^6.10.2 => 6.10.2 
    @types/react: ^18.2.73 => 18.2.73 
    react: 18.2.0 => 18.2.0 
    react-dom: 18.2.0 => 18.2.0 
    styled-components:  5.3.3 
    typescript: ^5.3.3 => 5.4.3 

Search keywords: boolean filter
Order ID: 85622

@ayhid ayhid added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Apr 29, 2024
@ayhid ayhid changed the title How can I write a controlled filter for a boolean field How can I write a controlled filter for a boolean field? Apr 29, 2024
@zannager zannager added support: question Community support but can be turned into an improvement component: data grid This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ labels Apr 29, 2024
@MBilalShafi
Copy link
Member

MBilalShafi commented Apr 30, 2024

You can write custom filters in general by using the colDef.filterOperators property.

const columns = [
  {
    ...otherProperties,
    filterOperators: customOperators;
  }
];

You can check this documentation section where this concept is explained with a few examples: https://mui.com/x/react-data-grid/filtering/customization/#create-a-custom-operator

The same would be the case for a boolean field, in this example, I tried to override the default filterOperators for boolean field and added another one (is not): https://stackblitz.com/edit/react-craaty?file=Demo.tsx

Let me know if you have further questions.

@MBilalShafi MBilalShafi added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 30, 2024
Copy link

github-actions bot commented May 7, 2024

The issue has been inactive for 7 days and has been automatically closed.

@github-actions github-actions bot closed this as completed May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information support: commercial Support request from paid users support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

3 participants