You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
diacritics-neutralise plugin enabled only for string columns. What about html ones? #569
First of all, I am discovering the benefits of dataTables and you guys did an amazing job.
I recently needed the search to ignore diacritics, so I found the diacritics-neutralize plugin. At first sight, it didn't work.
After diving into the code, I realised it's only enabled for string columns. But the column I wanted to filter were html ones.
So I fixed this by adding the snippet below, at the end of the diacritics-neutralise.js file:
jQuery.fn.DataTable.ext.type.search.html = function (s) {
return removeDiacritics(s)
};
It seems to be working fine with HTML columns now. Maybe you can provide an option to search there are well? Not really familiar with the plugin framework to be able to post a PR, hence opened an issue for your consideration.
Thanks! Yes, I'll look into this. Having some form of diacritic support built into DataTables is something I want to add, so I'll look into this when I do that. Can't be certain when that will be though...
The same applies for sorting plugin - if diacritics sort plugin is used, it only works fro string columns. If column contains any HTML data, diacritics sorting doesn't work.
DataTables 2 effectively has this ability built in. This plug-in is no longer useful. If you are having problems with that ability, please link to a test case showing the issue.
Yes, DT 2.0 has diacritics filtering built-in, and it works perfectly! Unfortunately, that doesn't apply to sorting, so I still have to use this plugin - https://datatables.net/plug-ins/sorting/diacritics-sort. Unfortunately, plugin doesn't work if column contains HTML data.
See "Name" column, which contains names with diacritics. In default state, names are sorted alphabetically. However, when names get sorted alphabetically by DT, sorting is wrong because DT orders names without diacritics first, and moves names with diacritics to the bottom.
If I add sorting plugin, it works as long as column with names doesn't have any HTML tags. Once HTML is added to some rows, ordering doesn't work again.
Thank you for the test case! The fix is fairly straight forward - we need to tell DataTables to use localeCompare rather than straight character number sorting. That can be done with the new DataTable.type() method:
You'd need to do similar for html data type as well if you needed that.
Should DataTables do that by default? Very possibly. I didn't include it a while back because of the impact on performance. That might have changed with updates to the Javascript engines. I'll look into it again.
Thanks for the example. I just want to let you know that code for desc contains a small typo and should be return b.localeCompare(a); (otherwise sorting descending will change nothing and items will be sorted ascending)
By the way, I'm not sure if you are aware that adding data-order tag prevents diacritics filter from working. See example here - https://live.datatables.net/dayodoli/4/edit - I just added data-order attribute to names, and diacritics filter doesn't work. In fact, even if you enter whole name correctly (with or without diacritics) into search field, DT2 can't find it.
I use a workaround now: add some random string to data-order attribute. For example, if I change data-order="1" to data-order="random-1", filtering starts working again.
Activity
AllanJard commentedon Aug 11, 2023
Thanks! Yes, I'll look into this. Having some form of diacritic support built into DataTables is something I want to add, so I'll look into this when I do that. Can't be certain when that will be though...
toxpal commentedon Mar 8, 2024
The same applies for sorting plugin - if diacritics sort plugin is used, it only works fro string columns. If column contains any HTML data, diacritics sorting doesn't work.
AllanJard commentedon Mar 9, 2024
DataTables 2 effectively has this ability built in. This plug-in is no longer useful. If you are having problems with that ability, please link to a test case showing the issue.
toxpal commentedon Mar 9, 2024
Yes, DT 2.0 has diacritics filtering built-in, and it works perfectly! Unfortunately, that doesn't apply to sorting, so I still have to use this plugin - https://datatables.net/plug-ins/sorting/diacritics-sort. Unfortunately, plugin doesn't work if column contains HTML data.
Here's an example using DT2 - https://live.datatables.net/dayodoli/1/edit
See "Name" column, which contains names with diacritics. In default state, names are sorted alphabetically. However, when names get sorted alphabetically by DT, sorting is wrong because DT orders names without diacritics first, and moves names with diacritics to the bottom.
If I add sorting plugin, it works as long as column with names doesn't have any HTML tags. Once HTML is added to some rows, ordering doesn't work again.
AllanJard commentedon Mar 10, 2024
Thank you for the test case! The fix is fairly straight forward - we need to tell DataTables to use
localeComparerather than straight character number sorting. That can be done with the newDataTable.type()method:Example here: https://live.datatables.net/dayodoli/3/edit .
You'd need to do similar for
htmldata type as well if you needed that.Should DataTables do that by default? Very possibly. I didn't include it a while back because of the impact on performance. That might have changed with updates to the Javascript engines. I'll look into it again.
edited Fix from below.
toxpal commentedon Mar 12, 2024
Thanks for the example. I just want to let you know that code for desc contains a small typo and should be
return b.localeCompare(a);(otherwise sorting descending will change nothing and items will be sorted ascending)AllanJard commentedon Mar 12, 2024
Doh - good point! I've updated my post in case anyone else gets caught by that.
toxpal commentedon Mar 13, 2024
By the way, I'm not sure if you are aware that adding
data-ordertag prevents diacritics filter from working. See example here - https://live.datatables.net/dayodoli/4/edit - I just addeddata-orderattribute to names, and diacritics filter doesn't work. In fact, even if you enter whole name correctly (with or without diacritics) into search field, DT2 can't find it.I use a workaround now: add some random string to
data-orderattribute. For example, if I changedata-order="1"todata-order="random-1", filtering starts working again.