Skip to content

Loading…

Empty values sorted incorrectly #185

Open
enlait opened this Issue · 10 comments

6 participants

@enlait

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

@javve
Owner
@adrien-be

seems to work smoothly, see http://jsfiddle.net/qwtwL/

@rsl

i'm having this problem as well: http://jsfiddle.net/7syUK/2/ definitely not working smoothly universally

@rsl

http://jsfiddle.net/7syUK/6/ 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: https://github.com/javve/list.js/blob/master/dist/list.js#L639-L640 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.

@adrien-be

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: http://jsfiddle.net/qAw2t/

@rsl

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.

@RiZKiT

If there is a solution, i suggest someone should check the solution against the original unit tests in this project too: https://github.com/overset/javascript-natural-sort

@adrien-be

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.
    see http://jsfiddle.net/wvtphqas/

  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 http://jsfiddle.net/wvtphqas/
    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 http://jsfiddle.net/aw21jcbg/

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
Open

Sorting incorrect when there is a space #7

@adrien-be

As pointed out above, this issue is probably coming from the "natural sort" algorithm, https://github.com/javve/natural-sort

It is used here https://github.com/javve/list.js/blob/master/dist/list.js#L607 (line 607 to 652).

@anonymoushenchman

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.