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.
@@ -1,4 +1,4 @@
1
- /* Tabulator v5.1.4 (c) Oliver Folkerd 2022 */
1
+ /* Tabulator v5.1.7 (c) Oliver Folkerd 2022 */
2
2
  class CoreFeature{
3
3
 
4
4
  constructor(table){
@@ -13147,13 +13147,11 @@ class Menu extends Module{
13147
13147
  }
13148
13148
 
13149
13149
  //move menu to start on bottom edge if it is too close to the edge of the screen
13150
- if((y + element.offsetHeight) >= this.menuContainer.offsetHeight){
13151
- element.style.top = "";
13152
-
13150
+ if((y + element.offsetHeight) > this.menuContainer.offsetHeight) {
13153
13151
  if(parentEl){
13154
- element.style.bottom = (this.menuContainer.offsetHeight - parentOffset.top - parentEl.offsetHeight - 1) + "px";
13152
+ element.style.top = (parseInt(element.style.top) - element.offsetHeight + parentEl.offsetHeight + 1) + "px";
13155
13153
  }else {
13156
- element.style.bottom = (this.menuContainer.offsetHeight - y) + "px";
13154
+ element.style.top = (parseInt(element.style.top) - element.offsetHeight) + "px";
13157
13155
  }
13158
13156
  }
13159
13157
  }
@@ -14901,17 +14899,18 @@ class Page extends Module{
14901
14899
  this.trackChanges();
14902
14900
  }
14903
14901
 
14904
- _setPageCounter(totalRows){
14905
- var content, currentRow;
14902
+ _setPageCounter(totalRows, size, currentRow){
14903
+ var content;
14906
14904
 
14907
14905
  if(this.pageCounter){
14908
- currentRow = ((this.page - 1) * this.size) + 1;
14909
14906
 
14910
14907
  if(this.mode === "remote"){
14908
+ size = this.size;
14909
+ currentRow = ((this.page - 1) * this.size) + 1;
14911
14910
  totalRows = this.remoteRowCountEstimate;
14912
14911
  }
14913
14912
 
14914
- content = this.pageCounter.call(this, this.size, currentRow, this.page, totalRows, this.max);
14913
+ content = this.pageCounter.call(this, size, currentRow, this.page, totalRows, this.max);
14915
14914
 
14916
14915
  switch(typeof content){
14917
14916
  case "object":
@@ -15051,7 +15050,12 @@ class Page extends Module{
15051
15050
 
15052
15051
  //return appropriate rows for current page
15053
15052
  getRows(data){
15054
- var output, start, end;
15053
+ var actualRowPageSize = 0,
15054
+ output, start, end, actualStartRow;
15055
+
15056
+ var actualRows = data.filter((row) => {
15057
+ return row.type === "row";
15058
+ });
15055
15059
 
15056
15060
  if(this.mode == "local"){
15057
15061
  output = [];
@@ -15066,21 +15070,30 @@ class Page extends Module{
15066
15070
  end = start + parseInt(this.size);
15067
15071
  }
15068
15072
 
15069
-
15070
15073
  this._setPageButtons();
15071
15074
 
15072
15075
  for(let i = start; i < end; i++){
15073
- if(data[i]){
15074
- output.push(data[i]);
15076
+ let row = data[i];
15077
+
15078
+ if(row){
15079
+ output.push(row);
15080
+
15081
+ if(row.type === "row"){
15082
+ if(!actualStartRow){
15083
+ actualStartRow = row;
15084
+ }
15085
+
15086
+ actualRowPageSize++;
15087
+ }
15075
15088
  }
15076
15089
  }
15077
-
15078
- this._setPageCounter(data.length);
15090
+
15091
+ this._setPageCounter(actualRows.length, actualRowPageSize, actualStartRow ? (actualRows.indexOf(actualStartRow) + 1) : 0);
15079
15092
 
15080
15093
  return output;
15081
15094
  }else {
15082
15095
  this._setPageButtons();
15083
- this._setPageCounter(data.length);
15096
+ this._setPageCounter(actualRows.length);
15084
15097
 
15085
15098
  return data.slice(0);
15086
15099
  }
@@ -18814,15 +18827,20 @@ class VirtualDomHorizontal extends Renderer{
18814
18827
 
18815
18828
  this.fitDataColAvg = 0;
18816
18829
 
18817
- this.window = 200; //pixel margin to make column visible before it is shown on screen
18830
+ this.windowBuffer = 200; //pixel margin to make column visible before it is shown on screen
18818
18831
 
18832
+ this.visibleRows = null;
18833
+
18819
18834
  this.initialized = false;
18835
+ this.isFitData = false;
18820
18836
 
18821
18837
  this.columns = [];
18822
18838
  }
18823
18839
 
18824
18840
  initialize(){
18825
18841
  this.compatibilityCheck();
18842
+ this.layoutCheck();
18843
+ this.vertScrollListen();
18826
18844
  }
18827
18845
 
18828
18846
  compatibilityCheck(){
@@ -18863,6 +18881,19 @@ class VirtualDomHorizontal extends Renderer{
18863
18881
  return ok;
18864
18882
  }
18865
18883
 
18884
+ layoutCheck(){
18885
+ this.isFitData = this.options("layout").startsWith('fitData');
18886
+ }
18887
+
18888
+ vertScrollListen(){
18889
+ this.subscribe("scroll-vertical", this.clearVisRowCache.bind(this));
18890
+ this.subscribe("data-refreshed", this.clearVisRowCache.bind(this));
18891
+ }
18892
+
18893
+ clearVisRowCache(){
18894
+ this.visibleRows = null;
18895
+ }
18896
+
18866
18897
  //////////////////////////////////////
18867
18898
  ///////// Public Functions ///////////
18868
18899
  //////////////////////////////////////
@@ -18870,21 +18901,40 @@ class VirtualDomHorizontal extends Renderer{
18870
18901
  renderColumns(row, force){
18871
18902
  this.dataChange();
18872
18903
  }
18904
+
18873
18905
 
18874
18906
  scrollColumns(left, dir){
18875
18907
  if(this.scrollLeft != left){
18876
18908
  this.scrollLeft = left;
18877
18909
 
18878
- this.scroll(left - (this.vDomScrollPosLeft + this.window));
18910
+ this.scroll(left - (this.vDomScrollPosLeft + this.windowBuffer));
18879
18911
  }
18880
18912
  }
18881
18913
 
18914
+ calcWindowBuffer(){
18915
+ var buffer = this.elementVertical.clientWidth;
18916
+
18917
+ this.table.columnManager.columnsByIndex.forEach((column) => {
18918
+ if(column.visible){
18919
+ var width = column.getWidth();
18920
+
18921
+ if(width > buffer){
18922
+ buffer = width;
18923
+ }
18924
+ }
18925
+ });
18926
+
18927
+ this.windowBuffer = buffer * 2;
18928
+ }
18929
+
18882
18930
  rerenderColumns(update, blockRedraw){
18883
18931
  var old = {
18884
18932
  cols:this.columns,
18885
18933
  leftCol:this.leftCol,
18886
18934
  rightCol:this.rightCol,
18887
- };
18935
+ },
18936
+ colPos = 0;
18937
+
18888
18938
 
18889
18939
  if(update && !this.initialized){
18890
18940
  return;
@@ -18892,12 +18942,12 @@ class VirtualDomHorizontal extends Renderer{
18892
18942
 
18893
18943
  this.clear();
18894
18944
 
18895
- this.scrollLeft = this.elementVertical.scrollLeft;
18945
+ this.calcWindowBuffer();
18896
18946
 
18897
- this.vDomScrollPosLeft = this.scrollLeft - this.window;
18898
- this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.window;
18947
+ this.scrollLeft = this.elementVertical.scrollLeft;
18899
18948
 
18900
- var colPos = 0;
18949
+ this.vDomScrollPosLeft = this.scrollLeft - this.windowBuffer;
18950
+ this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.windowBuffer;
18901
18951
 
18902
18952
  this.table.columnManager.columnsByIndex.forEach((column) => {
18903
18953
  var config = {};
@@ -18910,7 +18960,7 @@ class VirtualDomHorizontal extends Renderer{
18910
18960
 
18911
18961
  config.width = width;
18912
18962
 
18913
- if (this.options("layout") === "fitData") {
18963
+ if (this.isFitData) {
18914
18964
  config.fitDataCheck = column.modules.vdomHoz ? column.modules.vdomHoz.fitDataCheck : true;
18915
18965
  }
18916
18966
 
@@ -18999,7 +19049,7 @@ class VirtualDomHorizontal extends Renderer{
18999
19049
  colEnd = 0,
19000
19050
  row, rowEl;
19001
19051
 
19002
- if(this.options("layout") === "fitData"){
19052
+ if(this.isFitData){
19003
19053
  this.table.columnManager.columnsByIndex.forEach((column) => {
19004
19054
  if(!column.definition.width && column.visible){
19005
19055
  change = true;
@@ -19009,7 +19059,7 @@ class VirtualDomHorizontal extends Renderer{
19009
19059
  if(change){
19010
19060
  if(change && this.table.rowManager.getDisplayRows().length){
19011
19061
 
19012
- this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.window;
19062
+ this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.windowBuffer;
19013
19063
 
19014
19064
  var row = this.chain("rows-sample", [1], [], () => {
19015
19065
  return this.table.rowManager.getDisplayRows();
@@ -19031,18 +19081,18 @@ class VirtualDomHorizontal extends Renderer{
19031
19081
 
19032
19082
  collsWidth += cell.column.getWidth();
19033
19083
 
19034
- if(collsWidth > this.vDomScrollPosRight){
19035
- break;
19036
- }
19084
+ // if(collsWidth > this.vDomScrollPosRight){
19085
+ // break;
19086
+ // }
19037
19087
  }
19038
19088
 
19039
19089
  rowEl.parentNode.removeChild(rowEl);
19040
19090
 
19041
- this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
19091
+ // this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
19042
19092
 
19043
- for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
19044
- this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
19045
- }
19093
+ // for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
19094
+ // this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
19095
+ // }
19046
19096
 
19047
19097
  this.rerenderColumns(false, true);
19048
19098
  }
@@ -19073,17 +19123,25 @@ class VirtualDomHorizontal extends Renderer{
19073
19123
  }
19074
19124
 
19075
19125
  reinitializeRows(){
19076
- var rows = this.table.rowManager.getVisibleRows();
19126
+ var rows = this.getVisibleRows();
19077
19127
  rows.forEach((row) => {
19078
19128
  this.reinitializeRow(row, true);
19079
19129
  });
19080
19130
  }
19081
19131
 
19132
+ getVisibleRows(){
19133
+ if (!this.visibleRows){
19134
+ this.visibleRows = this.table.rowManager.getVisibleRows();
19135
+ }
19136
+
19137
+ return this.visibleRows;
19138
+ }
19139
+
19082
19140
  scroll(diff){
19083
19141
  this.vDomScrollPosLeft += diff;
19084
19142
  this.vDomScrollPosRight += diff;
19085
-
19086
- if(diff > (this.elementVertical.clientWidth * .8)){
19143
+
19144
+ if(Math.abs(diff) > (this.windowBuffer / 2)){
19087
19145
  this.rerenderColumns();
19088
19146
  }else {
19089
19147
  if(diff > 0){
@@ -19108,131 +19166,165 @@ class VirtualDomHorizontal extends Renderer{
19108
19166
  }
19109
19167
 
19110
19168
  addColRight(){
19111
- var column = this.columns[this.rightCol + 1],
19112
- rows;
19169
+ var changes = false;
19113
19170
 
19114
- if(column && column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight){
19115
- rows = this.table.rowManager.getVisibleRows();
19116
-
19117
- rows.forEach((row) => {
19118
- if(row.type !== "group"){
19119
- var cell = row.getCell(column);
19120
- row.getElement().appendChild(cell.getElement());
19121
- cell.cellRendered();
19122
- }
19123
- });
19124
-
19125
- this.fitDataColActualWidthCheck(column);
19171
+ while(true){
19126
19172
 
19127
- this.rightCol++; // Don't move this below the >= check below
19173
+ let column = this.columns[this.rightCol + 1];
19128
19174
 
19129
- if(this.rightCol >= (this.columns.length - 1)){
19130
- this.vDomPadRight = 0;
19175
+ if(column){
19176
+ if(column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight){
19177
+ changes = true;
19178
+
19179
+ this.getVisibleRows().forEach((row) => {
19180
+ if(row.type !== "group"){
19181
+ var cell = row.getCell(column);
19182
+ row.getElement().appendChild(cell.getElement());
19183
+ cell.cellRendered();
19184
+ }
19185
+ });
19186
+
19187
+ this.fitDataColActualWidthCheck(column);
19188
+
19189
+ this.rightCol++; // Don't move this below the >= check below
19190
+
19191
+ if(this.rightCol >= (this.columns.length - 1)){
19192
+ this.vDomPadRight = 0;
19193
+ }else {
19194
+ this.vDomPadRight -= column.getWidth();
19195
+ }
19196
+ }else {
19197
+ break;
19198
+ }
19131
19199
  }else {
19132
- this.vDomPadRight -= column.getWidth();
19200
+ break;
19133
19201
  }
19134
-
19202
+ }
19203
+
19204
+ if(changes){
19135
19205
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
19136
-
19137
- this.addColRight();
19138
19206
  }
19139
19207
  }
19140
19208
 
19141
19209
  addColLeft(){
19142
- var column = this.columns[this.leftCol - 1],
19143
- rows;
19210
+ var changes = false;
19144
19211
 
19145
- if(column && column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft){
19146
- var rows = this.table.rowManager.getVisibleRows();
19212
+ while(true){
19213
+ let column = this.columns[this.leftCol - 1];
19147
19214
 
19148
- rows.forEach((row) => {
19149
- if(row.type !== "group"){
19150
- var cell = row.getCell(column);
19151
- row.getElement().prepend(cell.getElement());
19152
- cell.cellRendered();
19215
+ if(column){
19216
+ if(column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft){
19217
+ changes = true;
19218
+
19219
+ this.getVisibleRows().forEach((row) => {
19220
+ if(row.type !== "group"){
19221
+ var cell = row.getCell(column);
19222
+ row.getElement().prepend(cell.getElement());
19223
+ cell.cellRendered();
19224
+ }
19225
+ });
19226
+
19227
+ this.leftCol--; // don't move this below the <= check below
19228
+
19229
+ if(this.leftCol <= 0){ // replicating logic in addColRight
19230
+ this.vDomPadLeft = 0;
19231
+ }else {
19232
+ this.vDomPadLeft -= column.getWidth();
19233
+ }
19234
+
19235
+ let diff = this.fitDataColActualWidthCheck(column);
19236
+
19237
+ if(diff){
19238
+ this.scrollLeft = this.elementVertical.scrollLeft = this.elementVertical.scrollLeft + diff;
19239
+ this.vDomPadRight -= diff;
19240
+ }
19241
+
19242
+ }else {
19243
+ break;
19153
19244
  }
19154
- });
19155
-
19156
- this.fitDataColActualWidthCheck(column);
19157
-
19158
- this.leftCol--; // don't move this below the <= check below
19159
-
19160
- if(this.leftCol <= 0){ // replicating logic in addColRight
19161
- this.vDomPadLeft = 0;
19162
19245
  }else {
19163
- this.vDomPadLeft -= column.getWidth();
19246
+ break;
19164
19247
  }
19165
-
19248
+ }
19249
+
19250
+ if(changes){
19166
19251
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
19167
-
19168
-
19169
- this.addColLeft();
19170
19252
  }
19171
19253
  }
19172
19254
 
19173
- removeColRight(column){
19174
- var column = this.columns[this.rightCol],
19175
- rows;
19255
+ removeColRight(){
19256
+ var changes = false;
19176
19257
 
19177
- if(column && column.modules.vdomHoz.leftPos > this.vDomScrollPosRight){
19178
- rows = this.table.rowManager.getVisibleRows();
19179
-
19180
- column.modules.vdomHoz.visible = false;
19258
+ while(true){
19259
+ let column = this.columns[this.rightCol];
19181
19260
 
19182
- rows.forEach((row) => {
19183
- if(row.type !== "group"){
19184
- var cell = row.getCell(column);
19185
- try {
19186
- row.getElement().removeChild(cell.getElement());
19187
- } catch (ex) {
19188
- console.warn("Could not removeColRight", ex.message);
19189
- }
19261
+ if(column){
19262
+ if(column.modules.vdomHoz.leftPos > this.vDomScrollPosRight){
19263
+ changes = true;
19264
+
19265
+ this.getVisibleRows().forEach((row) => {
19266
+ if(row.type !== "group"){
19267
+ var cell = row.getCell(column);
19268
+
19269
+ try {
19270
+ row.getElement().removeChild(cell.getElement());
19271
+ } catch (ex) {
19272
+ console.warn("Could not removeColRight", ex.message);
19273
+ }
19274
+ }
19275
+ });
19276
+
19277
+ this.vDomPadRight += column.getWidth();
19278
+ this.rightCol --;
19279
+ }else {
19280
+ break;
19190
19281
  }
19191
- });
19192
-
19193
- this.vDomPadRight += column.getWidth();
19282
+ }else {
19283
+ break;
19284
+ }
19285
+ }
19286
+
19287
+ if(changes){
19194
19288
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
19195
-
19196
- this.rightCol --;
19197
-
19198
- this.removeColRight();
19199
19289
  }
19200
19290
  }
19201
19291
 
19202
19292
  removeColLeft(){
19203
- var column = this.columns[this.leftCol],
19204
- rows;
19293
+ var changes = false;
19205
19294
 
19206
- if(column && column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft){
19207
- rows = this.table.rowManager.getVisibleRows();
19295
+ while(true){
19296
+ let column = this.columns[this.leftCol];
19208
19297
 
19209
- rows.forEach((row) => {
19210
- var cell, el;
19211
-
19212
- if(row.type !== "group"){
19213
- cell = row.getCell(column);
19214
-
19215
- if(cell){
19216
- el = cell.getElement();
19217
-
19218
- if(el.parentNode){
19298
+ if(column){
19299
+ if(column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft){
19300
+ changes = true;
19301
+
19302
+ this.getVisibleRows().forEach((row) => {
19303
+ if(row.type !== "group"){
19304
+ var cell = row.getCell(column);
19305
+
19219
19306
  try {
19220
- row.getElement().removeChild(el);
19307
+ row.getElement().removeChild(cell.getElement());
19221
19308
  } catch (ex) {
19222
19309
  console.warn("Could not removeColLeft", ex.message);
19223
19310
  }
19224
19311
  }
19225
- }
19312
+ });
19313
+
19314
+ this.vDomPadLeft += column.getWidth();
19315
+ this.leftCol ++;
19316
+ }else {
19317
+ break;
19226
19318
  }
19227
- });
19228
-
19229
- this.vDomPadLeft += column.getWidth();
19319
+ }else {
19320
+ break;
19321
+ }
19322
+ }
19323
+
19324
+ if(changes){
19230
19325
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
19231
-
19232
- this.leftCol ++;
19233
-
19234
- this.removeColLeft();
19235
19326
  }
19327
+
19236
19328
  }
19237
19329
 
19238
19330
  fitDataColActualWidthCheck(column){
@@ -19247,12 +19339,14 @@ class VirtualDomHorizontal extends Renderer{
19247
19339
  if(widthDiff){
19248
19340
  column.modules.vdomHoz.rightPos += widthDiff;
19249
19341
  column.modules.vdomHoz.width = newWidth;
19250
- this.colPositionAdjust(this.rightCol + 2, this.columns.length, widthDiff);
19342
+ this.colPositionAdjust(this.columns.indexOf(column) + 1, this.columns.length, widthDiff);
19251
19343
  }
19252
19344
 
19253
19345
  column.modules.vdomHoz.fitDataCheck = false;
19254
19346
  }
19255
- };
19347
+
19348
+ return widthDiff;
19349
+ }
19256
19350
 
19257
19351
  initializeRow(row){
19258
19352
  if(row.type !== "group"){