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.19k stars 898 forks source link

Sorting order errors #385

Open javve opened 8 years ago

javve commented 8 years ago

I'm adding this issue as a collection of all sorting order related issues.

saschanos commented 8 years ago
bildschirmfoto 2016-02-28 um 17 32 24

"ü" is before "y"; in descending order

loulafripouille commented 8 years ago

hello,

The sorting order fails on this case : http://codepen.io/anon/pen/VaKgZB Two almost identical values, but one with a number a the end.

dl1ely commented 8 years ago

@laudeon Thanks that i am not alone. Sorting fails for me in exact the same way. I am no javascript guru, i have no idea what is going wrong there. Any advice?

CBeloch commented 8 years ago

Having the same issue.

http://codepen.io/CBeloch/pen/RaLepP

It works when I rename the "PlayStation" to "PlayStation 1". The naturalSort fails because the normChunk method gets undefined as the first parameter. I fixed it by adding

if (!s) {
  return 0;
}

at the beginning

Pull request hast been submitted

EugeneTM commented 7 years ago

The sorting fails when the search variable contains mixed cyrilics (unicode?) and digits. Let's say, we have four values: RA1, RA2, ЗЫ1, ЗЫ2. First two are sorted correctly, second two do not sort at all. By the way, cyrillics without numbers is sorted well: for example, { Мартина, Густав } (Martina, Gustav) sorted correctly though. Codepen: http://codepen.io/anon/pen/qawvNm Now I'm trying to narrow the bug.

BTW, I found an error:

if (/[^\x00-\x80]/.test(oFxNcL + oFyNcL) && oFxNcL.localeCompare) {
                        var comp = oFxNcL.localeCompare(oFyNcL);
                        return comp / Math.abs(comp);
}

If both Unicode strings are equal, comp = 0, so we return 0/0. Also there's error should not set zero on this level, so we add if. As the localeCompare method returns either -1, 0 or 1, we don't need division, so the code shoud be, it seems,

if (/[^\x00-\x80]/.test(oFxNcL + oFyNcL) && oFxNcL.localeCompare) {
                        var comp = oFxNcL.localeCompare(oFyNcL);
                        if (comp !== 0) return comp;
}

Please check my solution.

darren131 commented 7 years ago

Hi I'm having a number sorting issue... I have hundreds of values e.g. 1.23; -0.23, 0.02 etc But the out of the box sorting doesn't seem to handle it... Any thoughts? The site is here: https://www.biopharmcatalyst.com/companies/company-pipeline-database (hit the change th)

We're using data attributes to apply the sort.