Skip to content

Commit 1c6c38d

Browse files
author
Владимир Колесников
committed
fix filter value in filter button tooltip
1 parent e7ef03a commit 1c6c38d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/grid/x-data-grid/src/components/toolbar/GridToolbarFilterButton.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ const GridToolbarFilterButton = React.forwardRef<HTMLButtonElement, GridToolbarF
7878
.getLocaleText(`filterOperator${capitalize(item.operatorValue!)}` as GridTranslationKeys)!
7979
.toString();
8080

81+
const getFilterItemValue = (item: GridFilterItem): string => {
82+
const { getValueAsString } = lookup[item.columnField!].filterOperators!.find(
83+
(operator) => operator.value === item.operatorValue,
84+
)!;
85+
86+
return getValueAsString ? getValueAsString(item.value) : item.value;
87+
};
88+
8189
return (
8290
<div>
8391
{apiRef.current.getLocaleText('toolbarFiltersTooltipActive')(activeFilters.length)}
@@ -87,7 +95,7 @@ const GridToolbarFilterButton = React.forwardRef<HTMLButtonElement, GridToolbarF
8795
<li key={index}>
8896
{`${lookup[item.columnField!].headerName || item.columnField}
8997
${getOperatorLabel(item)}
90-
${item.value ?? ''}`}
98+
${item.value ? getFilterItemValue(item.value) : ''}`}
9199
</li>
92100
)),
93101
}))}

packages/grid/x-data-grid/src/models/gridFilterOperator.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export interface GridFilterOperator<R extends GridValidRowModel = any, V = any,
4242
* The props to pass to the input component in the filter panel for this filter operator.
4343
*/
4444
InputComponentProps?: Record<string, any>;
45+
/**
46+
* Converts the value of a filter item to a human-readable form.
47+
* @param {GridFilterItem['value']} value The filter item value.
48+
* @returns {string} The value formatted to be displayed in the UI.
49+
*/
50+
getValueAsString?: (value: GridFilterItem['value']) => string;
4551
/**
4652
* If `false`, filter operator doesn't require user-entered value to work.
4753
* Usually should be set to `false` for filter operators that don't have `InputComponent` (for example `isEmpty`)

0 commit comments

Comments
 (0)