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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tabulator-tables",
3
- "version": "5.1.4",
3
+ "version": "5.1.7",
4
4
  "description": "Interactive table generation JavaScript library",
5
5
  "style": "dist/css/tabulator.css",
6
6
  "main": "dist/js/tabulator.js",
@@ -17,15 +17,20 @@ export default class VirtualDomHorizontal extends Renderer{
17
17
 
18
18
  this.fitDataColAvg = 0;
19
19
 
20
- this.window = 200; //pixel margin to make column visible before it is shown on screen
20
+ this.windowBuffer = 200; //pixel margin to make column visible before it is shown on screen
21
21
 
22
+ this.visibleRows = null;
23
+
22
24
  this.initialized = false;
25
+ this.isFitData = false;
23
26
 
24
27
  this.columns = [];
25
28
  }
26
29
 
27
30
  initialize(){
28
31
  this.compatibilityCheck();
32
+ this.layoutCheck();
33
+ this.vertScrollListen();
29
34
  }
30
35
 
31
36
  compatibilityCheck(){
@@ -66,6 +71,19 @@ export default class VirtualDomHorizontal extends Renderer{
66
71
  return ok;
67
72
  }
68
73
 
74
+ layoutCheck(){
75
+ this.isFitData = this.options("layout").startsWith('fitData');
76
+ }
77
+
78
+ vertScrollListen(){
79
+ this.subscribe("scroll-vertical", this.clearVisRowCache.bind(this));
80
+ this.subscribe("data-refreshed", this.clearVisRowCache.bind(this));
81
+ }
82
+
83
+ clearVisRowCache(){
84
+ this.visibleRows = null;
85
+ }
86
+
69
87
  //////////////////////////////////////
70
88
  ///////// Public Functions ///////////
71
89
  //////////////////////////////////////
@@ -73,21 +91,40 @@ export default class VirtualDomHorizontal extends Renderer{
73
91
  renderColumns(row, force){
74
92
  this.dataChange();
75
93
  }
94
+
76
95
 
77
96
  scrollColumns(left, dir){
78
97
  if(this.scrollLeft != left){
79
98
  this.scrollLeft = left;
80
99
 
81
- this.scroll(left - (this.vDomScrollPosLeft + this.window));
100
+ this.scroll(left - (this.vDomScrollPosLeft + this.windowBuffer));
82
101
  }
83
102
  }
84
103
 
104
+ calcWindowBuffer(){
105
+ var buffer = this.elementVertical.clientWidth;
106
+
107
+ this.table.columnManager.columnsByIndex.forEach((column) => {
108
+ if(column.visible){
109
+ var width = column.getWidth();
110
+
111
+ if(width > buffer){
112
+ buffer = width;
113
+ }
114
+ }
115
+ });
116
+
117
+ this.windowBuffer = buffer * 2;
118
+ }
119
+
85
120
  rerenderColumns(update, blockRedraw){
86
121
  var old = {
87
122
  cols:this.columns,
88
123
  leftCol:this.leftCol,
89
124
  rightCol:this.rightCol,
90
- };
125
+ },
126
+ colPos = 0;
127
+
91
128
 
92
129
  if(update && !this.initialized){
93
130
  return;
@@ -95,12 +132,12 @@ export default class VirtualDomHorizontal extends Renderer{
95
132
 
96
133
  this.clear();
97
134
 
98
- this.scrollLeft = this.elementVertical.scrollLeft;
135
+ this.calcWindowBuffer();
99
136
 
100
- this.vDomScrollPosLeft = this.scrollLeft - this.window;
101
- this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.window;
137
+ this.scrollLeft = this.elementVertical.scrollLeft;
102
138
 
103
- var colPos = 0;
139
+ this.vDomScrollPosLeft = this.scrollLeft - this.windowBuffer;
140
+ this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.windowBuffer;
104
141
 
105
142
  this.table.columnManager.columnsByIndex.forEach((column) => {
106
143
  var config = {};
@@ -113,7 +150,7 @@ export default class VirtualDomHorizontal extends Renderer{
113
150
 
114
151
  config.width = width;
115
152
 
116
- if (this.options("layout") === "fitData") {
153
+ if (this.isFitData) {
117
154
  config.fitDataCheck = column.modules.vdomHoz ? column.modules.vdomHoz.fitDataCheck : true;
118
155
  }
119
156
 
@@ -202,7 +239,7 @@ export default class VirtualDomHorizontal extends Renderer{
202
239
  colEnd = 0,
203
240
  group, row, rowEl;
204
241
 
205
- if(this.options("layout") === "fitData"){
242
+ if(this.isFitData){
206
243
  this.table.columnManager.columnsByIndex.forEach((column) => {
207
244
  if(!column.definition.width && column.visible){
208
245
  change = true;
@@ -212,7 +249,7 @@ export default class VirtualDomHorizontal extends Renderer{
212
249
  if(change){
213
250
  if(change && this.table.rowManager.getDisplayRows().length){
214
251
 
215
- this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.window;
252
+ this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.windowBuffer;
216
253
 
217
254
  var row = this.chain("rows-sample", [1], [], () => {
218
255
  return this.table.rowManager.getDisplayRows();
@@ -234,18 +271,18 @@ export default class VirtualDomHorizontal extends Renderer{
234
271
 
235
272
  collsWidth += cell.column.getWidth();
236
273
 
237
- if(collsWidth > this.vDomScrollPosRight){
238
- break;
239
- }
274
+ // if(collsWidth > this.vDomScrollPosRight){
275
+ // break;
276
+ // }
240
277
  }
241
278
 
242
279
  rowEl.parentNode.removeChild(rowEl);
243
280
 
244
- this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
281
+ // this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
245
282
 
246
- for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
247
- this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
248
- }
283
+ // for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
284
+ // this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
285
+ // }
249
286
 
250
287
  this.rerenderColumns(false, true);
251
288
  }
@@ -276,17 +313,25 @@ export default class VirtualDomHorizontal extends Renderer{
276
313
  }
277
314
 
278
315
  reinitializeRows(){
279
- var rows = this.table.rowManager.getVisibleRows();
316
+ var rows = this.getVisibleRows();
280
317
  rows.forEach((row) => {
281
318
  this.reinitializeRow(row, true);
282
319
  });
283
320
  }
284
321
 
322
+ getVisibleRows(){
323
+ if (!this.visibleRows){
324
+ this.visibleRows = this.table.rowManager.getVisibleRows();
325
+ }
326
+
327
+ return this.visibleRows;
328
+ }
329
+
285
330
  scroll(diff){
286
331
  this.vDomScrollPosLeft += diff;
287
332
  this.vDomScrollPosRight += diff;
288
-
289
- if(diff > (this.elementVertical.clientWidth * .8)){
333
+
334
+ if(Math.abs(diff) > (this.windowBuffer / 2)){
290
335
  this.rerenderColumns();
291
336
  }else{
292
337
  if(diff > 0){
@@ -311,131 +356,165 @@ export default class VirtualDomHorizontal extends Renderer{
311
356
  }
312
357
 
313
358
  addColRight(){
314
- var column = this.columns[this.rightCol + 1],
315
- rows, newWidth, widthDiff;
359
+ var changes = false;
316
360
 
317
- if(column && column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight){
318
- rows = this.table.rowManager.getVisibleRows();
361
+ while(true){
319
362
 
320
- rows.forEach((row) => {
321
- if(row.type !== "group"){
322
- var cell = row.getCell(column);
323
- row.getElement().appendChild(cell.getElement());
324
- cell.cellRendered();
325
- }
326
- });
327
-
328
- this.fitDataColActualWidthCheck(column);
329
-
330
- this.rightCol++; // Don't move this below the >= check below
363
+ let column = this.columns[this.rightCol + 1];
331
364
 
332
- if(this.rightCol >= (this.columns.length - 1)){
333
- this.vDomPadRight = 0;
365
+ if(column){
366
+ if(column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight){
367
+ changes = true;
368
+
369
+ this.getVisibleRows().forEach((row) => {
370
+ if(row.type !== "group"){
371
+ var cell = row.getCell(column);
372
+ row.getElement().appendChild(cell.getElement());
373
+ cell.cellRendered();
374
+ }
375
+ });
376
+
377
+ this.fitDataColActualWidthCheck(column);
378
+
379
+ this.rightCol++; // Don't move this below the >= check below
380
+
381
+ if(this.rightCol >= (this.columns.length - 1)){
382
+ this.vDomPadRight = 0;
383
+ }else{
384
+ this.vDomPadRight -= column.getWidth();
385
+ }
386
+ }else{
387
+ break;
388
+ }
334
389
  }else{
335
- this.vDomPadRight -= column.getWidth();
390
+ break;
336
391
  }
337
-
392
+ }
393
+
394
+ if(changes){
338
395
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
339
-
340
- this.addColRight();
341
396
  }
342
397
  }
343
398
 
344
399
  addColLeft(){
345
- var column = this.columns[this.leftCol - 1],
346
- rows;
400
+ var changes = false;
347
401
 
348
- if(column && column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft){
349
- var rows = this.table.rowManager.getVisibleRows();
402
+ while(true){
403
+ let column = this.columns[this.leftCol - 1];
350
404
 
351
- rows.forEach((row) => {
352
- if(row.type !== "group"){
353
- var cell = row.getCell(column);
354
- row.getElement().prepend(cell.getElement());
355
- cell.cellRendered();
405
+ if(column){
406
+ if(column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft){
407
+ changes = true;
408
+
409
+ this.getVisibleRows().forEach((row) => {
410
+ if(row.type !== "group"){
411
+ var cell = row.getCell(column);
412
+ row.getElement().prepend(cell.getElement());
413
+ cell.cellRendered();
414
+ }
415
+ });
416
+
417
+ this.leftCol--; // don't move this below the <= check below
418
+
419
+ if(this.leftCol <= 0){ // replicating logic in addColRight
420
+ this.vDomPadLeft = 0;
421
+ }else{
422
+ this.vDomPadLeft -= column.getWidth();
423
+ }
424
+
425
+ let diff = this.fitDataColActualWidthCheck(column);
426
+
427
+ if(diff){
428
+ this.scrollLeft = this.elementVertical.scrollLeft = this.elementVertical.scrollLeft + diff;
429
+ this.vDomPadRight -= diff;
430
+ }
431
+
432
+ }else{
433
+ break;
356
434
  }
357
- });
358
-
359
- this.fitDataColActualWidthCheck(column);
360
-
361
- this.leftCol--; // don't move this below the <= check below
362
-
363
- if(this.leftCol <= 0){ // replicating logic in addColRight
364
- this.vDomPadLeft = 0;
365
435
  }else{
366
- this.vDomPadLeft -= column.getWidth();
436
+ break;
367
437
  }
368
-
438
+ }
439
+
440
+ if(changes){
369
441
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
370
-
371
-
372
- this.addColLeft();
373
442
  }
374
443
  }
375
444
 
376
- removeColRight(column){
377
- var column = this.columns[this.rightCol],
378
- rows;
445
+ removeColRight(){
446
+ var changes = false;
379
447
 
380
- if(column && column.modules.vdomHoz.leftPos > this.vDomScrollPosRight){
381
- rows = this.table.rowManager.getVisibleRows();
448
+ while(true){
449
+ let column = this.columns[this.rightCol];
382
450
 
383
- column.modules.vdomHoz.visible = false;
384
-
385
- rows.forEach((row) => {
386
- if(row.type !== "group"){
387
- var cell = row.getCell(column);
388
- try {
389
- row.getElement().removeChild(cell.getElement());
390
- } catch (ex) {
391
- console.warn("Could not removeColRight", ex.message)
392
- }
451
+ if(column){
452
+ if(column.modules.vdomHoz.leftPos > this.vDomScrollPosRight){
453
+ changes = true;
454
+
455
+ this.getVisibleRows().forEach((row) => {
456
+ if(row.type !== "group"){
457
+ var cell = row.getCell(column);
458
+
459
+ try {
460
+ row.getElement().removeChild(cell.getElement());
461
+ } catch (ex) {
462
+ console.warn("Could not removeColRight", ex.message)
463
+ }
464
+ }
465
+ });
466
+
467
+ this.vDomPadRight += column.getWidth();
468
+ this.rightCol --;
469
+ }else{
470
+ break;
393
471
  }
394
- });
395
-
396
- this.vDomPadRight += column.getWidth();
472
+ }else{
473
+ break;
474
+ }
475
+ }
476
+
477
+ if(changes){
397
478
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
398
-
399
- this.rightCol --;
400
-
401
- this.removeColRight();
402
479
  }
403
480
  }
404
481
 
405
482
  removeColLeft(){
406
- var column = this.columns[this.leftCol],
407
- rows;
483
+ var changes = false;
408
484
 
409
- if(column && column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft){
410
- rows = this.table.rowManager.getVisibleRows();
485
+ while(true){
486
+ let column = this.columns[this.leftCol];
411
487
 
412
- rows.forEach((row) => {
413
- var cell, el;
414
-
415
- if(row.type !== "group"){
416
- cell = row.getCell(column);
417
-
418
- if(cell){
419
- el = cell.getElement();
420
-
421
- if(el.parentNode){
488
+ if(column){
489
+ if(column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft){
490
+ changes = true;
491
+
492
+ this.getVisibleRows().forEach((row) => {
493
+ if(row.type !== "group"){
494
+ var cell = row.getCell(column);
495
+
422
496
  try {
423
- row.getElement().removeChild(el);
497
+ row.getElement().removeChild(cell.getElement());
424
498
  } catch (ex) {
425
499
  console.warn("Could not removeColLeft", ex.message)
426
500
  }
427
501
  }
428
- }
502
+ });
503
+
504
+ this.vDomPadLeft += column.getWidth();
505
+ this.leftCol ++;
506
+ }else{
507
+ break;
429
508
  }
430
- });
431
-
432
- this.vDomPadLeft += column.getWidth();
509
+ }else{
510
+ break;
511
+ }
512
+ }
513
+
514
+ if(changes){
433
515
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
434
-
435
- this.leftCol ++;
436
-
437
- this.removeColLeft();
438
516
  }
517
+
439
518
  }
440
519
 
441
520
  fitDataColActualWidthCheck(column){
@@ -450,12 +529,14 @@ export default class VirtualDomHorizontal extends Renderer{
450
529
  if(widthDiff){
451
530
  column.modules.vdomHoz.rightPos += widthDiff;
452
531
  column.modules.vdomHoz.width = newWidth;
453
- this.colPositionAdjust(this.rightCol + 2, this.columns.length, widthDiff);
532
+ this.colPositionAdjust(this.columns.indexOf(column) + 1, this.columns.length, widthDiff);
454
533
  }
455
534
 
456
535
  column.modules.vdomHoz.fitDataCheck = false;
457
536
  }
458
- };
537
+
538
+ return widthDiff;
539
+ }
459
540
 
460
541
  initializeRow(row){
461
542
  if(row.type !== "group"){
@@ -335,13 +335,11 @@ class Menu extends Module{
335
335
  }
336
336
 
337
337
  //move menu to start on bottom edge if it is too close to the edge of the screen
338
- if((y + element.offsetHeight) >= this.menuContainer.offsetHeight){
339
- element.style.top = "";
340
-
338
+ if((y + element.offsetHeight) > this.menuContainer.offsetHeight) {
341
339
  if(parentEl){
342
- element.style.bottom = (this.menuContainer.offsetHeight - parentOffset.top - parentEl.offsetHeight - 1) + "px";
340
+ element.style.top = (parseInt(element.style.top) - element.offsetHeight + parentEl.offsetHeight + 1) + "px";
343
341
  }else{
344
- element.style.bottom = (this.menuContainer.offsetHeight - y) + "px";
342
+ element.style.top = (parseInt(element.style.top) - element.offsetHeight) + "px";
345
343
  }
346
344
  }
347
345
  }
@@ -575,17 +575,18 @@ class Page extends Module{
575
575
  this.trackChanges();
576
576
  }
577
577
 
578
- _setPageCounter(totalRows){
579
- var content, currentRow;
578
+ _setPageCounter(totalRows, size, currentRow){
579
+ var content;
580
580
 
581
581
  if(this.pageCounter){
582
- currentRow = ((this.page - 1) * this.size) + 1;
583
582
 
584
583
  if(this.mode === "remote"){
584
+ size = this.size;
585
+ currentRow = ((this.page - 1) * this.size) + 1;
585
586
  totalRows = this.remoteRowCountEstimate;
586
587
  }
587
588
 
588
- content = this.pageCounter.call(this, this.size, currentRow, this.page, totalRows, this.max);
589
+ content = this.pageCounter.call(this, size, currentRow, this.page, totalRows, this.max);
589
590
 
590
591
  switch(typeof content){
591
592
  case "object":
@@ -725,7 +726,12 @@ class Page extends Module{
725
726
 
726
727
  //return appropriate rows for current page
727
728
  getRows(data){
728
- var output, start, end;
729
+ var actualRowPageSize = 0,
730
+ output, start, end, actualStartRow;
731
+
732
+ var actualRows = data.filter((row) => {
733
+ return row.type === "row";
734
+ });
729
735
 
730
736
  if(this.mode == "local"){
731
737
  output = [];
@@ -740,21 +746,30 @@ class Page extends Module{
740
746
  end = start + parseInt(this.size);
741
747
  }
742
748
 
743
-
744
749
  this._setPageButtons();
745
750
 
746
751
  for(let i = start; i < end; i++){
747
- if(data[i]){
748
- output.push(data[i]);
752
+ let row = data[i];
753
+
754
+ if(row){
755
+ output.push(row);
756
+
757
+ if(row.type === "row"){
758
+ if(!actualStartRow){
759
+ actualStartRow = row;
760
+ }
761
+
762
+ actualRowPageSize++;
763
+ }
749
764
  }
750
765
  }
751
-
752
- this._setPageCounter(data.length);
766
+
767
+ this._setPageCounter(actualRows.length, actualRowPageSize, actualStartRow ? (actualRows.indexOf(actualStartRow) + 1) : 0);
753
768
 
754
769
  return output;
755
770
  }else{
756
771
  this._setPageButtons();
757
- this._setPageCounter(data.length);
772
+ this._setPageCounter(actualRows.length);
758
773
 
759
774
  return data.slice(0);
760
775
  }