Filtering strings independently from diacritics #140

Closed
opened 2026-01-29 17:32:12 +00:00 by claunia · 4 comments
Owner

Originally created by @OndrejUzovic on GitHub (Jun 25, 2021).

Currently DataGrid filter requires from users to enter the filtering string with exact diacritics, otherwise it is filtered out.

E.g. if the column filter operator is set to 'startswith' and it is 'CaseInsensitive' and we have following data in the column:
• Čerešňa
• Čučoriedka
• Marhuľa

Then if the user writes the character 'c' into the filter then everything is filtered out because 'c' is considered different from 'č'.
However, in such use-cases users with diacritic languages expect the filter understands that 'c' is equal to 'č'.

I think solving this issue is not so difficult. It is just needed to use CultureInfo.InvariantCulture.CompareInfo methods instead of standard String methods:

// instead of StartsWith(...)
CultureInfo.InvariantCulture.CompareInfo.IsPrefix(text, filterString, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace);
...
// instead of EndsWith(...)
CultureInfo.InvariantCulture.CompareInfo.IsSuffix(text, filterString, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace);
...
// instead of Contains(...)
CultureInfo.InvariantCulture.CompareInfo.IndexOf(text, filterString, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace) != -1;

I think using those methods would need to be incorporated into the method:
static string QueryableExtension.GetColumnFilter<T>(RadzenGridColumn<T> column, bool second = false)

Originally created by @OndrejUzovic on GitHub (Jun 25, 2021). Currently DataGrid filter requires from users to enter the filtering string with exact diacritics, otherwise it is filtered out. E.g. if the column filter operator is set to 'startswith' and it is 'CaseInsensitive' and we have following data in the column: • Čerešňa • Čučoriedka • Marhuľa Then if the user writes the character 'c' into the filter then everything is filtered out because 'c' is considered different from 'č'. However, in such use-cases users with diacritic languages expect the filter understands that 'c' is equal to 'č'. I think solving this issue is not so difficult. It is just needed to use CultureInfo.InvariantCulture.CompareInfo methods instead of standard String methods: ``` // instead of StartsWith(...) CultureInfo.InvariantCulture.CompareInfo.IsPrefix(text, filterString, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace); ... // instead of EndsWith(...) CultureInfo.InvariantCulture.CompareInfo.IsSuffix(text, filterString, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace); ... // instead of Contains(...) CultureInfo.InvariantCulture.CompareInfo.IndexOf(text, filterString, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace) != -1; ``` I think using those methods would need to be incorporated into the method: `static string QueryableExtension.GetColumnFilter<T>(RadzenGridColumn<T> column, bool second = false)`
Author
Owner

@akorchev commented on GitHub (Jun 25, 2021):

I don't think this would work with Entity Framework. Did you test it? Filtering is done at database level.

@akorchev commented on GitHub (Jun 25, 2021): I don't think this would work with Entity Framework. Did you test it? Filtering is done at database level.
Author
Owner

@OndrejUzovic commented on GitHub (Jun 25, 2021):

You are right this will not work on the EF level. I was just wondering if this filtering could work for cases when DataGrid is not connected directly to DB.

@OndrejUzovic commented on GitHub (Jun 25, 2021): You are right this will not work on the EF level. I was just wondering if this filtering could work for cases when DataGrid is not connected directly to DB.
Author
Owner

@akorchev commented on GitHub (Jun 25, 2021):

It would probably work but would also require us to have two different filtering implementations. To be honest in most cases the data grid is bound to either some sort of service that supports filtering or to EF IQueryable. The case for in memory sorting and filtering is too niche IMHO.

@akorchev commented on GitHub (Jun 25, 2021): It would probably work but would also require us to have two different filtering implementations. To be honest in most cases the data grid is bound to either some sort of service that supports filtering or to EF IQueryable. The case for in memory sorting and filtering is too niche IMHO.
Author
Owner

@OndrejUzovic commented on GitHub (Jun 25, 2021):

Ok, I understand, it probably would not be in align with your DataGrid idea.
Therefore I am closing this feature request.

@OndrejUzovic commented on GitHub (Jun 25, 2021): Ok, I understand, it probably would not be in align with your DataGrid idea. Therefore I am closing this feature request.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#140