Skip to content

Commit 6750a5d

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

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

docs/pages/x/api/data-grid/grid-filter-operator.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { GridFilterOperator } from '@mui/x-data-grid';
1717
| Name | Type | Default | Description |
1818
| :---------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1919
| <span class="prop-name">getApplyFilterFn</span> | <span class="prop-type">(filterItem: GridFilterItem, column: GridStateColDef&lt;R, V, F&gt;) =&gt; null \| ((params: GridCellParams&lt;V, R, F&gt;) =&gt; boolean)</span> | | The callback that generates a filtering function for a given filter item and column.<br />This function can return `null` to skip filtering for this item and column. |
20+
| <span class="prop-name optional">getValueAsString<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">(value: GridFilterItem['value']) =&gt; string</span> | | Converts the value of a filter item to a human-readable form. |
2021
| <span class="prop-name optional">InputComponent<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">React.JSXElementConstructor&lt;GridFilterInputValueProps&gt; \| React.JSXElementConstructor&lt;GridFilterInputMultipleValueProps&gt; \| React.JSXElementConstructor&lt;GridFilterInputMultipleSingleSelectProps&gt;</span> | | The input component to render in the filter panel for this filter operator. |
2122
| <span class="prop-name optional">InputComponentProps<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">Record&lt;string, any&gt;</span> | | The props to pass to the input component in the filter panel for this filter operator. |
2223
| <span class="prop-name optional">label<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">string</span> | | The label of the filter operator. |

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)