tabulator-tables 5.1.5 → 5.1.6

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.5",
3
+ "version": "5.1.6",
4
4
  "description": "Interactive table generation JavaScript library",
5
5
  "style": "dist/css/tabulator.css",
6
6
  "main": "dist/js/tabulator.js",
@@ -18,8 +18,9 @@ export default class VirtualDomHorizontal extends Renderer{
18
18
  this.fitDataColAvg = 0;
19
19
 
20
20
  this.windowBuffer = 200; //pixel margin to make column visible before it is shown on screen
21
-
22
21
 
22
+ this.visibleRows = null;
23
+
23
24
  this.initialized = false;
24
25
  this.isFitData = false;
25
26
 
@@ -29,6 +30,7 @@ export default class VirtualDomHorizontal extends Renderer{
29
30
  initialize(){
30
31
  this.compatibilityCheck();
31
32
  this.layoutCheck();
33
+ this.vertScrollListen();
32
34
  }
33
35
 
34
36
  compatibilityCheck(){
@@ -68,10 +70,16 @@ export default class VirtualDomHorizontal extends Renderer{
68
70
 
69
71
  return ok;
70
72
  }
71
-
73
+
72
74
  layoutCheck(){
73
75
  this.isFitData = this.options("layout").startsWith('fitData');
74
76
  }
77
+
78
+ vertScrollListen(){
79
+ this.subscribe("scroll-vertical", () => {
80
+ this.visibleRows = null;
81
+ })
82
+ }
75
83
 
76
84
  //////////////////////////////////////
77
85
  ///////// Public Functions ///////////
@@ -80,6 +88,7 @@ export default class VirtualDomHorizontal extends Renderer{
80
88
  renderColumns(row, force){
81
89
  this.dataChange();
82
90
  }
91
+
83
92
 
84
93
  scrollColumns(left, dir){
85
94
  if(this.scrollLeft != left){
@@ -88,20 +97,20 @@ export default class VirtualDomHorizontal extends Renderer{
88
97
  this.scroll(left - (this.vDomScrollPosLeft + this.windowBuffer));
89
98
  }
90
99
  }
91
-
100
+
92
101
  calcWindowBuffer(){
93
102
  var buffer = this.elementVertical.clientWidth;
94
-
103
+
95
104
  this.table.columnManager.columnsByIndex.forEach((column) => {
96
105
  if(column.visible){
97
106
  var width = column.getWidth();
98
-
107
+
99
108
  if(width > buffer){
100
109
  buffer = width;
101
110
  }
102
111
  }
103
112
  });
104
-
113
+
105
114
  this.windowBuffer = buffer * 2;
106
115
  }
107
116
 
@@ -119,20 +128,20 @@ export default class VirtualDomHorizontal extends Renderer{
119
128
  }
120
129
 
121
130
  this.clear();
122
-
131
+
123
132
  this.calcWindowBuffer();
124
133
 
125
134
  this.scrollLeft = this.elementVertical.scrollLeft;
126
135
 
127
136
  this.vDomScrollPosLeft = this.scrollLeft - this.windowBuffer;
128
137
  this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.windowBuffer;
129
-
138
+
130
139
  this.table.columnManager.columnsByIndex.forEach((column) => {
131
140
  var config = {};
132
141
 
133
142
  if(column.visible){
134
143
  var width = column.getWidth();
135
-
144
+
136
145
  config.leftPos = colPos;
137
146
  config.rightPos = colPos + width;
138
147
 
@@ -259,18 +268,18 @@ export default class VirtualDomHorizontal extends Renderer{
259
268
 
260
269
  collsWidth += cell.column.getWidth();
261
270
 
262
- if(collsWidth > this.vDomScrollPosRight){
263
- break;
264
- }
271
+ // if(collsWidth > this.vDomScrollPosRight){
272
+ // break;
273
+ // }
265
274
  }
266
275
 
267
276
  rowEl.parentNode.removeChild(rowEl);
268
277
 
269
- this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
278
+ // this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
270
279
 
271
- for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
272
- this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
273
- }
280
+ // for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
281
+ // this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
282
+ // }
274
283
 
275
284
  this.rerenderColumns(false, true);
276
285
  }
@@ -301,17 +310,25 @@ export default class VirtualDomHorizontal extends Renderer{
301
310
  }
302
311
 
303
312
  reinitializeRows(){
304
- var rows = this.table.rowManager.getVisibleRows();
313
+ var rows = this.getVisibleRows();
305
314
  rows.forEach((row) => {
306
315
  this.reinitializeRow(row, true);
307
316
  });
308
317
  }
309
318
 
319
+ getVisibleRows(){
320
+ if (!this.visibleRows){
321
+ this.visibleRows = this.table.rowManager.getVisibleRows();
322
+ }
323
+
324
+ return this.visibleRows;
325
+ }
326
+
310
327
  scroll(diff){
311
328
  this.vDomScrollPosLeft += diff;
312
329
  this.vDomScrollPosRight += diff;
313
-
314
- if(diff > (this.elementVertical.clientWidth * .8)){
330
+
331
+ if(Math.abs(diff) > (this.windowBuffer / 2)){
315
332
  this.rerenderColumns();
316
333
  }else{
317
334
  if(diff > 0){
@@ -336,131 +353,165 @@ export default class VirtualDomHorizontal extends Renderer{
336
353
  }
337
354
 
338
355
  addColRight(){
339
- var column = this.columns[this.rightCol + 1],
340
- rows, newWidth, widthDiff;
356
+ var changes = false;
341
357
 
342
- if(column && column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight){
343
- rows = this.table.rowManager.getVisibleRows();
358
+ while(true){
344
359
 
345
- rows.forEach((row) => {
346
- if(row.type !== "group"){
347
- var cell = row.getCell(column);
348
- row.getElement().appendChild(cell.getElement());
349
- cell.cellRendered();
350
- }
351
- });
360
+ let column = this.columns[this.rightCol + 1];
352
361
 
353
- this.fitDataColActualWidthCheck(column);
354
-
355
- this.rightCol++; // Don't move this below the >= check below
356
-
357
- if(this.rightCol >= (this.columns.length - 1)){
358
- this.vDomPadRight = 0;
362
+ if(column){
363
+ if(column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight){
364
+ changes = true;
365
+
366
+ this.getVisibleRows().forEach((row) => {
367
+ if(row.type !== "group"){
368
+ var cell = row.getCell(column);
369
+ row.getElement().appendChild(cell.getElement());
370
+ cell.cellRendered();
371
+ }
372
+ });
373
+
374
+ this.fitDataColActualWidthCheck(column);
375
+
376
+ this.rightCol++; // Don't move this below the >= check below
377
+
378
+ if(this.rightCol >= (this.columns.length - 1)){
379
+ this.vDomPadRight = 0;
380
+ }else{
381
+ this.vDomPadRight -= column.getWidth();
382
+ }
383
+ }else{
384
+ break;
385
+ }
359
386
  }else{
360
- this.vDomPadRight -= column.getWidth();
387
+ break;
361
388
  }
362
-
389
+ }
390
+
391
+ if(changes){
363
392
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
364
-
365
- this.addColRight();
366
393
  }
367
394
  }
368
395
 
369
396
  addColLeft(){
370
- var column = this.columns[this.leftCol - 1],
371
- rows;
397
+ var changes = false;
372
398
 
373
- if(column && column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft){
374
- var rows = this.table.rowManager.getVisibleRows();
399
+ while(true){
400
+ let column = this.columns[this.leftCol - 1];
375
401
 
376
- rows.forEach((row) => {
377
- if(row.type !== "group"){
378
- var cell = row.getCell(column);
379
- row.getElement().prepend(cell.getElement());
380
- cell.cellRendered();
402
+ if(column){
403
+ if(column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft){
404
+ changes = true;
405
+
406
+ this.getVisibleRows().forEach((row) => {
407
+ if(row.type !== "group"){
408
+ var cell = row.getCell(column);
409
+ row.getElement().prepend(cell.getElement());
410
+ cell.cellRendered();
411
+ }
412
+ });
413
+
414
+ this.leftCol--; // don't move this below the <= check below
415
+
416
+ if(this.leftCol <= 0){ // replicating logic in addColRight
417
+ this.vDomPadLeft = 0;
418
+ }else{
419
+ this.vDomPadLeft -= column.getWidth();
420
+ }
421
+
422
+ let diff = this.fitDataColActualWidthCheck(column);
423
+
424
+ if(diff){
425
+ this.scrollLeft = this.elementVertical.scrollLeft = this.elementVertical.scrollLeft + diff;
426
+ this.vDomPadRight -= diff;
427
+ }
428
+
429
+ }else{
430
+ break;
381
431
  }
382
- });
383
-
384
- this.fitDataColActualWidthCheck(column);
385
-
386
- this.leftCol--; // don't move this below the <= check below
387
-
388
- if(this.leftCol <= 0){ // replicating logic in addColRight
389
- this.vDomPadLeft = 0;
390
432
  }else{
391
- this.vDomPadLeft -= column.getWidth();
433
+ break;
392
434
  }
393
-
435
+ }
436
+
437
+ if(changes){
394
438
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
395
-
396
-
397
- this.addColLeft();
398
439
  }
399
440
  }
400
441
 
401
- removeColRight(column){
402
- var column = this.columns[this.rightCol],
403
- rows;
442
+ removeColRight(){
443
+ var changes = false;
404
444
 
405
- if(column && column.modules.vdomHoz.leftPos > this.vDomScrollPosRight){
406
- rows = this.table.rowManager.getVisibleRows();
407
-
408
- column.modules.vdomHoz.visible = false;
445
+ while(true){
446
+ let column = this.columns[this.rightCol];
409
447
 
410
- rows.forEach((row) => {
411
- if(row.type !== "group"){
412
- var cell = row.getCell(column);
413
- try {
414
- row.getElement().removeChild(cell.getElement());
415
- } catch (ex) {
416
- console.warn("Could not removeColRight", ex.message)
417
- }
448
+ if(column){
449
+ if(column.modules.vdomHoz.leftPos > this.vDomScrollPosRight){
450
+ changes = true;
451
+
452
+ this.getVisibleRows().forEach((row) => {
453
+ if(row.type !== "group"){
454
+ var cell = row.getCell(column);
455
+
456
+ try {
457
+ row.getElement().removeChild(cell.getElement());
458
+ } catch (ex) {
459
+ console.warn("Could not removeColRight", ex.message)
460
+ }
461
+ }
462
+ });
463
+
464
+ this.vDomPadRight += column.getWidth();
465
+ this.rightCol --;
466
+ }else{
467
+ break;
418
468
  }
419
- });
420
-
421
- this.vDomPadRight += column.getWidth();
469
+ }else{
470
+ break;
471
+ }
472
+ }
473
+
474
+ if(changes){
422
475
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
423
-
424
- this.rightCol --;
425
-
426
- this.removeColRight();
427
476
  }
428
477
  }
429
478
 
430
479
  removeColLeft(){
431
- var column = this.columns[this.leftCol],
432
- rows;
480
+ var changes = false;
433
481
 
434
- if(column && column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft){
435
- rows = this.table.rowManager.getVisibleRows();
482
+ while(true){
483
+ let column = this.columns[this.leftCol];
436
484
 
437
- rows.forEach((row) => {
438
- var cell, el;
439
-
440
- if(row.type !== "group"){
441
- cell = row.getCell(column);
442
-
443
- if(cell){
444
- el = cell.getElement();
445
-
446
- if(el.parentNode){
485
+ if(column){
486
+ if(column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft){
487
+ changes = true;
488
+
489
+ this.getVisibleRows().forEach((row) => {
490
+ if(row.type !== "group"){
491
+ var cell = row.getCell(column);
492
+
447
493
  try {
448
- row.getElement().removeChild(el);
494
+ row.getElement().removeChild(cell.getElement());
449
495
  } catch (ex) {
450
496
  console.warn("Could not removeColLeft", ex.message)
451
497
  }
452
498
  }
453
- }
499
+ });
500
+
501
+ this.vDomPadLeft += column.getWidth();
502
+ this.leftCol ++;
503
+ }else{
504
+ break;
454
505
  }
455
- });
456
-
457
- this.vDomPadLeft += column.getWidth();
506
+ }else{
507
+ break;
508
+ }
509
+ }
510
+
511
+ if(changes){
458
512
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
459
-
460
- this.leftCol ++;
461
-
462
- this.removeColLeft();
463
513
  }
514
+
464
515
  }
465
516
 
466
517
  fitDataColActualWidthCheck(column){
@@ -475,12 +526,14 @@ export default class VirtualDomHorizontal extends Renderer{
475
526
  if(widthDiff){
476
527
  column.modules.vdomHoz.rightPos += widthDiff;
477
528
  column.modules.vdomHoz.width = newWidth;
478
- this.colPositionAdjust(this.rightCol + 2, this.columns.length, widthDiff);
529
+ this.colPositionAdjust(this.columns.indexOf(column) + 1, this.columns.length, widthDiff);
479
530
  }
480
531
 
481
532
  column.modules.vdomHoz.fitDataCheck = false;
482
533
  }
483
- };
534
+
535
+ return widthDiff;
536
+ }
484
537
 
485
538
  initializeRow(row){
486
539
  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
  }