Hello,
I have a radgrid with filters and I want my futur users to be able to perform ACCENT INSENSITIVE filtering.
I know this is not implemented in any version of telerik. But my client needs it so I have to do it.
Here's my solution...
In my grid, when a column can contain value with accents, I clone the column, replace all the accents ( é = e, ï = i, ù=u,...), and set the visible property of the cloned column to false (user won't see it).
Now, what i need to do is, when my user filter something, I catch the event using the ItemCommand event, I remove all the accent of the filter value ( i.e. "Pépin" = "Pepin") and perform the search on the hided column and show him the result.
My question is, how can i perform the search on the hided colum. At first, it looked very simple but I can't understand why it doesnt work.
Any help would be appreciated :D
I have a radgrid with filters and I want my futur users to be able to perform ACCENT INSENSITIVE filtering.
I know this is not implemented in any version of telerik. But my client needs it so I have to do it.
Here's my solution...
In my grid, when a column can contain value with accents, I clone the column, replace all the accents ( é = e, ï = i, ù=u,...), and set the visible property of the cloned column to false (user won't see it).
Now, what i need to do is, when my user filter something, I catch the event using the ItemCommand event, I remove all the accent of the filter value ( i.e. "Pépin" = "Pepin") and perform the search on the hided column and show him the result.
My question is, how can i perform the search on the hided colum. At first, it looked very simple but I can't understand why it doesnt work.
Any help would be appreciated :D
4 Answers, 1 is accepted
0

Alexis
Top achievements
Rank 1
answered on 03 Oct 2008, 07:27 PM
I found the solution !!
Here are the steps I made:
1. In my grid event NeedDataSource, for every column in my DataSet that has data with accent in it, I clone it, remove the accents, and hide it. Here's the function to remove the accent:
2. In the itemCommand event of my grid, I catch the filter events, check if it's from a column that has data with accent [ i.e. "RaisonSociale"], if so, I cancel the event, and fire a new one on the hidden colum [i.e. "RaisonSocialeFiltre"] with the same filtering expression and value but without accent using the same function as below.
3. Finally, in the ItemDataBound, I put back the original FilterValue provided to it's original place (in the filter textbox). I use a global variable named "FiltreOriginalClient" to do so.
4. That's it! It works, it's fast and it's transparent for the user. GREAT SUCCESS!
Here are the steps I made:
1. In my grid event NeedDataSource, for every column in my DataSet that has data with accent in it, I clone it, remove the accents, and hide it. Here's the function to remove the accent:
public static string RemoveDiacritics(string s) |
{ |
string normalizedString = s.Normalize(NormalizationForm.FormD); |
StringBuilder stringBuilder = new StringBuilder(); |
for (int i = 0; i < normalizedString.Length; i++) |
{ |
char c = normalizedString[i]; |
if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark) |
{ |
stringBuilder.Append(c); |
} |
} |
return stringBuilder.ToString(); |
} |
2. In the itemCommand event of my grid, I catch the filter events, check if it's from a column that has data with accent [ i.e. "RaisonSociale"], if so, I cancel the event, and fire a new one on the hidden colum [i.e. "RaisonSocialeFiltre"] with the same filtering expression and value but without accent using the same function as below.
protected void RadGridClients_ItemCommand(object source, GridCommandEventArgs e) |
{ |
if (e.CommandName == RadGrid.FilterCommandName) |
{ |
Pair laPaire = (Pair)e.CommandArgument; |
if (string.Compare((string)laPaire.Second, "RaisonSociale") == 0) |
{ |
e.Canceled = true; |
TextBox txtBox = (TextBox)((GridFilteringItem)e.Item)["RaisonSociale"].Controls[0]; |
FiltreOriginalClient = txtBox.Text; |
GridColumn colonneCachee = ((RadGrid)source).MasterTableView.GetColumnSafe("RaisonSocialeFiltre"); |
colonneCachee.CurrentFilterFunction = (GridKnownFunction)(Enum.Parse(typeof(GridKnownFunction), Convert.ToString(laPaire.First, CultureInfo.InvariantCulture), true)); |
colonneCachee.CurrentFilterValue = Utilitaire.RemoveDiacritics(txtBox.Text); |
((RadGrid)source).Rebind(); |
GridFilteringItem filterItem = ((RadGrid)source).MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem; |
filterItem.FireCommandEvent("Filter", new Pair((string)laPaire.First, "RaisonSocialeFiltre")); |
} |
} |
} |
3. Finally, in the ItemDataBound, I put back the original FilterValue provided to it's original place (in the filter textbox). I use a global variable named "FiltreOriginalClient" to do so.
protected void RadGridClients_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
// Utilisé pour remettre le filtre dans le textbox filtre en haut de la colonne RaisonSociale |
if (e.Item.ItemType == GridItemType.FilteringItem) |
{ |
if (!string.IsNullOrEmpty(((TextBox)((GridFilteringItem)e.Item)["RaisonSocialeFiltre"].Controls[0]).Text) && !string.IsNullOrEmpty(FiltreOriginalClient)) |
{ |
((TextBox)((GridFilteringItem)e.Item)["RaisonSociale"].Controls[0]).Text = FiltreOriginalClient; |
} |
} |
} |
4. That's it! It works, it's fast and it's transparent for the user. GREAT SUCCESS!
0

Alexandre
Top achievements
Rank 1
answered on 03 Oct 2008, 07:54 PM
"Great Success" is MY expression!!!
Good job buddy ;)
Good job buddy ;)
0

bjørn
Top achievements
Rank 1
answered on 25 Oct 2017, 09:22 PM
Unfortunately this doesn't work at all. Désolé, mais ça ne fonctionne pas!
0
Hello Bjørn,
I am afraid this requirement is not supported. You may come across some custom approaches over the net, however, these are beyond our support scope and we do not guarantee their viability.
Generally, you can add a new string field in your data source to hold "clean" values without any diacritics. Then, you can create a GridTemplateColumn with its DataField property set to "CleanField". In its ItemTemplate you can place a Label and set its Text to '<%# Eval("DiacriticsField") %>'.
Alternatively, you can create 2 columns and filter by the second column instead, which will be hidden, similar to the attached web site sample.
You can also check:
https://www.telerik.com/forums/sorting-unbound-column-onneeddatasource#NFYQrrz76UO-rJgUqK7gUA
I hope this will prove helpful.
Regards,
Eyup
Progress Telerik
I am afraid this requirement is not supported. You may come across some custom approaches over the net, however, these are beyond our support scope and we do not guarantee their viability.
Generally, you can add a new string field in your data source to hold "clean" values without any diacritics. Then, you can create a GridTemplateColumn with its DataField property set to "CleanField". In its ItemTemplate you can place a Label and set its Text to '<%# Eval("DiacriticsField") %>'.
Alternatively, you can create 2 columns and filter by the second column instead, which will be hidden, similar to the attached web site sample.
You can also check:
https://www.telerik.com/forums/sorting-unbound-column-onneeddatasource#NFYQrrz76UO-rJgUqK7gUA
I hope this will prove helpful.
Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.