30e8abab05cf2b9f2775dcba58efaea493096915
kate
  Fri Jan 23 16:57:04 2015 -0800
Fix table sort bug (wasn't doing subsorts on columns other than the clicked one). refs #14723
diff --git src/hg/js/utils.js src/hg/js/utils.js
index 3963c35..73e83d2 100644
--- src/hg/js/utils.js
+++ src/hg/js/utils.js
@@ -1600,46 +1600,46 @@
     //    };
 
     // These 2 globals are used during setTimeout, so that rows can be hidden while sorting
     // and javascript timeout on slow (IE) browsers is less likely
     columns: null,
     tbody: null,
     loadingId: null,
     caseSensitive: false, // sorts are case INSENSITIVE by default
 
     sortCaseSensitive: function (sensitive)
     {   // set case senstivity, which can be added to each sortable columnn's onclick event.
         // or set for the whole table right after initialize()
         sortTable.caseSensitive = sensitive;
     },
 
-    row: function (tr,sortColumns,row)  // UNUSED: sortTable.fieldCmp works fine
+    row: function (tr,sortColumns)
     {
         this.fields  = [];
         this.reverse = [];
-        this.row     = row;
+        this.row = tr;
         for (var ix=0; ix < sortColumns.cellIxs.length; ix++)
             {
-            var th = tr.cells[sortColumns.cellIxs[ix]];
-            this.fields[ix]  = (sortColumns.useAbbr[ix] ? th.abbr : $(th).text());
+            var cell = tr.cells[sortColumns.cellIxs[ix]];
+            this.fields[ix]  = (sortColumns.useAbbr[ix] ? cell.abbr : $(cell).text());
             if (!sortTable.caseSensitive) 
                 this.fields[ix]  = this.fields[ix].toLowerCase(); // case insensitive sorts
             this.reverse[ix] = sortColumns.reverse[ix];
             }
     },
 
-    rowCmp: function (a,b)  // UNUSED: sortTable.fieldCmp works fine
+    rowCmp: function (a,b)
     {
         for (var ix=0; ix < a.fields.length; ix++) {
             if (a.fields[ix] > b.fields[ix])
                 return (a.reverse[ix] ? -1:1);
             else if (a.fields[ix] < b.fields[ix])
                 return (a.reverse[ix] ? 1:-1);
         }
         return 0;
     },
 
     field: function (value,reverse,row)
     {
         if (sortTable.caseSensitive || typeof(value) !== 'string') 
             this.value   = value;
         else
@@ -1655,46 +1655,44 @@
         else if (a.value < b.value)
             return (a.reverse ? 1:-1);
         return 0;
     },
 
     sort: function (tbody,sortColumns)
     {// Sorts table based upon rules passed in by function reference
     // Expects tbody to not sort thead, but could take table
 
         // The sort routine available is javascript array.sort(), which cannot sort rows directly
         // Until we have jQuery >=v1.4, we cannot easily convert tbody.rows[] inot a javascript array
         // So we will make our own array, sort, then then walk through the table and reorder
         // FIXME: Until better methods are developed, only sortOrder based sorts are supported
         //        and fnCompare is obsolete
 
-        // Create array of the primary sort column's text
-        var cols = [];
+        // Create an array of rows to sort
+        var rows = [];
         var trs = tbody.rows;
         $(trs).each(function(ix) {
-            var th = this.cells[sortColumns.cellIxs[0]];
-            if (sortColumns.useAbbr[0])
-                cols.push(new sortTable.field(th.abbr,sortColumns.reverse[0],this));
-            else
-                cols.push(new sortTable.field($(th).text(),sortColumns.reverse[0],this));
+            rows.push(new sortTable.row(this, sortColumns));
         });
 
         // Sort the array
-        cols.sort(sortTable.fieldCmp);
+        rows.sort(sortTable.rowCmp);
 
         // most efficient reload of sorted rows I have found
-        var sortedRows = jQuery.map(cols, function(col, i) { return col.row; });
+        var sortedRows = jQuery.map(rows, function(row, i) { 
+                return row.row; 
+        });
         $(tbody).append(sortedRows);
 
         sortTable.tbody=tbody;
         sortTable.columns=sortColumns;
         // Avoid js timeout
         setTimeout(function() { 
                         sortTable.sortFinish(sortTable.tbody,sortTable.columns); 
                     },5);
     },
 
     sortFinish: function (tbody,sortColumns)
     {   // Additional sort cleanup.
         // This is in a separate function to allow calling with setTimeout() which will
         // prevent javascript timeouts (I hope)
         sortTable.savePositions(tbody);