tabulator-tables 5.1.4 → 5.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bower.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tabulator",
3
3
  "main": "dist/js/tabulator.js",
4
- "version": "5.1.4",
4
+ "version": "5.1.7",
5
5
  "description": "Interactive table generation JavaScript library",
6
6
  "keywords": [
7
7
  "table",
@@ -1,4 +1,4 @@
1
- /* Tabulator v5.1.4 (c) Oliver Folkerd 2022 */
1
+ /* Tabulator v5.1.7 (c) Oliver Folkerd 2022 */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -2542,9 +2542,11 @@
2542
2542
  _this.vDomPadLeft = 0;
2543
2543
  _this.vDomPadRight = 0;
2544
2544
  _this.fitDataColAvg = 0;
2545
- _this.window = 200; //pixel margin to make column visible before it is shown on screen
2545
+ _this.windowBuffer = 200; //pixel margin to make column visible before it is shown on screen
2546
2546
 
2547
+ _this.visibleRows = null;
2547
2548
  _this.initialized = false;
2549
+ _this.isFitData = false;
2548
2550
  _this.columns = [];
2549
2551
  return _this;
2550
2552
  }
@@ -2553,6 +2555,8 @@
2553
2555
  key: "initialize",
2554
2556
  value: function initialize() {
2555
2557
  this.compatibilityCheck();
2558
+ this.layoutCheck();
2559
+ this.vertScrollListen();
2556
2560
  }
2557
2561
  }, {
2558
2562
  key: "compatibilityCheck",
@@ -2591,6 +2595,22 @@
2591
2595
 
2592
2596
 
2593
2597
  return ok;
2598
+ }
2599
+ }, {
2600
+ key: "layoutCheck",
2601
+ value: function layoutCheck() {
2602
+ this.isFitData = this.options("layout").startsWith('fitData');
2603
+ }
2604
+ }, {
2605
+ key: "vertScrollListen",
2606
+ value: function vertScrollListen() {
2607
+ this.subscribe("scroll-vertical", this.clearVisRowCache.bind(this));
2608
+ this.subscribe("data-refreshed", this.clearVisRowCache.bind(this));
2609
+ }
2610
+ }, {
2611
+ key: "clearVisRowCache",
2612
+ value: function clearVisRowCache() {
2613
+ this.visibleRows = null;
2594
2614
  } //////////////////////////////////////
2595
2615
  ///////// Public Functions ///////////
2596
2616
  //////////////////////////////////////
@@ -2605,9 +2625,24 @@
2605
2625
  value: function scrollColumns(left, dir) {
2606
2626
  if (this.scrollLeft != left) {
2607
2627
  this.scrollLeft = left;
2608
- this.scroll(left - (this.vDomScrollPosLeft + this.window));
2628
+ this.scroll(left - (this.vDomScrollPosLeft + this.windowBuffer));
2609
2629
  }
2610
2630
  }
2631
+ }, {
2632
+ key: "calcWindowBuffer",
2633
+ value: function calcWindowBuffer() {
2634
+ var buffer = this.elementVertical.clientWidth;
2635
+ this.table.columnManager.columnsByIndex.forEach(function (column) {
2636
+ if (column.visible) {
2637
+ var width = column.getWidth();
2638
+
2639
+ if (width > buffer) {
2640
+ buffer = width;
2641
+ }
2642
+ }
2643
+ });
2644
+ this.windowBuffer = buffer * 2;
2645
+ }
2611
2646
  }, {
2612
2647
  key: "rerenderColumns",
2613
2648
  value: function rerenderColumns(update, blockRedraw) {
@@ -2617,17 +2652,18 @@
2617
2652
  cols: this.columns,
2618
2653
  leftCol: this.leftCol,
2619
2654
  rightCol: this.rightCol
2620
- };
2655
+ },
2656
+ colPos = 0;
2621
2657
 
2622
2658
  if (update && !this.initialized) {
2623
2659
  return;
2624
2660
  }
2625
2661
 
2626
2662
  this.clear();
2663
+ this.calcWindowBuffer();
2627
2664
  this.scrollLeft = this.elementVertical.scrollLeft;
