-
-
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
[DataGrid] Allow to ignore diacritics when filtering #10569
Conversation
packages/grid/x-data-grid/src/hooks/features/filter/gridFilterUtils.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice enhancement, thanks for working on this. 👍
{{"demo": "QuickFilteringDiacritics.js", "bg": "inline", "defaultCodeOpen": false}} | ||
|
||
:::warning | ||
Note that `ignoreDiacritics` affects [regular filters](/x/react-data-grid/filtering/), [Quick filter](/x/react-data-grid/filtering/quick-filter/) and [Header filters](/x/react-data-grid/filtering/header-filters/) simultaneously. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this warning won't be necessary if we move this section to the customization page
Note that `ignoreDiacritics` affects [regular filters](/x/react-data-grid/filtering/), [Quick filter](/x/react-data-grid/filtering/quick-filter/) and [Header filters](/x/react-data-grid/filtering/header-filters/) simultaneously. | |
Note that `ignoreDiacritics` affects [normal filters](/x/react-data-grid/filtering/), [quick filter](/x/react-data-grid/filtering/quick-filter/) and [header filters](/x/react-data-grid/filtering/header-filters/) simultaneously. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make it explicit. Not everything on Customization page applies to all filter types
fn: getApplyQuickFilterFnV7(value, column, apiRef), | ||
})), | ||
appliers: quickFilterValues.map((quickFilterValue) => { | ||
const value = column.ignoreDiacritics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Does it make sense to make this a grid root prop? I guess not as it's only supported with string
types.
I am considering a less usual scenario with hundreds of columns with accented data where such a search is needed but users have to add ignoreDiacritics
to all of the colDefs, a root-level prop may save some time/hassle.
But I'm not sure about making this a root prop, since it's string
only. 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't necessarily just apply to string columns. Not sure what's the default date format but e.g. "February" is "février" in French so we can get diacritics elsewhere, and those are supposed to be searchable through the quickfilter. Any column can return a formatted localized (aka with diacritics) value with the .valueFormatter
also.
I think it might make sense to make it a root-level option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, for quick filters, it could apply to any column type.
For regular filters and header filters, it will only apply to the string column type.
I was thinking about where to put this option and decided to put it in GridColDef
to allow per-column configuration.
But it's a bit of a pain if you have a lot of columns and want to ignore diacritics in all of them.
This seems to emphasize a larger problem - we don't provide a way to pass something to all columns at once (or all columns of a certain type at once).
Regarding ignoreDiacritics
specifically, enabling it on the root level should cover most, if not all, use cases.
So this makes sense to me, I will update the demo and the docs 👍🏻
@cherniavskii hi,gm.Any update?maybe u can help,i watching this issue for few weeks |
@resatakks Thanks for the reminder, I'll update the PR to address the feedback from the team 👍🏻 |
@@ -175,6 +182,13 @@ const getFilterCallbackFromItem = ( | |||
} else { | |||
parsedValue = filterItem.value; | |||
} | |||
|
|||
const { ignoreDiacriticsInFiltering } = apiRef.current.getRootProps(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the getRootProps
method to be able to access ignoreDiacriticsInFiltering
here, otherwise, I had to pass the prop through in ~20 places 😅
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Could have even been just a field like apiRef.current.rootProps
, this is private anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to apiRef.current.rootProps
instead 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think?
Nice one, it could also be useful in some other places in the future too.
This comment was marked as resolved.
This comment was marked as resolved.
/** | ||
* If `true`, the diacritics (accents) are ignored when filtering or quick filtering. | ||
* * E.g. when filter value is `cafe`, the rows with `café` will be visible. | ||
* @default false | ||
*/ | ||
ignoreDiacriticsInFiltering: PropTypes.bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I like the naming, but I don't have anything better to propose atm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: To me personally, simply ignoreDiacritics
also makes sense, as the JSDoc comment will be sufficient to explain the relation with filtering. Also, the user using it should already be aware of what it does so maybe a little bit less explanatory title would make the prop name a bit simple?
params.value.toLocaleDateString('fr-FR', { | ||
day: 'numeric', | ||
month: 'long', | ||
year: 'numeric', | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sidenote but this is slow for formatters, not sure if we should show the more performant way in this example though. (using Intl.DateTimeFormat
directly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I didn't think about performance in this case.
However, the difference seems to be minimal (toLocaleDateString
being a bit faster): https://jsperf.app/lohope
Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.toLocaleDateString
builds a new Intl.DateTimeFormat
instance on each call. It's best to build an instance outside the loop, and re-use it for each call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another sidenote but I have also noticed in previous performance benchmarking that using the native Intl
formatter vs using a JS based one is much slower. Crossing the JS/C++ boundary is usually quite bad for performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, gotcha!
Here's a benchmark for the singleton formatter: https://jsperf.app/hutiwe
I'll update the demo.
using the native Intl formatter vs using a JS based one is much slower
I didn't know that, thanks for the heads-up 👍🏻
I think for demo purposes Intl.DateTimeFormat
is fine.
Closes #10376
Makes the workaround in #9817 (comment) unnecessary.
Preview: https://deploy-preview-10569--material-ui-x.netlify.app/x/react-data-grid/filtering/quick-filter/#ignore-diacritics-accents
TODO: