-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[data grid] Format value shown in the filter button tooltip #5492
Comments
We have this same problem with every operator. In the tooltip, we display the value as it is, without any formatting. Another example is the date operator which doesn't format the value to the user's locale. The date should be displayed as dd/mm/YYYY to me. I propose to add a function to diff --git a/packages/grid/x-data-grid/src/models/gridFilterOperator.ts b/packages/grid/x-data-grid/src/models/gridFilterOperator.ts
index 5fc3586d8..ccc50308c 100644
--- a/packages/grid/x-data-grid/src/models/gridFilterOperator.ts
+++ b/packages/grid/x-data-grid/src/models/gridFilterOperator.ts
@@ -42,4 +42,10 @@ export interface GridFilterOperator<R extends GridValidRowModel = any, V = any,
* The props to pass to the input component in the filter panel for this filter operator.
*/
InputComponentProps?: Record<string, any>;
+ /**
+ * Converts the value of a filter item to a human-readable form.
+ * @param {GridFilterItem['value']} value The filter item value.
+ * @returns {string} The value formatted to be displayed in the UI.
+ */
+ getValueAsString?: (value: GridFilterItem['value']) => string;
} Then, in the filter button, we call it if it's available: diff --git a/packages/grid/x-data-grid/src/components/toolbar/GridToolbarFilterButton.tsx b/packages/grid/x-data-grid/src/components/toolbar/GridToolbarFilterButton.tsx
index 3206f2833..ef0dde140 100644
--- a/packages/grid/x-data-grid/src/components/toolbar/GridToolbarFilterButton.tsx
+++ b/packages/grid/x-data-grid/src/components/toolbar/GridToolbarFilterButton.tsx
@@ -76,6 +76,13 @@ const GridToolbarFilterButton = React.forwardRef<HTMLButtonElement, GridToolbarF
.getLocaleText(`filterOperator${capitalize(item.operatorValue!)}` as GridTranslationKeys)!
.toString();
+ const getFilterItemValue = (item: GridFilterItem): string => {
+ const { getValueAsString } = lookup[item.columnField!].filterOperators!.find(
+ (operator) => operator.value === item.operatorValue,
+ )!;
+ return getValueAsString ? getValueAsString(item.value) : item.value;
+ };
+
return (
<div>
{apiRef.current.getLocaleText('toolbarFiltersTooltipActive')(activeFilters.length)}
@@ -85,7 +92,7 @@ const GridToolbarFilterButton = React.forwardRef<HTMLButtonElement, GridToolbarF
<li key={index}>
{`${lookup[item.columnField!].headerName || item.columnField}
${getOperatorLabel(item)}
- ${item.value}`}
+ ${getFilterItemValue(item)}`}
</li>
)),
}))}
You can disable the tooltip by providing a custom filter button. Here's an example: https://codesandbox.io/s/customtoolbargrid-demo-mui-x-forked-miy29h?file=/demo.tsx |
Hi all! I was about to create an issue but found this one while looking for duplicates. Cheers! |
I have the same problem in DataGridPremium. |
Hi all! With PR #6956 merged, to customize the value displayed I have to do something like this: filterOperators: getGridSingleSelectOperators().map((operator) => {
return {
...operator,
getValueAsString: (value) => {
// Handle anyOf operator
if (Array.isArray(value)) {
return value.map((v) => getStatusLabel(v)).join(', ')
}
return getStatusLabel(value)
},
}
}), I think this is an overcomplicated solution because, in most use cases, the users want to see the same label of the selected options in the filter tooltip. Wouldn't it be better, for Let me know what you all think! :) |
Hello, @TiagoPortfolio. I faced the same problem and see the followings solution options:
I hope @m4theushw could help us. |
is there any update to this issue? |
Any futher update to this? |
Bump. |
Hi, folks! End-users and developers are most likely expecting the label to appear in the tooltip, so I'll modify the However, given the function name Please check the details in the PR. |
Order ID 💳
44899
Duplicates
Latest version
The problem in depth 🔍
I set valueOptions wich is array of objects and operator isAnyOf, but when i read filterModel it is changed to array of values. The issue is that info tooltip of filtered values shows values instead of labels. Is there any way how to read tooltip of labels instead of values or disable tooltip info?
Column setting
Tooltip info
Filter model
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: