فهرست منبع

HUE-3960 [editor] Fixed locked rows with new HueDatatable

Enrico Berti 9 سال پیش
والد
کامیت
39f203c

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/hue.utils.js

@@ -328,7 +328,7 @@ var hueDebugTimer = (function () {
       var mark = (new Date()).getTime();
       times.push(mark);
       if (withConsole){
-        console.log(label ? label : times.length, mark - times[times.length - 2]);
+        console.log(label ? label : times.length, mark - times[times.length - 2], mark - initialTime);
       }
       return mark - times[times.length - 2];
     },

+ 18 - 9
desktop/core/src/desktop/static/desktop/js/jquery.huedatatable.js

@@ -48,9 +48,13 @@
         var aoColumns = self.$table.data('aoColumns');
         var appendable = $t.children('tbody').length > 0 ? $t.children('tbody') : $t;
 
-        var invisibleOffset = 1;
+        var maxDOMCells = 20000;
         var scrollable = $t.parents($t.data('oInit')['scrollable']);
-        var visibleRows = Math.ceil((scrollable.height() - Math.max($t.offset().top, 0)) / rowHeight) + invisibleOffset;
+        var visibleRows = Math.ceil((scrollable.height() - Math.max($t.offset().top, 0)) / rowHeight);
+
+        var invisibleOffset = Math.ceil(Math.min(Math.max(0, (visibleRows * (maxDOMCells / (aoColumns.length * visibleRows))) - visibleRows), 100 - visibleRows));
+
+        visibleRows += invisibleOffset;
 
         var startRow = $t.offset().top - 73 < 0 ? Math.max(Math.floor(Math.abs($t.offset().top - 73) / rowHeight) - invisibleOffset, 0) : 0;
         var endRow = startRow + visibleRows;
@@ -68,11 +72,13 @@
           }
         }
 
-        $t.find('.ht-visible-row').empty();
+        if ($t.data('fnDraws') == 0){
+          $t.find('.ht-visible-row').empty();
 
-        for (var i=0; i<visibleRows; i++) {
-          if ($t.find('.ht-visible-row-' + i).length === 0) {
-            $t.find('.ht-north-spacer').after('<tr class="ht-visible-row ht-visible-row-' + i + '"></tr>');
+          for (var i=visibleRows - 1; i >= 0; i--) {
+            if ($t.find('.ht-visible-row-' + i).length === 0) {
+              $t.find('.ht-north-spacer').after('<tr class="ht-visible-row ht-visible-row-' + i + '"></tr>');
+            }
           }
         }
 
@@ -97,10 +103,9 @@
         }
 
         if ($t.data('oInit')['fnDrawCallback']) {
-          window.setTimeout(function(){
-            $t.data('oInit')['fnDrawCallback']();
-          }, 0);
+          $t.data('oInit')['fnDrawCallback']();
         }
+        $t.data('fnDraws', $t.data('fnDraws') + 1);
         self.isDrawing = false;
       }
     };
@@ -144,6 +149,9 @@
         $t.children('tr').remove();
       }
       $t.data('data', []);
