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] upsertFilterItem expects filters with an id field #16806

Open
whitehat101 opened this issue Mar 3, 2025 · 1 comment
Open

[docs] upsertFilterItem expects filters with an id field #16806

whitehat101 opened this issue Mar 3, 2025 · 1 comment
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Filtering on header Related to the header filtering (Pro) feature feature: Filtering Related to the data grid Filtering feature support: docs-feedback Feedback from documentation page

Comments

@whitehat101
Copy link

whitehat101 commented Mar 3, 2025

Related page

https://mui.com/x/react-data-grid/filtering/header-filters/#renderheaderfilter-method

Kind of issue

Missing information

Issue description

While trying to implement the renderHeaderFilter method as described in the docs. I was trying to use a custom filter for all fields. The issue was that all other filters were being cleared when a second filter was added. I found this bug that is very similar to issue: #11793

upsertFilterItems works by comparing the id of the filter items. However in the example code, we're upserting a filter with no id field. This works okay if there is only one custom filter being used (like the current docs example does), but it fails when there are multiple.

The current example includes:

const getDefaultFilter = (field: string) => ({ field, operator: 'is' });

It would be better as:

const getDefaultFilter = (field: string) => ({ field, operator: 'is', id: field });

There are probably even better ways to populate this ID field, too.

Before I read through the code, I was assuming it was key'd off field, but of course this would not work for multiple filters on a single field.

The docs should mention the need for filter items with an id field.

Context

No response

Search keywords: renderHeaderFilter upsertFilterItem

@whitehat101 whitehat101 added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: docs-feedback Feedback from documentation page labels Mar 3, 2025
@zannager zannager added docs Improvements or additions to the documentation component: data grid This is the name of the generic UI component, not the React module! labels Mar 4, 2025
@michelengelen
Copy link
Member

Nice catch @whitehat101 ... It is indeed a bit 'under-documented'. Although the type definition states that the id is only necessary when using multiple filters: https://mui.com/x/api/data-grid/grid-filter-item/

I'll still add this to the board as it can be made a bit clearer.

cc @mapache-salvaje

@michelengelen michelengelen added feature: Filtering Related to the data grid Filtering feature feature: Filtering on header Related to the header filtering (Pro) feature and removed docs Improvements or additions to the documentation status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 4, 2025
@github-project-automation github-project-automation bot moved this to 🆕 Needs refinement in MUI X Data Grid Mar 4, 2025
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! feature: Filtering on header Related to the header filtering (Pro) feature feature: Filtering Related to the data grid Filtering feature support: docs-feedback Feedback from documentation page
Projects
Status: 🆕 Needs refinement
Development

No branches or pull requests

3 participants