kylefox/jquery-tablesort

Inaccurate Sorting Comparison

calsyfur opened this issue · 0 comments

[tablesort] Sorting by null desc
545 0 1
545 30 1
0 30 -1
70 30 1
40 30 1
580 30 1
30 30 0
550 30 1
530 30 1
25 30 -1
0 30 -1
30 30 0
25 0 1
0 0 0
545 70 -1   <------------- incorrect comparison
545 40 1
40 580 -1
545 580 -1
70 580 1
40 550 -1
545 550 -1
580 550 1
40 530 -1
545 530 1
[tablesort] Sort finished in 33ms

So I am experience a lot of sorting issues. I edited the tablesort to console.log the comparisons and have found that the comparisons are not accurate. There is only one inaccurate calculation here, but I also tested with another set of data and there are more than one.

Data is found using:

console.log(a.value, b.value, self.settings.compare(a.value, b.value))

Comparison function:

compare: function(a, b) {
	if (a > b) {
		return 1;
	} else if (a < b) {
		return -1;
	} else {
		return 0;
	}
}

Also, I am using handlebars... not sure if that affects it. I have tested it without handlebars and still getting wrong output. Codepen: https://codepen.io/anon/pen/aJeJYY