Skip to content

[DataGridPro] Fix header filters rendering issue for isEmpty and isNotEmpty filter operators#14493

Merged
MBilalShafi merged 4 commits intomui:masterfrom
k-rajat19:header-filter
Sep 17, 2024
Merged

[DataGridPro] Fix header filters rendering issue for isEmpty and isNotEmpty filter operators#14493
MBilalShafi merged 4 commits intomui:masterfrom
k-rajat19:header-filter

Conversation

@k-rajat19
Copy link
Copy Markdown
Contributor

Fixes #14490

@k-rajat19 k-rajat19 changed the title [data grid ] Use disabled InputComponent for isEmpty and isNotEmpty filter operators [data grid] Use disabled InputComponent for isEmpty and isNotEmpty filter operators Sep 5, 2024
@michelengelen michelengelen added scope: data grid Changes related to the data grid. feature: Filtering on header Related to the header filtering (Pro) feature labels Sep 5, 2024
Copy link
Copy Markdown
Member

@MBilalShafi MBilalShafi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for picking this up. 🙏

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having to update the behavior in the filter panel:

Before
image

After
image

I'd rather keep the disabled input components in the header filter cell.

How about something like:

diff --git a/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx b/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx
index 1d22e8793..80ff6dfa2 100644
--- a/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx
+++ b/packages/x-data-grid-pro/src/components/headerFiltering/GridHeaderFilterCell.tsx
@@ -18,6 +18,11 @@ import {
   gridFilterModelSelector,
   gridFilterableColumnLookupSelector,
   GridPinnedColumnPosition,
+  GridFilterInputValue,
+  GridFilterInputDate,
+  GridFilterInputBoolean,
+  GridColType,
+  GridFilterInputSingleSelect,
 } from '@mui/x-data-grid';
 import {
   GridStateColDef,
@@ -32,7 +37,6 @@ import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
 import { DataGridProProcessedProps } from '../../models/dataGridProProps';
 import { GridHeaderFilterMenuContainer } from './GridHeaderFilterMenuContainer';
 import { GridHeaderFilterClearButton } from './GridHeaderFilterClearButton';
-
 export interface GridRenderHeaderFilterProps extends GridHeaderFilterCellProps {
   inputRef: React.RefObject<unknown>;
 }
@@ -87,6 +91,19 @@ const dateSx = {
   [`& input[value=""]:not(:focus)`]: { color: 'transparent' },
 };
 
+const defaultInputComponents: {
+  [key in GridColType]: React.JSXElementConstructor<any> | null;
+} = {
+  string: GridFilterInputValue,
+  number: GridFilterInputValue,
+  date: GridFilterInputDate,
+  dateTime: GridFilterInputDate,
+  boolean: GridFilterInputBoolean,
+  singleSelect: GridFilterInputSingleSelect,
+  actions: null,
+  custom: null,
+};
+
 const GridHeaderFilterCell = React.forwardRef<HTMLDivElement, GridHeaderFilterCellProps>(
   (props, ref) => {
     const {
@@ -147,7 +164,9 @@ const GridHeaderFilterCell = React.forwardRef<HTMLDivElement, GridHeaderFilterCe
     );
 
     const InputComponent =
-      colDef.filterable || isFilterReadOnly ? currentOperator!.InputComponent : null;
+      colDef.filterable || isFilterReadOnly
+        ? (currentOperator.InputComponent ?? defaultInputComponents[colDef.type as GridColType])
+        : null;
 
     const applyFilterChanges = React.useCallback(
       (updatedItem: GridFilterItem) => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shukriya for the review
this solution is much better than that I have proposed earlier
I missed checking that it is already working in v6
thanks again :)

@MBilalShafi MBilalShafi added the type: regression A bug, but worse, it used to behave as expected. label Sep 6, 2024
@k-rajat19 k-rajat19 changed the title [data grid] Use disabled InputComponent for isEmpty and isNotEmpty filter operators [DataGridPro] Fix header filters rendering issue for isEmpty and isNotEmpty filter operators Sep 6, 2024
@MBilalShafi
Copy link
Copy Markdown
Member

Hey @k-rajat19
Thank you again for this pull request!

Your changes seem to impact the commercially licensed code. For any changes of this nature, we require contributors to sign the MUI’s Contributor License Agreement (CLA). However, I can’t find a CLA signed that could cover these changes. Please follow the steps at https://mui-org.notion.site/CLA-Contributor-License-Agreement-92ece655b1584b10b00e4de9e67eedb0 to sign the document.

@MBilalShafi MBilalShafi added the CLA: required Head to https://mui-org.notion.site/92ece655b1584b10b00e4de9e67eed. label Sep 6, 2024
@k-rajat19
Copy link
Copy Markdown
Contributor Author

I've sent the email to team-legal@mui.com

@zannager zannager added CLA: signed Head to https://mui-org.notion.site/92ece655b1584b10b00e4de9e67eed. and removed CLA: required Head to https://mui-org.notion.site/92ece655b1584b10b00e4de9e67eed. labels Sep 6, 2024
@zannager
Copy link
Copy Markdown
Member

zannager commented Sep 6, 2024

@MBilalShafi, CLA signed, thanks.

@mui-bot
Copy link
Copy Markdown

mui-bot commented Sep 6, 2024

Deploy preview: https://deploy-preview-14493--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 74d04b2

Copy link
Copy Markdown
Member

@MBilalShafi MBilalShafi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA: signed Head to https://mui-org.notion.site/92ece655b1584b10b00e4de9e67eed. feature: Filtering on header Related to the header filtering (Pro) feature scope: data grid Changes related to the data grid. type: regression A bug, but worse, it used to behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[data grid] Header Filters empty / no UI once isEmpty or isNotEmpty is selected

5 participants