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

[docs] Missing explanations about the "id" field in the GridFilterModel #2735

Closed
2 tasks done
alsiola opened this issue Sep 29, 2021 · 1 comment · Fixed by #2783
Closed
2 tasks done

[docs] Missing explanations about the "id" field in the GridFilterModel #2735

alsiola opened this issue Sep 29, 2021 · 1 comment · Fixed by #2783
Assignees
Labels
docs Improvements or additions to the documentation

Comments

@alsiola
Copy link

alsiola commented Sep 29, 2021

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

When creating a data grid with externally state-managed filterModel, opening the filter modal and adding a new filter (with "and") unsets the initial filter state.

Setting a property id (of any value) on the initial filter item seems to resolve the issue, but this is not documented and seems surprising.

{
    items: [
      {
        columnField: "commodity",
        operatorValue: "contains",
        value: "rice",
        id: 123 // <- adding this field resolves the issue
      }
    ]
  }
Screen.Recording.2021-09-29.at.09.52.41.mov

Expected behavior 🤔

Initial filter state should be maintained, or requirement for id property should be documented.

Steps to reproduce 🕹

Reproduced in CodeSandbox

Context 🔦

No response

Your environment 🌎

`npx @mui/envinfo`
  System:
    OS: macOS 11.6
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v14.16.0/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
  Browsers:
    Chrome: 94.0.4606.61 (browser used to identify issue)
    Edge: Not Found
    Firefox: 84.0
    Safari: 14.1.2
  npmPackages:
    @emotion/react:  11.1.5 
    @emotion/styled:  10.0.27 
    @mui/x-data-grid: ^4.0.0 => 4.0.0 
    @types/react: ^17.0.0 => 17.0.0 
    react: 17.0.1 => 17.0.1 
    react-dom: 17.0.1 => 17.0.1 
    typescript: ^4.1.3 => 4.1.3 

Order ID 💳 (optional)

No response

@alsiola alsiola added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 29, 2021
@flaviendelangle
Copy link
Member

flaviendelangle commented Sep 29, 2021

image

https://mui.com/components/data-grid/filtering/#multi-column-filtering

Some of the demo descriptions are even wrong

As you said, if you have multiple filters, they should have an ID.

Here is the exact logic :

    if (props.filterModel !== undefined && props.filterModel.items.length > 1) {
      const hasItemsWithoutIds = props.filterModel.items.find((item) => item.id == null);
      if (hasItemsWithoutIds) {
        throw new Error(
          "The 'id' field is required on filterModel.items when you use multiple filters.",
        );
      }
    }

@flaviendelangle flaviendelangle added docs Improvements or additions to the documentation components: DataGridPro and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 29, 2021
@flaviendelangle flaviendelangle changed the title Initial filter state removed when a filter is added [docs] Missing explanations about the "id" field in the GridFilterModel Sep 29, 2021
@ZeeshanTamboli ZeeshanTamboli self-assigned this Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation
Projects
None yet
3 participants