Fossil SCM

Make table sorting (by clicking on column headers) stable. In other words, identical values in the column being sorted preserve their prior relative order. Patch suggested by Jacek Cała.

drh 2015-01-22 22:52 trunk
Commit fe61f4958d1b8983cf051922d35648d63674508a
1 file changed +3 -2
+3 -2
--- src/report.c
+++ src/report.c
@@ -999,27 +999,28 @@
999999
@ }
10001000
@ this.sortText = function(a,b) {
10011001
@ var i = thisObject.sortIndex;
10021002
@ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
10031003
@ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
1004
- @ if(aa==bb) return 0;
1004
+ @ if(aa==bb) return a.rowIndex-b.rowIndex;
10051005
@ if(aa<bb) return -1;
10061006
@ return 1;
10071007
@ }
10081008
@ this.sortNumeric = function(a,b) {
10091009
@ var i = thisObject.sortIndex;
10101010
@ aa = parseFloat(a.cells[i].textContent);
10111011
@ if (isNaN(aa)) aa = 0;
10121012
@ bb = parseFloat(b.cells[i].textContent);
10131013
@ if (isNaN(bb)) bb = 0;
1014
+ @ if(aa==bb) return a.rowIndex-b.rowIndex;
10141015
@ return aa-bb;
10151016
@ }
10161017
@ this.sortKey = function(a,b) {
10171018
@ var i = thisObject.sortIndex;
10181019
@ aa = a.cells[i].getAttribute("data-sortkey");
10191020
@ bb = b.cells[i].getAttribute("data-sortkey");
1020
- @ if(aa==bb) return 0;
1021
+ @ if(aa==bb) return a.rowIndex-b.rowIndex;
10211022
@ if(aa<bb) return -1;
10221023
@ return 1;
10231024
@ }
10241025
@ var x = tableEl.getElementsByTagName('thead');
10251026
@ if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
10261027
--- src/report.c
+++ src/report.c
@@ -999,27 +999,28 @@
999 @ }
1000 @ this.sortText = function(a,b) {
1001 @ var i = thisObject.sortIndex;
1002 @ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
1003 @ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
1004 @ if(aa==bb) return 0;
1005 @ if(aa<bb) return -1;
1006 @ return 1;
1007 @ }
1008 @ this.sortNumeric = function(a,b) {
1009 @ var i = thisObject.sortIndex;
1010 @ aa = parseFloat(a.cells[i].textContent);
1011 @ if (isNaN(aa)) aa = 0;
1012 @ bb = parseFloat(b.cells[i].textContent);
1013 @ if (isNaN(bb)) bb = 0;
 
1014 @ return aa-bb;
1015 @ }
1016 @ this.sortKey = function(a,b) {
1017 @ var i = thisObject.sortIndex;
1018 @ aa = a.cells[i].getAttribute("data-sortkey");
1019 @ bb = b.cells[i].getAttribute("data-sortkey");
1020 @ if(aa==bb) return 0;
1021 @ if(aa<bb) return -1;
1022 @ return 1;
1023 @ }
1024 @ var x = tableEl.getElementsByTagName('thead');
1025 @ if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
1026
--- src/report.c
+++ src/report.c
@@ -999,27 +999,28 @@
999 @ }
1000 @ this.sortText = function(a,b) {
1001 @ var i = thisObject.sortIndex;
1002 @ aa = a.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
1003 @ bb = b.cells[i].textContent.replace(/^\W+/,'').toLowerCase();
1004 @ if(aa==bb) return a.rowIndex-b.rowIndex;
1005 @ if(aa<bb) return -1;
1006 @ return 1;
1007 @ }
1008 @ this.sortNumeric = function(a,b) {
1009 @ var i = thisObject.sortIndex;
1010 @ aa = parseFloat(a.cells[i].textContent);
1011 @ if (isNaN(aa)) aa = 0;
1012 @ bb = parseFloat(b.cells[i].textContent);
1013 @ if (isNaN(bb)) bb = 0;
1014 @ if(aa==bb) return a.rowIndex-b.rowIndex;
1015 @ return aa-bb;
1016 @ }
1017 @ this.sortKey = function(a,b) {
1018 @ var i = thisObject.sortIndex;
1019 @ aa = a.cells[i].getAttribute("data-sortkey");
1020 @ bb = b.cells[i].getAttribute("data-sortkey");
1021 @ if(aa==bb) return a.rowIndex-b.rowIndex;
1022 @ if(aa<bb) return -1;
1023 @ return 1;
1024 @ }
1025 @ var x = tableEl.getElementsByTagName('thead');
1026 @ if(!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length>0)){
1027

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button