tabulator-tables 5.1.3 → 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.3",
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",
@@ -44,7 +44,7 @@ export default class FooterManager extends CoreFeature{
44
44
  this.containerElement.innerHTML = this.table.options.footerElement;
45
45
  }else{
46
46
  this.external = true;
47
- this.element = document.querySelector(this.table.options.footerElement);
47
+ this.containerElement = document.querySelector(this.table.options.footerElement);
48
48
  }
49
49
  break;
50
50
 
@@ -171,7 +171,7 @@ class Tabulator {
171
171
  _clearObjectPointers(){
172
172
  this.options.columns = this.options.columns.slice(0);
173
173
 
174
- if(this.options.data && !this.options.reactiveData){
174
+ if(Array.isArray(this.options.data) && !this.options.reactiveData){
175
175
  this.options.data = this.options.data.slice(0);
176
176
  }
177
177
  }
@@ -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,16 @@ 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", () => {
80
+ this.visibleRows = null;
81
+ })
82
+ }
83
+
69
84
  //////////////////////////////////////
70
85
  ///////// Public Functions ///////////
71
86
  //////////////////////////////////////
@@ -73,21 +88,40 @@ export default class VirtualDomHorizontal extends Renderer{
73
88
  renderColumns(row, force){
74
89
  this.dataChange();
75
90
  }
91
+
76
92
 
77
93
  scrollColumns(left, dir){
78
94
  if(this.scrollLeft != left){
79
95
  this.scrollLeft = left;
80
96
 
81
- this.scroll(left - (this.vDomScrollPosLeft + this.window));
97
+ this.scroll(left - (this.vDomScrollPosLeft + this.windowBuffer));
82
98
  }
83
99
  }
84
100
 
101
+ calcWindowBuffer(){
102
+ var buffer = this.elementVertical.clientWidth;
103
+
104
+ this.table.columnManager.columnsByIndex.forEach((column) => {
105
+ if(column.visible){
106
+ var width = column.getWidth();
107
+
108
+ if(width > buffer){
109
+ buffer = width;
110
+ }
111
+ }
112
+ });
113
+
114
+ this.windowBuffer = buffer * 2;
115
+ }
116
+
85
117
  rerenderColumns(update, blockRedraw){
86
118
  var old = {
87
119
  cols:this.columns,
88
120
  leftCol:this.leftCol,
89
121
  rightCol:this.rightCol,
90
- };
122
+ },
123
+ colPos = 0;
124
+
91
125
 
92
126
  if(update && !this.initialized){
93
127
  return;
@@ -95,12 +129,12 @@ export default class VirtualDomHorizontal extends Renderer{
95
129
 
96
130
  this.clear();
97
131
 
98
- this.scrollLeft = this.elementVertical.scrollLeft;
132
+ this.calcWindowBuffer();
99
133
 
100
- this.vDomScrollPosLeft = this.scrollLeft - this.window;
101
- this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.window;
134
+ this.scrollLeft = this.elementVertical.scrollLeft;
102
135
 
103
- var colPos = 0;
136
+ this.vDomScrollPosLeft = this.scrollLeft - this.windowBuffer;
137
+ this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.windowBuffer;
104
138
 
105
139
  this.table.columnManager.columnsByIndex.forEach((column) => {
106
140
  var config = {};
@@ -113,7 +147,7 @@ export default class VirtualDomHorizontal extends Renderer{
113
147
 
114
148
  config.width = width;
115
149
 
116
- if (this.options("layout") === "fitData") {
150
+ if (this.isFitData) {
117
151
  config.fitDataCheck = column.modules.vdomHoz ? column.modules.vdomHoz.fitDataCheck : true;
118
152
  }
119
153
 
@@ -202,7 +236,7 @@ export default class VirtualDomHorizontal extends Renderer{
202
236
  colEnd = 0,
203
237
  group, row, rowEl;
204
238
 
205
- if(this.options("layout") === "fitData"){
239
+ if(this.isFitData){
206
240
  this.table.columnManager.columnsByIndex.forEach((column) => {
207
241
  if(!column.definition.width && column.visible){
208
242
  change = true;
@@ -212,10 +246,10 @@ export default class VirtualDomHorizontal extends Renderer{
212
246
  if(change){
213
247
  if(change && this.table.rowManager.getDisplayRows().length){
214
248
 
215
- this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.window;
249
+ this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.windowBuffer;
216
250
 
217
251
  var row = this.chain("rows-sample", [1], [], () => {
218
- return this.table.rowManager.getDisplayRows()[0];
252
+ return this.table.rowManager.getDisplayRows();
219
253
  })[0];
220
254
 
221
255
  if(row){
@@ -234,18 +268,18 @@ export default class VirtualDomHorizontal extends Renderer{
234
268
 
235
269
  collsWidth += cell.column.getWidth();
236
270
 
237
- if(collsWidth > this.vDomScrollPosRight){
238
- break;
239
- }
271
+ // if(collsWidth > this.vDomScrollPosRight){
272
+ // break;
273
+ // }
240
274
  }
241
275
 
242
276
  rowEl.parentNode.removeChild(rowEl);
243
277
 
244
- this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
278
+ // this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
245
279
 
246
- for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
247
- this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
248
- }
280
+ // for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
281
+ // this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
282
+ // }
249
283
 
250
284
  this.rerenderColumns(false, true);
251
285
  }
@@ -276,17 +310,25 @@ export default class VirtualDomHorizontal extends Renderer{
276
310
  }
277
311
 
278
312
  reinitializeRows(){
279
- var rows = this.table.rowManager.getVisibleRows();
313
+ var rows = this.getVisibleRows();
280
314
  rows.forEach((row) => {
281
315
  this.reinitializeRow(row, true);
282
316
  });
283
317
  }
284
318
 
319
+ getVisibleRows(){
320
+ if (!this.visibleRows){
321
+ this.visibleRows = this.table.rowManager.getVisibleRows();
322
+ }
323
+
324
+ return this.visibleRows;
325
+ }
326
+
285
327
  scroll(diff){
286
328
  this.vDomScrollPosLeft += diff;
287
329
  this.vDomScrollPosRight += diff;
288
-
289
- if(diff > (this.elementVertical.clientWidth * .8)){
330
+
331
+ if(Math.abs(diff) > (this.windowBuffer / 2)){
290
332
  this.rerenderColumns();
291
333
  }else{
292
334
  if(diff > 0){
@@ -311,131 +353,165 @@ export default class VirtualDomHorizontal extends Renderer{
311
353
  }
312
354
 
313
355
  addColRight(){
314
- var column = this.columns[this.rightCol + 1],
315
- rows, newWidth, widthDiff;
356
+ var changes = false;
316
357
 
317
- if(column && column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight){
318
- rows = this.table.rowManager.getVisibleRows();
319
-
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
- });
358
+ while(true){
327
359
 
328
- this.fitDataColActualWidthCheck(column);
360
+ let column = this.columns[this.rightCol + 1];
329
361
 
330
- this.rightCol++; // Don't move this below the >= check below
331
-
332
- if(this.rightCol >= (this.columns.length - 1)){
333
- 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
+ }
334
386
  }else{
335
- this.vDomPadRight -= column.getWidth();
387
+ break;
336
388
  }
337
-
389
+ }
390
+
391
+ if(changes){
338
392
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
339
-
340
- this.addColRight();
341
393
  }
342
394
  }
343
395
 
344
396
  addColLeft(){
345
- var column = this.columns[this.leftCol - 1],
346
- rows;
397
+ var changes = false;
347
398
 
348
- if(column && column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft){
349
- var rows = this.table.rowManager.getVisibleRows();
399
+ while(true){
400
+ let column = this.columns[this.leftCol - 1];
350
401
 
351
- rows.forEach((row) => {
352
- if(row.type !== "group"){
353
- var cell = row.getCell(column);
354
- row.getElement().prepend(cell.getElement());
355
- 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;
356
431
  }
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
432
  }else{
366
- this.vDomPadLeft -= column.getWidth();
433
+ break;
367
434
  }
368
-
435
+ }
436
+
437
+ if(changes){
369
438
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
370
-
371
-
372
- this.addColLeft();
373
439
  }
374
440
  }
375
441
 
376
- removeColRight(column){
377
- var column = this.columns[this.rightCol],
378
- rows;
442
+ removeColRight(){
443
+ var changes = false;
379
444
 
380
- if(column && column.modules.vdomHoz.leftPos > this.vDomScrollPosRight){
381
- rows = this.table.rowManager.getVisibleRows();
382
-
383
- column.modules.vdomHoz.visible = false;
445
+ while(true){
446
+ let column = this.columns[this.rightCol];
384
447
 
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
- }
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;
393
468
  }
394
- });
395
-
396
- this.vDomPadRight += column.getWidth();
469
+ }else{
470
+ break;
471
+ }
472
+ }
473
+
474
+ if(changes){
397
475
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
398
-
399
- this.rightCol --;
400
-
401
- this.removeColRight();
402
476
  }
403
477
  }
404
478
 
405
479
  removeColLeft(){
406
- var column = this.columns[this.leftCol],
407
- rows;
480
+ var changes = false;
408
481
 
409
- if(column && column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft){
410
- rows = this.table.rowManager.getVisibleRows();
482
+ while(true){
483
+ let column = this.columns[this.leftCol];
411
484
 
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){
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
+
422
493
  try {
423
- row.getElement().removeChild(el);
494
+ row.getElement().removeChild(cell.getElement());
424
495
  } catch (ex) {
425
496
  console.warn("Could not removeColLeft", ex.message)
426
497
  }
427
498
  }
428
- }
499
+ });
500
+
501
+ this.vDomPadLeft += column.getWidth();
502
+ this.leftCol ++;
503
+ }else{
504
+ break;
429
505
  }
430
- });
431
-
432
- this.vDomPadLeft += column.getWidth();
506
+ }else{
507
+ break;
508
+ }
509
+ }
510
+
511
+ if(changes){
433
512
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
434
-
435
- this.leftCol ++;
436
-
437
- this.removeColLeft();
438
513
  }
514
+
439
515
  }
440
516
 
441
517
  fitDataColActualWidthCheck(column){
@@ -450,12 +526,14 @@ export default class VirtualDomHorizontal extends Renderer{
450
526
  if(widthDiff){
451
527
  column.modules.vdomHoz.rightPos += widthDiff;
452
528
  column.modules.vdomHoz.width = newWidth;
453
- this.colPositionAdjust(this.rightCol + 2, this.columns.length, widthDiff);
529
+ this.colPositionAdjust(this.columns.indexOf(column) + 1, this.columns.length, widthDiff);
454
530
  }
455
531
 
456
532
  column.modules.vdomHoz.fitDataCheck = false;
457
533
  }
458
- };
534
+
535
+ return widthDiff;
536
+ }
459
537
 
460
538
  initializeRow(row){
461
539
  if(row.type !== "group"){
@@ -76,6 +76,8 @@ export default class Row extends CoreFeature{
76
76
 
77
77
  this.generateCells();
78
78
 
79
+ this.initialized = true;
80
+
79
81
  this.table.columnManager.renderer.renderRowCells(this);
80
82
 
81
83
  if(force){
@@ -84,8 +86,6 @@ export default class Row extends CoreFeature{
84
86
 
85
87
  this.dispatch("row-layout", this);
86
88
 
87
- this.initialized = true;
88
-
89
89
  if(this.table.options.rowFormatter){
90
90
  this.table.options.rowFormatter(this.getComponent());
91
91
  }
@@ -255,7 +255,7 @@ export default class InteractionManager extends CoreFeature {
255
255
  return row.getElement() === target;
256
256
  });
257
257
 
258
- if(targets["row"].parentNode && targets["row"].parentNode.closest(".tabulator-row")){
258
+ if(targets["row"] && targets["row"].parentNode && targets["row"].parentNode.closest(".tabulator-row")){
259
259
  targets[key] = false;
260
260
  }
261
261
  }
@@ -467,10 +467,10 @@ class Export extends Module{
467
467
  rowEl.classList.add("tabulator-print-table-row");
468
468
 
469
469
  row.columns.forEach((col) => {
470
-
471
470
  if(col){
472
471
  var cellEl = document.createElement("td"),
473
472
  column = col.component._column,
473
+ index = this.table.columnManager.findColumnIndex(column),
474
474
  value = col.value;
475
475
 
476
476
  var cellWrapper = {
@@ -529,8 +529,8 @@ class Export extends Module{
529
529
  cellEl.innerHTML = value;
530
530
  }
531
531
 
532
- if(styles.firstCell){
533
- this.mapElementStyles(styles.firstCell, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom", "border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size"]);
532
+ if(styles.styleCells[index] || styles.firstCell){
533
+ this.mapElementStyles(styles.styleCells[index] || styles.firstCell, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom", "border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "text-align"]);
534
534
 
535
535
  if(column.definition.align){
536
536
  cellEl.style.textAlign = column.definition.align;
@@ -416,7 +416,9 @@ class Filter extends Module{
416
416
  editorElement.addEventListener("focus", (e) => {
417
417
  var left = this.table.columnManager.element.scrollLeft;
418
418
 
419
- if(left !== this.table.rowManager.element.scrollLeft){
419
+ var headerPos = this.table.rowManager.element.scrollLeft + parseInt(this.table.columnManager.element.style.marginLeft);
420
+
421
+ if(left !== headerPos){
420
422
  this.table.rowManager.scrollHorizontal(left);
421
423
  this.table.columnManager.scrollHorizontal(left);
422
424
  }
@@ -5,8 +5,9 @@ export default function(cell, formatterParams, onRendered){
5
5
  var blocked = false;
6
6
 
7
7
  checkbox.type = 'checkbox';
8
-
9
8
 
9
+ checkbox.setAttribute("aria-label", "Select Row");
10
+
10
11
  if(this.table.modExists("selectRow", true)){
11
12
 
12
13
  checkbox.addEventListener("click", (e) => {