2628
- this.vDomScrollPosLeft = this.scrollLeft - this.window;
2629
- this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.window;
2630
- var colPos = 0;
2665
+ this.vDomScrollPosLeft = this.scrollLeft - this.windowBuffer;
2666
+ this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.windowBuffer;
2631
2667
  this.table.columnManager.columnsByIndex.forEach(function (column) {
2632
2668
  var config = {};
2633
2669
 
@@ -2637,7 +2673,7 @@
2637
2673
  config.rightPos = colPos + width;
2638
2674
  config.width = width;
2639
2675
 
2640
- if (_this2.options("layout") === "fitData") {
2676
+ if (_this2.isFitData) {
2641
2677
  config.fitDataCheck = column.modules.vdomHoz ? column.modules.vdomHoz.fitDataCheck : true;
2642
2678
  }
2643
2679
 
@@ -2728,7 +2764,7 @@
2728
2764
  row,
2729
2765
  rowEl;
2730
2766
 
2731
- if (this.options("layout") === "fitData") {
2767
+ if (this.isFitData) {
2732
2768
  this.table.columnManager.columnsByIndex.forEach(function (column) {
2733
2769
  if (!column.definition.width && column.visible) {
2734
2770
  change = true;
@@ -2737,7 +2773,7 @@
2737
2773
 
2738
2774
  if (change) {
2739
2775
  if (change && this.table.rowManager.getDisplayRows().length) {
2740
- this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.window;
2776
+ this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.windowBuffer;
2741
2777
  var row = this.chain("rows-sample", [1], [], function () {
2742
2778
  return _this3.table.rowManager.getDisplayRows();
2743
2779
  })[0];
@@ -2751,19 +2787,15 @@
2751
2787
  var cell = row.cells[colEnd];
2752
2788
  rowEl.appendChild(cell.getElement());
2753
2789
  cell.column.reinitializeWidth();
2754
- collsWidth += cell.column.getWidth();
2755
-
2756
- if (collsWidth > this.vDomScrollPosRight) {
2757
- break;
2758
- }
2790
+ collsWidth += cell.column.getWidth(); // if(collsWidth > this.vDomScrollPosRight){
2791
+ // break;
2792
+ // }
2759
2793
  }
2760
2794
 
2761
- rowEl.parentNode.removeChild(rowEl);
2762
- this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
2763
-
2764
- for (colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++) {
2765
- this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
2766
- }
2795
+ rowEl.parentNode.removeChild(rowEl); // this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
2796
+ // for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
2797
+ // this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
2798
+ // }
2767
2799
 
2768
2800
  this.rerenderColumns(false, true);
2769
2801
  }
@@ -2799,18 +2831,27 @@
2799
2831
  value: function reinitializeRows() {
2800
2832
  var _this5 = this;
2801
2833
 
2802
- var rows = this.table.rowManager.getVisibleRows();
2834
+ var rows = this.getVisibleRows();
2803
2835
  rows.forEach(function (row) {
2804
2836
  _this5.reinitializeRow(row, true);
2805
2837
  });
2806
2838
  }
2839
+ }, {
2840
+ key: "getVisibleRows",
2841
+ value: function getVisibleRows() {
2842
+ if (!this.visibleRows) {
2843
+ this.visibleRows = this.table.rowManager.getVisibleRows();
2844
+ }
2845
+
2846
+ return this.visibleRows;
2847
+ }
2807
2848
  }, {
2808
2849
  key: "scroll",
2809
2850
  value: function scroll(diff) {
2810
2851
  this.vDomScrollPosLeft += diff;
2811
2852
  this.vDomScrollPosRight += diff;
2812
2853
 
2813
- if (diff > this.elementVertical.clientWidth * .8) {
2854
+ if (Math.abs(diff) > this.windowBuffer / 2) {
2814
2855
  this.rerenderColumns();
2815
2856
  } else {
2816
2857
  if (diff > 0) {
@@ -2836,117 +2877,197 @@
2836
2877
  }, {
2837
2878
  key: "addColRight",
2838
2879
  value: function addColRight() {
2839
- var column = this.columns[this.rightCol + 1],
2840
- rows;
2880
+ var _this6 = this;
2841
2881
 
2842
- if (column && column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight) {
2843
- rows = this.table.rowManager.getVisibleRows();
2844
- rows.forEach(function (row) {
2845
- if (row.type !== "group") {
2846
- var cell = row.getCell(column);
2847
- row.getElement().appendChild(cell.getElement());
2848
- cell.cellRendered();
2849
- }
2850
- });
2851
- this.fitDataColActualWidthCheck(column);
2852
- this.rightCol++; // Don't move this below the >= check below
2882
+ var changes = false;
2883
+
2884
+ var _loop = function _loop() {
2885
+ var column = _this6.columns[_this6.rightCol + 1];
2886
+
2887
+ if (column) {
2888
+ if (column.modules.vdomHoz.leftPos <= _this6.vDomScrollPosRight) {
2889
+ changes = true;
2890
+
2891
+ _this6.getVisibleRows().forEach(function (row) {
2892
+ if (row.type !== "group") {
2893
+ var cell = row.getCell(column);
2894
+ row.getElement().appendChild(cell.getElement());
2895
+ cell.cellRendered();
2896
+ }
2897
+ });
2853
2898
 
2854
- if (this.rightCol >= this.columns.length - 1) {
2855
- this.vDomPadRight = 0;
2899
+ _this6.fitDataColActualWidthCheck(column);
2900
+
2901
+ _this6.rightCol++; // Don't move this below the >= check below
2902
+
2903
+ if (_this6.rightCol >= _this6.columns.length - 1) {
2904
+ _this6.vDomPadRight = 0;
2905
+ } else {
2906
+ _this6.vDomPadRight -= column.getWidth();
2907
+ }
2908
+ } else {
2909
+ return "break";
2910
+ }
2856
2911
  } else {
2857
- this.vDomPadRight -= column.getWidth();
2912
+ return "break";
2858
2913
  }
2914
+ };
2859
2915
 
2916
+ while (true) {
2917
+ var _ret = _loop();
2918
+
2919
+ if (_ret === "break") break;
2920
+ }
2921
+
2922
+ if (changes) {
2860
2923
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
2861
- this.addColRight();
2862
2924
  }
2863
2925
  }
2864
2926
  }, {
2865
2927
  key: "addColLeft",
2866
2928
  value: function addColLeft() {
2867
- var column = this.columns[this.leftCol - 1],
2868
- rows;
2929
+ var _this7 = this;
2869
2930
 
2870
- if (column && column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft) {
2871
- var rows = this.table.rowManager.getVisibleRows();
2872
- rows.forEach(function (row) {
2873
- if (row.type !== "group") {
2874
- var cell = row.getCell(column);
2875
- row.getElement().prepend(cell.getElement());
2876
- cell.cellRendered();
2877
- }
2878
- });
2879
- this.fitDataColActualWidthCheck(column);
2880
- this.leftCol--; // don't move this below the <= check below
2931
+ var changes = false;
2932
+
2933
+ var _loop2 = function _loop2() {
2934
+ var column = _this7.columns[_this7.leftCol - 1];
2935
+
2936
+ if (column) {
2937
+ if (column.modules.vdomHoz.rightPos >= _this7.vDomScrollPosLeft) {
2938
+ changes = true;
2939
+
2940
+ _this7.getVisibleRows().forEach(function (row) {
2941
+ if (row.type !== "group") {
2942
+ var cell = row.getCell(column);
2943
+ row.getElement().prepend(cell.getElement());
2944
+ cell.cellRendered();
2945
+ }
2946
+ });
2881
2947
 
2882
- if (this.leftCol <= 0) {
2883
- // replicating logic in addColRight
2884
- this.vDomPadLeft = 0;
2948
+ _this7.leftCol--; // don't move this below the <= check below
2949
+
2950
+ if (_this7.leftCol <= 0) {
2951
+ // replicating logic in addColRight
2952
+ _this7.vDomPadLeft = 0;
2953
+ } else {
2954
+ _this7.vDomPadLeft -= column.getWidth();
2955
+ }
2956
+
2957
+ var diff = _this7.fitDataColActualWidthCheck(column);
2958
+
2959
+ if (diff) {
2960
+ _this7.scrollLeft = _this7.elementVertical.scrollLeft = _this7.elementVertical.scrollLeft + diff;
2961
+ _this7.vDomPadRight -= diff;
2962
+ }
2963
+ } else {
2964
+ return "break";
2965
+ }
2885
2966
  } else {
2886
- this.vDomPadLeft -= column.getWidth();
2967
+ return "break";
2887
2968
  }
2969
+ };
2970
+
2971
+ while (true) {
2972
+ var _ret2 = _loop2();
2888
2973
 
2974
+ if (_ret2 === "break") break;
2975
+ }
2976
+
2977
+ if (changes) {
2889
2978
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
2890
- this.addColLeft();
2891
2979
  }
2892
2980
  }
2893
2981
  }, {
2894
2982
  key: "removeColRight",
2895
- value: function removeColRight(column) {
2896
- var column = this.columns[this.rightCol],
2897
- rows;
2983
+ value: function removeColRight() {
2984
+ var _this8 = this;
2898
2985
 
2899
- if (column && column.modules.vdomHoz.leftPos > this.vDomScrollPosRight) {
2900
- rows = this.table.rowManager.getVisibleRows();
2901
- column.modules.vdomHoz.visible = false;
2902
- rows.forEach(function (row) {
2903
- if (row.type !== "group") {
2904
- var cell = row.getCell(column);
2986
+ var changes = false;
2905
2987
 
2906
- try {
2907
- row.getElement().removeChild(cell.getElement());
2908
- } catch (ex) {
2909
- console.warn("Could not removeColRight", ex.message);
2910
- }
2988
+ var _loop3 = function _loop3() {
2989
+ var column = _this8.columns[_this8.rightCol];
2990
+
2991
+ if (column) {
2992
+ if (column.modules.vdomHoz.leftPos > _this8.vDomScrollPosRight) {
2993
+ changes = true;
2994
+
2995
+ _this8.getVisibleRows().forEach(function (row) {
2996
+ if (row.type !== "group") {
2997
+ var cell = row.getCell(column);
2998
+
2999
+ try {
3000
+ row.getElement().removeChild(cell.getElement());
3001
+ } catch (ex) {
3002
+ console.warn("Could not removeColRight", ex.message);
3003
+ }
3004
+ }
3005
+ });
3006
+
3007
+ _this8.vDomPadRight += column.getWidth();
3008
+ _this8.rightCol--;
3009
+ } else {
3010
+ return "break";
2911
3011
  }
2912
- });
2913
- this.vDomPadRight += column.getWidth();
3012
+ } else {
3013
+ return "break";
3014
+ }
3015
+ };
3016
+
3017
+ while (true) {
3018
+ var _ret3 = _loop3();
3019
+
3020
+ if (_ret3 === "break") break;
3021
+ }
3022
+
3023
+ if (changes) {
2914
3024
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
2915
- this.rightCol--;
2916
- this.removeColRight();
2917
3025
  }
2918
3026
  }
2919
3027
  }, {
2920
3028
  key: "removeColLeft",
2921
3029
  value: function removeColLeft() {
2922
- var column = this.columns[this.leftCol],
2923
- rows;
3030
+ var _this9 = this;
2924
3031
 
2925
- if (column && column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft) {
2926
- rows = this.table.rowManager.getVisibleRows();
2927
- rows.forEach(function (row) {
2928
- var cell, el;
3032
+ var changes = false;
2929
3033
 
2930
- if (row.type !== "group") {
2931
- cell = row.getCell(column);
3034
+ var _loop4 = function _loop4() {
3035
+ var column = _this9.columns[_this9.leftCol];
2932
3036
 
2933
- if (cell) {
2934
- el = cell.getElement();
3037
+ if (column) {
3038
+ if (column.modules.vdomHoz.rightPos < _this9.vDomScrollPosLeft) {
3039
+ changes = true;
3040
+
3041
+ _this9.getVisibleRows().forEach(function (row) {
3042
+ if (row.type !== "group") {
3043
+ var cell = row.getCell(column);
2935
3044
 
2936
- if (el.parentNode) {
2937
3045
  try {
2938
- row.getElement().removeChild(el);
3046
+ row.getElement().removeChild(cell.getElement());
2939
3047
  } catch (ex) {
2940
3048
  console.warn("Could not removeColLeft", ex.message);
2941
3049
  }
2942
3050
  }
2943
- }
3051
+ });
3052
+
3053
+ _this9.vDomPadLeft += column.getWidth();
3054
+ _this9.leftCol++;
3055
+ } else {
3056
+ return "break";
2944
3057
  }
2945
- });
2946
- this.vDomPadLeft += column.getWidth();
3058
+ } else {
3059
+ return "break";
3060
+ }
3061
+ };
3062
+
3063
+ while (true) {
3064
+ var _ret4 = _loop4();
3065
+
3066
+ if (_ret4 === "break") break;
3067
+ }
3068
+
3069
+ if (changes) {
2947
3070
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
2948
- this.leftCol++;
2949
- this.removeColLeft();
2950
3071
  }
2951
3072
  }
2952
3073
  }, {
@@ -2962,11 +3083,13 @@
2962
3083
  if (widthDiff) {
2963
3084
  column.modules.vdomHoz.rightPos += widthDiff;
2964
3085
  column.modules.vdomHoz.width = newWidth;
2965
- this.colPositionAdjust(this.rightCol + 2, this.columns.length, widthDiff);
3086
+ this.colPositionAdjust(this.columns.indexOf(column) + 1, this.columns.length, widthDiff);
2966
3087
  }
2967
3088
 
2968
3089
  column.modules.vdomHoz.fitDataCheck = false;
2969
3090
  }
3091
+
3092
+ return widthDiff;
2970
3093
  }
2971
3094
  }, {
2972
3095
  key: "initializeRow",
@@ -20061,13 +20184,11 @@
20061
20184
  } //move menu to start on bottom edge if it is too close to the edge of the screen
20062
20185
 
20063
20186
 
20064
- if (y + element.offsetHeight >= this.menuContainer.offsetHeight) {
20065
- element.style.top = "";
20066
-
20187
+ if (y + element.offsetHeight > this.menuContainer.offsetHeight) {
20067
20188
  if (parentEl) {
20068
- element.style.bottom = this.menuContainer.offsetHeight - parentOffset.top - parentEl.offsetHeight - 1 + "px";
20189
+ element.style.top = parseInt(element.style.top) - element.offsetHeight + parentEl.offsetHeight + 1 + "px";
20069
20190
  } else {
20070
- element.style.bottom = this.menuContainer.offsetHeight - y + "px";
20191
+ element.style.top = parseInt(element.style.top) - element.offsetHeight + "px";
20071
20192
  }
20072
20193
  }
20073
20194
  }
@@ -21913,17 +22034,17 @@
21913
22034
  }
21914
22035
  }, {
21915
22036
  key: "_setPageCounter",
21916
- value: function _setPageCounter(totalRows) {
21917
- var content, currentRow;
22037
+ value: function _setPageCounter(totalRows, size, currentRow) {
22038
+ var content;
21918
22039
 
21919
22040
  if (this.pageCounter) {
21920
- currentRow = (this.page - 1) * this.size + 1;
21921
-
21922
22041
  if (this.mode === "remote") {
22042
+ size = this.size;
22043
+ currentRow = (this.page - 1) * this.size + 1;
21923
22044
  totalRows = this.remoteRowCountEstimate;
21924
22045
  }
21925
22046
 
21926
- content = this.pageCounter.call(this, this.size, currentRow, this.page, totalRows, this.max);
22047
+ content = this.pageCounter.call(this, size, currentRow, this.page, totalRows, this.max);
21927
22048
 
21928
22049
  switch (_typeof(content)) {
21929
22050
  case "object":
@@ -22071,7 +22192,14 @@
22071
22192
  }, {
22072
22193
  key: "getRows",
22073
22194
  value: function getRows(data) {
22074
- var output, start, end;
22195
+ var actualRowPageSize = 0,
22196
+ output,
22197
+ start,
22198
+ end,
22199
+ actualStartRow;
22200
+ var actualRows = data.filter(function (row) {
22201
+ return row.type === "row";
22202
+ });
22075
22203
 
22076
22204
  if (this.mode == "local") {
22077
22205
  output = [];
@@ -22088,18 +22216,28 @@
22088
22216
  this._setPageButtons();
22089
22217
 
22090
22218
  for (var i = start; i < end; i++) {
22091
- if (data[i]) {
22092
- output.push(data[i]);
22219
+ var row = data[i];
22220
+
22221
+ if (row) {
22222
+ output.push(row);
22223
+
22224
+ if (row.type === "row") {
22225
+ if (!actualStartRow) {
22226
+ actualStartRow = row;
22227
+ }
22228
+
22229
+ actualRowPageSize++;
22230
+ }
22093
22231
  }
22094
22232
  }
22095
22233
 
22096
- this._setPageCounter(data.length);
22234
+ this._setPageCounter(actualRows.length, actualRowPageSize, actualStartRow ? actualRows.indexOf(actualStartRow) + 1 : 0);
22097
22235
 
22098
22236
  return output;
22099
22237
  } else {
22100
22238
  this._setPageButtons();
22101
22239
 
22102
- this._setPageCounter(data.length);
22240
+ this._setPageCounter(actualRows.length);
22103
22241
 
22104
22242
  return data.slice(0);
22105
22243
  }