+      $t.data('aoRows', []);
+      $t.data('aoColumns', []);
+      $t.data('fnDraws', 0);
     };
 
     self.fnDestroy = function () {
@@ -161,6 +169,7 @@
       self.$table.data('data', []);
       self.$table.data('aoRows', []);
       self.$table.data('aoColumns', []);
+      self.$table.data('fnDraws', 0);
       self.$table.wrap('<div class="dataTables_wrapper"></div>');
 
       if (typeof oInit !== 'undefined') {

+ 38 - 22
desktop/core/src/desktop/static/desktop/js/jquery.tableextender.js

@@ -187,29 +187,46 @@
 
   function drawLockedRow(plugin, rowNo) {
     var $pluginElement = $(plugin.element);
-    var lockedRows = $pluginElement.data('lockedRows') || [];
-    if (lockedRows.indexOf(rowNo) === -1) {
-      lockedRows.push(rowNo);
-      $pluginElement.data('lockedRows', lockedRows);
-      var $header = $("#" + $pluginElement.attr("id") + "jHueTableExtenderClonedContainer");
-      var $headerCounter = $("#" + $pluginElement.attr("id") + "jHueTableExtenderClonedContainerCell");
-      var $clone = $pluginElement.find('tbody tr:eq('+ rowNo +')').clone();
+    var lockedRows = $pluginElement.data('lockedRows') || {};
+    var $header = $("#" + $pluginElement.attr("id") + "jHueTableExtenderClonedContainer");
+    var $headerCounter = $("#" + $pluginElement.attr("id") + "jHueTableExtenderClonedContainerCell");
+    $header.addClass('locked');
+    $headerCounter.addClass('locked');
+
+    function unlock($el) {
+      var idx = $el.parent().index();
+      $header.find('tbody tr:eq('+ idx +')').remove();
+      delete lockedRows[$el.text()]
+      $el.parent().remove();
+      if ($header.find('tbody tr').length == 0){
+        $header.removeClass('locked');
+        $headerCounter.removeClass('locked');
+        $pluginElement.data('lockedRows', {});
+      }
+    }
+
+    if (Object.keys(lockedRows).indexOf(rowNo) === -1) {
+      var $clone = $pluginElement.find('tr td:first-child').filter(function() {
+        return $(this).text() === rowNo+'';
+      }).closest('tr').clone();
       $clone.addClass('locked');
-      $header.addClass('locked');
-      $headerCounter.addClass('locked');
       $clone.appendTo($header.find('tbody'));
+      $pluginElement.data('lockedRows', lockedRows);
       var $newTr = $('<tr>');
-      $newTr.addClass('locked').html('<td class="pointer unlockable" title="' + plugin.options.labels.UNLOCK + '"><i class="fa fa-unlock muted"></i>' + (rowNo+1) + '</td>').appendTo($headerCounter.find('tbody'));
+      $newTr.addClass('locked').html('<td class="pointer unlockable" title="' + plugin.options.labels.UNLOCK + '"><i class="fa fa-unlock muted"></i>' + rowNo + '</td>').appendTo($headerCounter.find('tbody'));
       $newTr.find('td').on('click', function(){
-        var idx = $(this).parent().index();
-        $header.find('tbody tr:eq('+ idx +')').remove();
-        $pluginElement.data('lockedRows').splice(idx, 1);
-        $(this).parent().remove();
-        if ($header.find('tbody tr').length == 0){
-          $header.removeClass('locked');
-          $headerCounter.removeClass('locked');
-          $pluginElement.data('lockedRows', []);
-        }
+        unlock($(this));
+      });
+      lockedRows[rowNo] = {
+        row: $clone,
+        cell: $newTr
+      };
+    }
+    else {
+      lockedRows[rowNo].row.appendTo($header.find('tbody'));
+      lockedRows[rowNo].cell.appendTo($headerCounter.find('tbody'));
+      lockedRows[rowNo].cell.find('td').on('click', function(){
+        unlock($(this));
       });
     }
   }
@@ -259,7 +276,7 @@
       if (plugin.options.lockSelectedRow) {
         var cell = $(this).find('td:eq(0)');
         cell.attr('title', plugin.options.labels.LOCK).addClass('lockable pointer').on('click', function(){
-          drawLockedRow(plugin, $(this).parent().index());
+          drawLockedRow(plugin, $(this).text()*1);
         });
         $('<i>').addClass('fa fa-lock muted').prependTo(cell);
       }
@@ -327,8 +344,7 @@
 
     if ($pluginElement.data('lockedRows')) {
       var locks = $pluginElement.data('lockedRows');
-      $pluginElement.data('lockedRows', []);
-      locks.forEach(function (idx) {
+      Object.keys(locks).forEach(function (idx) {
         drawLockedRow(plugin, idx);
       });
     }

+ 1 - 0
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -3192,6 +3192,7 @@ ${ hueIcons.symbols() }
             _el.hueDataTable().fnDestroy();
           }
           _el.find("thead tr").empty();
+          _el.data('lockedRows', {});
         }
       });