04e19b4c5a3d76b31a21f068fc8ba4d86744dc2a
chmalee
  Tue Jan 7 15:16:07 2025 -0800
Fix row ordering when adding a new row

diff --git src/hg/js/hgMyData.js src/hg/js/hgMyData.js
index 73f3248..e4b9315 100644
--- src/hg/js/hgMyData.js
+++ src/hg/js/hgMyData.js
@@ -388,31 +388,31 @@
     }
 
 
     // hash of file paths to their objects, starts as userFiles
     let filesHash = {};
     function addNewUploadedFileToTable(req) {
         // req is an object with properties of an uploaded file, make a new row
         // for it in the filesTable
         if (!(req.fullPath in filesHash)) {
             if ($.fn.dataTable.isDataTable("#filesTable")) {
                 let table = $("#filesTable").DataTable();
                 let rowObj = table.row.add(req);
                 rowVis[req.fullPath] = true;
                 table.search.fixed("defaultView", function(searchStr, data, rowIx) {
                     return rowVis[data.fileName] || rowVis[data.fullPath];
-                }).order([{name: "fileName", dir: 'desc'}]).draw(false);
+                }).draw();
                 indentActionButton(rowObj);
                 let newRow = rowObj.node();
                 $(newRow).css('color','red').animate({color: 'black'}, 1500);
             } else {
                 showExistingFiles([req]);
             }
             filesHash[req.fullPath] = req;
         }
     }
 
     function doRowSelect(ev, table, indexes) {
         let row = table.row(indexes);
         let rowTr = row.node();
         let rowCheckbox = rowTr.childNodes[0].firstChild;
         if (rowTr.classList.contains("parentRow")) {
@@ -449,31 +449,30 @@
             }
             parentVis = rowVis[parentName] || rowVis[parentData.fullPath];
             rowVis[data.fullPath] = parentVis;
         }
 
         table.rows().every(function(rowIdx, tableLoop, rowLoop) {
             let data = this.data();
             rowHeirarchy(data);
         });
     }
 
     function indentActionButton(rowObj) {
         let data = rowObj.data();
         let numIndents = data.parentDir !== "" ? data.fullPath.split('/').length - 1: 0;
         rowObj.node().childNodes[1].style.textIndent = (numIndents * 10) + "px";
-        //table.row(rowIdx).node().childNodes[1].style.textIndent = (numIndents * 10) + "px";
     }
 
     let tableInitOptions = {
         select: {
             items: 'row',
             style: 'multi', // default to a single click is all that's needed
         },
         pageLength: 25,
         scrollY: 600,
         scrollCollapse: true, // when less than scrollY height is needed, make the table shorter
         layout: {
             topStart: {
                 buttons: [
                     {
                         text: 'Upload',
@@ -529,63 +528,64 @@
                 targets: 9,
                 visible: false,
                 searchable: false,
                 orderable: true,
             }
         ],
         columns: [
             {data: "", },
             {data: "", },
             {data: "fileName", title: "File name"},
             {data: "fileSize", title: "File size"},
             {data: "fileType", title: "File type"},
             {data: "genome", title: "Genome"},
             {data: "parentDir", title: "Hubs"},
             {data: "lastModified", title: "File Last Modified"},
-            {data: "uploadTime", title: "Upload Time"},
-            {data: "fullPath", title: "fullPath"},
+            {data: "uploadTime", title: "Upload Time", name: "uploadTime"},
+            {data: "fullPath", title: "fullPath", name: "fullPath"},
         ],
-        order: [{name: "fullPath"},{name: "uploadTime"}],
+        order: [{name: "fullPath", dir: "asc"},{name: "uploadTime", dir: "asc"}],
         drawCallback: function(settings) {
             console.log("table draw");
             if (isLoggedIn) {
                 settings.api.buttons(0).enable();
             }
         },
         rowCallback: function(row, data, displayNum, displayIndex, dataIndex) {
             // a row can represent one of three things:
             // a 'folder', with no parents, but with children
             // a folder with parents and children (can only come from hubtools
             // a 'file' with no children, but with parentDir
             // we assign the appropriate classes which are used later to
             // collapse/expand and select rows for viewing or deletion
             if (!data.parentDir) {
                 row.className = "topLevelRow";
             } else {
                 row.className = "childRow";
             }
             if (data.fileType === "dir") {
                 row.className += " parentRow";
             }
         },
         initComplete: function(settings, json) {
             console.log("data loaded, hiding directories");
             let table = new $.fn.dataTable.Api(settings);
             makeFileHeirarchy(table);
             table.rows().every(function(rowIdx, rowLoop, tableLoop) {
                 indentActionButton(this);
             });
+            table.order.fixed({pre: [{name: "fullPath", dir: "asc"}, {name: "uploadTime", dir: "asc"}]});
             // only show the top level and one layer of children by default
             table.search.fixed("defaultView", function(searchStr, data, rowIx) {
                 return rowVis[data.fileName] || rowVis[data.fullPath];
             }).draw();
         }
     };
 
     function showExistingFiles(d) {
         // Make the DataTable for each file
         // make buttons have the same style as other buttons
         $.fn.dataTable.Buttons.defaults.dom.button.className = 'button';
         tableInitOptions.data = d;
         if (isLoggedIn) {
             tableInitOptions.language = {emptyTable: "Uploaded files will appear here. Click \"Upload\" to get started"};
         } else {