Skip to content


Empty values sorted incorrectly #185

enlait opened this Issue · 10 comments

6 participants


There's a regression bug, the issue was fixed in alphanumeric sort #136 but is present in natural sort algorithm used now. As a result, empty strings are always on top, whatever the sort direction.

The correct way would be not to do any string replacement at all if one of (or both) passed values are null/empty


seems to work smoothly, see


i'm having this problem as well: definitely not working smoothly universally

@rsl shows the difference between how it handles '', ' ', and ' '. i can work around via the non-breaking space but for most users how this natural sort handles empty strings is incorrect. the issue seems to be here: but i find that js kinda inscrutable and have little clue how to fix [also it's a source you're pulling in from upstream so not sure how to submit a pull request on that anyhow]. hopefully my digging into this helps you be able to find the issue and a solution. let me know if i can help anymore.


I just found out that this feature works... but only if the value in the TDs are numbers.
See in your example if you replace the PP1 & PP2 by numbers:


that makes sense because it does some kind of coercion of empty strings to 0 for comparisons. which causes isNaN comparisons to not be the same and returns undesired results.


If there is a solution, i suggest someone should check the solution against the original unit tests in this project too:


On a similar subject:

  1. when sorting cells where some cells "only have NUMBERS" & some other cells have "numbers and letters" it seems that the cells with numbers always come first.

  2. when sorting cells where some cells "only have LETTERS " & some other cells have "numbers and letters" it seems:
    2.a if the cells with numbers & letters start by a letter: everything runs as expected, see
    2,b if the cells with numbers & letters start by a number: we run again in the same pb, the cells starting with a number always come first, see

My understanding is that these bugs may have something in common with the "empty values sorted incorrectly" bug. Although I may be wrong.

Finally, it seems that list.js does need some clean up on those main functionnalities.
In the end, as much as I like list.js, why would one use list.js knowing there is such as silly bug ?
I will try to help out at commiting some fix.

@adrien-be adrien-be referenced this issue in javve/natural-sort

Sorting incorrect when there is a space #7


As pointed out above, this issue is probably coming from the "natural sort" algorithm,

It is used here (line 607 to 652).


I'm all fresh to web dev, but it looks like this hasn't been fixed yet.
A workaround I found was to append a zero-width-non-joiner (‌) to the text that was being searched, e.g.:

<td class="firstname" ><c:out value="${firstname.value}" />&zwnj;</td>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.