tonytomov / jqGrid

jQuery grid plugin
www.trirand.com
2.84k stars 1.2k forks source link

Local special characters are sorted wrong when sorting columns. Please change to localeCompare() #982

Closed SKPFCW closed 3 years ago

SKPFCW commented 3 years ago

German umlauts appear after sorting at the end of the list instead of in their correct place. JavaScript localeCompare-Method should be used instead of greater/less-comparison.

For example: Correct sorting would be: Am, An, Ao, , Ap, Aq

Wrong sorting in jqGrid is: Am, An, Ao, Ap, Aq,

The error occurs in the function this._compare by using binary greater-/less-than comparison: (Versions 5.5.4 and before)

529: this._compare = function (a, b, d) {
...
552:     if (a <b) {return -d;}
553:     if (a> b) {return d;}
554:     return 0;

Hotfix by using the JS localeCompare()-method:

552:-3     if (typeof a === "string") {
552:-2         return a.localeCompare(b) * d;
552:-1    } else {
552:             if (a <b) {return -d; }
553:             if (a> b) {return d; }
554:             return 0;
554:+1    }
tonytomov commented 3 years ago

I have fixed the problem. You can check it. Please let me know if it is ok for you.

SKPFCW commented 3 years ago

It works great. Thank you for your quick and helpful support.

tonytomov commented 3 years ago

I will close the issue. Feel free to reopen it, if there is a problem