javve / list.js

The perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML.
https://listjs.com
MIT License
11.2k stars 896 forks source link

Support for UTF-8 special characters #178

Closed ardziej closed 8 years ago

ardziej commented 10 years ago

Hi,is it possible to support polish characters in searching or filtering ? http://webdesign.about.com/od/localization/l/blhtmlcodes-pl.htm Strings with special characters are not properly working.

javve commented 10 years ago

Hmm.. could you make a JSFiddle/JSpen/JSbin that shows this problem? What happens?

ardziej commented 10 years ago

Thanks. Look at this: http://jsfiddle.net/36GHg/3/ This is generally problem of JavaScript. How is that possible that JS doesn't support UTF-8 at all ?

seb-vial commented 10 years ago

There might be a fix for that. In the list.js file line 1105 (in the current master version), replace

return naturalSort(a.values()[valueName], b.values()[valueName], options);

By

return naturalSort(encodeURIComponent(a.values()[valueName]), encodeURIComponent(b.values()[valueName]), options);

I had the same issue with A and À now the À is first and the A is second, I know you want Ą to be second but I was also sure that À should have been afer A, turned out (after checking in dictionnary (France)) that words beginning by À are listed before words beginning by A.

Hope it helps you

koocotte commented 10 years ago

I don't think this will work better. Some characters, depending of browser, will be translated into %XX, and the '%' character will be before any alphabetic character. This as nothing to do with locale sort.

In French (and in France, I'm french), 'À' and 'A', and 'Â' also, and any accentuated character is sorted exactly as if it does not have an accent; and 'Œ' is between 'O' and 'P'. If I take a random page, I have 'accepter', then 'accès', then 'accessible'.

Sorting is dependant of locale, not every language sort characters the same way; and according to http://stackoverflow.com/questions/6909126/javascript-sort-with-unicode; the "less wrong way" is to sort using String.localeCompare(); which will work using the locale configured in the user browser. This will not be right in any case; but better than nothing.

javve commented 8 years ago

I'll close this with a reference to this issue: #385