tabulator-tables 5.0.6 → 5.0.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.0.6",
3
+ "version": "5.0.7",
4
4
  "description": "Interactive table generation JavaScript library",
5
5
  "style": "dist/css/tabulator.css",
6
6
  "main": "dist/js/tabulator.js",
@@ -232,8 +232,9 @@ export default class ColumnManager extends CoreFeature {
232
232
  index = nextToColumn ? this.findColumnIndex(nextToColumn) : nextToColumn;
233
233
 
234
234
  if(nextToColumn && index > -1){
235
- var parentIndex = this.columns.indexOf(nextToColumn.getTopColumn());
236
- var nextEl = nextToColumn.getElement();
235
+ var topColumn = nextToColumn.getTopColumn()
236
+ var parentIndex = this.columns.indexOf(topColumn);
237
+ var nextEl = topColumn.getElement();
237
238
 
238
239
  if(before){
239
240
  this.columns.splice(parentIndex, 0, column);
@@ -608,13 +609,11 @@ export default class ColumnManager extends CoreFeature {
608
609
 
609
610
  this.dispatch("column-add", definition, before, nextToColumn);
610
611
 
611
- this.redraw(true);
612
-
613
612
  if(this.layoutMode() != "fitColumns"){
614
613
  column.reinitializeWidth();
615
614
  }
616
615
 
617
- this.verticalAlignHeaders();
616
+ this.redraw(true);
618
617
 
619
618
  this.table.rowManager.reinitialize();
620
619
 
@@ -409,68 +409,80 @@ class Tabulator {
409
409
 
410
410
  //replace data, keeping table in position with same sort
411
411
  replaceData(data, params, config){
412
- return this.dataLoader.load(data, params, config, true, true);
412
+ if(this.initialized){
413
+ return this.dataLoader.load(data, params, config, true, true);
414
+ }else{
415
+ console.warn("replaceData failed - table not yet initialized. Please wait for the `tableBuilt` event before calling this function.");
416
+ }
413
417
  }
414
418
 
415
419
  //update table data
416
420
  updateData(data){
417
421
  var responses = 0;
418
422
 
419
- return new Promise((resolve, reject) => {
420
- this.dataLoader.blockActiveLoad();
423
+ if(this.initialized){
424
+ return new Promise((resolve, reject) => {
425
+ this.dataLoader.blockActiveLoad();
421
426
 
422
- if(typeof data === "string"){
423
- data = JSON.parse(data);
424
- }
427
+ if(typeof data === "string"){
428
+ data = JSON.parse(data);
429
+ }
425
430
 
426
- if(data){
427
- data.forEach((item) => {
428
- var row = this.rowManager.findRow(item[this.options.index]);
431
+ if(data){
432
+ data.forEach((item) => {
433
+ var row = this.rowManager.findRow(item[this.options.index]);
429
434
 
430
- if(row){
431
- responses++;
435
+ if(row){
436
+ responses++;
432
437
 
433
- row.updateData(item)
434
- .then(()=>{
435
- responses--;
438
+ row.updateData(item)
439
+ .then(()=>{
440
+ responses--;
436
441
 
437
- if(!responses){
438
- resolve();
439
- }
440
- });
441
- }
442
- });
443
- }else{
444
- console.warn("Update Error - No data provided");
445
- reject("Update Error - No data provided");
446
- }
447
- });
442
+ if(!responses){
443
+ resolve();
444
+ }
445
+ });
446
+ }
447
+ });
448
+ }else{
449
+ console.warn("Update Error - No data provided");
450
+ reject("Update Error - No data provided");
451
+ }
452
+ });
453
+ }else{
454
+ console.warn("updateData failed - table not yet initialized. Please wait for the `tableBuilt` event before calling this function.");
455
+ }
448
456
  }
449
457
 
450
458
  addData(data, pos, index){
451
- return new Promise((resolve, reject) => {
452
- this.dataLoader.blockActiveLoad();
459
+ if(this.initialized){
460
+ return new Promise((resolve, reject) => {
461
+ this.dataLoader.blockActiveLoad();
453
462
 
454
- if(typeof data === "string"){
455
- data = JSON.parse(data);
456
- }
463
+ if(typeof data === "string"){
464
+ data = JSON.parse(data);
465
+ }
457
466
 
458
- if(data){
459
- this.rowManager.addRows(data, pos, index)
460
- .then((rows) => {
461
- var output = [];
467
+ if(data){
468
+ this.rowManager.addRows(data, pos, index)
469
+ .then((rows) => {
470
+ var output = [];
462
471
 
463
- rows.forEach(function(row){
464
- output.push(row.getComponent());
465
- });
472
+ rows.forEach(function(row){
473
+ output.push(row.getComponent());
474
+ });
466
475
 
467
- resolve(output);
468
- });
469
- }else{
470
- console.warn("Update Error - No data provided");
471
- reject("Update Error - No data provided");
472
- }
473
- });
476
+ resolve(output);
477
+ });
478
+ }else{
479
+ console.warn("Update Error - No data provided");
480
+ reject("Update Error - No data provided");
481
+ }
482
+ });
483
+ }else{
484
+ console.warn("addData failed - table not yet initialized. Please wait for the `tableBuilt` event before calling this function.");
485
+ }
474
486
  }
475
487
 
476
488
  //update table data
@@ -478,46 +490,50 @@ class Tabulator {
478
490
  var rows = [],
479
491
  responses = 0;
480
492
 
481
- return new Promise((resolve, reject) => {
482
- this.dataLoader.blockActiveLoad();
483
-
484
- if(typeof data === "string"){
485
- data = JSON.parse(data);
486
- }
493
+ if(this.initialized){
494
+ return new Promise((resolve, reject) => {
495
+ this.dataLoader.blockActiveLoad();
487
496
 
488
- if(data){
489
- data.forEach((item) => {
490
- var row = this.rowManager.findRow(item[this.options.index]);
497
+ if(typeof data === "string"){
498
+ data = JSON.parse(data);
499
+ }
491
500
 
492
- responses++;
501
+ if(data){
502
+ data.forEach((item) => {
503
+ var row = this.rowManager.findRow(item[this.options.index]);
493
504
 
494
- if(row){
495
- row.updateData(item)
496
- .then(()=>{
497
- responses--;
498
- rows.push(row.getComponent());
505
+ responses++;
499
506
 
500
- if(!responses){
501
- resolve(rows);
502
- }
503
- });
504
- }else{
505
- this.rowManager.addRows(item)
506
- .then((newRows)=>{
507
- responses--;
508
- rows.push(newRows[0].getComponent());
509
-
510
- if(!responses){
511
- resolve(rows);
512
- }
513
- });
514
- }
515
- });
516
- }else{
517
- console.warn("Update Error - No data provided");
518
- reject("Update Error - No data provided");
519
- }
520
- });
507
+ if(row){
508
+ row.updateData(item)
509
+ .then(()=>{
510
+ responses--;
511
+ rows.push(row.getComponent());
512
+
513
+ if(!responses){
514
+ resolve(rows);
515
+ }
516
+ });
517
+ }else{
518
+ this.rowManager.addRows(item)
519
+ .then((newRows)=>{
520
+ responses--;
521
+ rows.push(newRows[0].getComponent());
522
+
523
+ if(!responses){
524
+ resolve(rows);
525
+ }
526
+ });
527
+ }
528
+ });
529
+ }else{
530
+ console.warn("Update Error - No data provided");
531
+ reject("Update Error - No data provided");
532
+ }
533
+ });
534
+ }else{
535
+ console.warn("updateOrAddData failed - table not yet initialized. Please wait for the `tableBuilt` event before calling this function.");
536
+ }
521
537
  }
522
538
 
523
539
  //get row object
@@ -582,14 +598,18 @@ class Tabulator {
582
598
 
583
599
  //add row to table
584
600
  addRow(data, pos, index){
585
- if(typeof data === "string"){
586
- data = JSON.parse(data);
587
- }
601
+ if(this.initialized){
602
+ if(typeof data === "string"){
603
+ data = JSON.parse(data);
604
+ }
588
605
 
589
- return this.rowManager.addRows(data, pos, index)
590
- .then((rows)=>{
591
- return rows[0].getComponent();
592
- });
606
+ return this.rowManager.addRows(data, pos, index)
607
+ .then((rows)=>{
608
+ return rows[0].getComponent();
609
+ });
610
+ }else{
611
+ console.warn("addRow failed - table not yet initialized. Please wait for the `tableBuilt` event before calling this function.");
612
+ }
593
613
  }
594
614
 
595
615
  //update a row if it exitsts otherwise create it
@@ -655,7 +675,11 @@ class Tabulator {
655
675
  }
656
676
 
657
677
  getRows(active){
658
- return this.rowManager.getComponents(active);
678
+ if(this.initialized){
679
+ return this.rowManager.getComponents(active);
680
+ }else{
681
+ console.warn("getRows failed - table not yet initialized. Please wait for the `tableBuilt` event before calling this function.");
682
+ }
659
683
  }
660
684
 
661
685
  //get position of row in table
@@ -798,8 +822,12 @@ class Tabulator {
798
822
  //////////// General Public Functions ////////////
799
823
  //redraw list without updating data
800
824
  redraw(force){
801
- this.columnManager.redraw(force);
802
- this.rowManager.redraw(force);
825
+ if(this.initialized){
826
+ this.columnManager.redraw(force);
827
+ this.rowManager.redraw(force);
828
+ }else{
829
+ console.warn("redraw failed - table not yet initialized. Please wait for the `tableBuilt` event before calling this function.");
830
+ }
803
831
  }
804
832
 
805
833
  setHeight(height){
@@ -94,7 +94,6 @@ export default class InteractionManager extends CoreFeature {
94
94
  if(!listener.handler){
95
95
  listener.handler = this.track.bind(this, key);
96
96
  this.el.addEventListener(key, listener.handler)
97
- console.log("add", key)
98
97
  // this.el.addEventListener(key, listener.handler, {passive: true})
99
98
  }
100
99
  }else{
@@ -15,6 +15,7 @@ class Filter extends Module{
15
15
  this.prevHeaderFilterChangeCheck = "{}";
16
16
 
17
17
  this.changed = false; //has filtering changed since last render
18
+ this.tableInitialized = false;
18
19
 
19
20
  this.registerTableOption("filterMode", "local"); //local or remote filtering
20
21
 
@@ -82,6 +83,8 @@ class Filter extends Module{
82
83
  }
83
84
  });
84
85
  }
86
+
87
+ this.tableInitialized = true;
85
88
  }
86
89
 
87
90
  remoteFilterParams(data, config, silent, params){
@@ -546,10 +549,12 @@ class Filter extends Module{
546
549
  }
547
550
 
548
551
  refreshFilter(){
549
- if(this.table.options.filterMode === "remote"){
550
- this.reloadData();
551
- }else{
552
- this.refreshData();
552
+ if(this.tableInitialized){
553
+ if(this.table.options.filterMode === "remote"){
554
+ this.reloadData();
555
+ }else{
556
+ this.refreshData();
557
+ }
553
558
  }
554
559
 
555
560
  //TODO - Persist left position of row manager
@@ -99,7 +99,10 @@ class FrozenRows extends Module{
99
99
 
100
100
  if(index > -1){
101
101
  var rowEl = row.getElement();
102
- rowEl.parentNode.removeChild(rowEl);
102
+
103
+ if(rowEl.parentNode){
104
+ rowEl.parentNode.removeChild(rowEl);
105
+ }
103
106
 
104
107
  this.rows.splice(index, 1);
105
108
  }
@@ -45,6 +45,34 @@ class GroupRows extends Module{
45
45
 
46
46
  //initialize group configuration
47
47
  initialize(){
48
+ if(this.table.options.groupBy){
49
+
50
+ this.configureGroupSetup();
51
+
52
+ if(this.table.options.groupUpdateOnCellEdit){
53
+ this.subscribe("cell-value-updated", this.cellUpdated.bind(this));
54
+ this.subscribe("row-data-changed", this.reassignRowToGroup.bind(this), 0);
55
+ }
56
+
57
+ this.subscribe("row-deleting", this.rowDeleting.bind(this));
58
+ this.subscribe("row-deleted", this.rowsUpdated.bind(this));
59
+ this.subscribe("scroll-horizontal", this.scrollHeaders.bind(this));
60
+ this.subscribe("rows-wipe", this.wipe.bind(this));
61
+ this.subscribe("rows-added", this.rowsUpdated.bind(this));
62
+ this.subscribe("row-moving", this.rowMoving.bind(this));
63
+ this.subscribe("row-adding-index", this.rowAddingIndex.bind(this));
64
+
65
+ this.subscribe("rows-sample", this.rowSample.bind(this));
66
+
67
+ this.subscribe("render-virtual-fill", this.virtualRenderFill.bind(this));
68
+
69
+ this.registerDisplayHandler(this.displayHandler, 20);
70
+
71
+ this.initialized = true;
72
+ }
73
+ }
74
+
75
+ configureGroupSetup(){
48
76
  if(this.table.options.groupBy){
49
77
  var groupBy = this.table.options.groupBy,
50
78
  startOpen = this.table.options.groupStartOpen,
@@ -133,27 +161,6 @@ class GroupRows extends Module{
133
161
  if(groupHeader){
134
162
  this.headerGenerator = Array.isArray(groupHeader) ? groupHeader : [groupHeader];
135
163
  }
136
-
137
- if(this.table.options.groupUpdateOnCellEdit){
138
- this.subscribe("cell-value-updated", this.cellUpdated.bind(this));
139
- this.subscribe("row-data-changed", this.reassignRowToGroup.bind(this), 0);
140
- }
141
-
142
- this.subscribe("row-deleting", this.rowDeleting.bind(this));
143
- this.subscribe("row-deleted", this.rowsUpdated.bind(this));
144
- this.subscribe("scroll-horizontal", this.scrollHeaders.bind(this));
145
- this.subscribe("rows-wipe", this.wipe.bind(this));
146
- this.subscribe("rows-added", this.rowsUpdated.bind(this));
147
- this.subscribe("row-moving", this.rowMoving.bind(this));
148
- this.subscribe("row-adding-index", this.rowAddingIndex.bind(this));
149
-
150
- this.subscribe("rows-sample", this.rowSample.bind(this));
151
-
152
- this.subscribe("render-virtual-fill", this.virtualRenderFill.bind(this));
153
-
154
- this.registerDisplayHandler(this.displayHandler, 20);
155
-
156
- this.initialized = true;
157
164
  }
158
165
  }
159
166
 
@@ -218,23 +225,23 @@ class GroupRows extends Module{
218
225
 
219
226
  setGroupBy(groups){
220
227
  this.table.options.groupBy = groups;
221
- this.initialize();
222
- this.refreshData(false, "display");
228
+ this.configureGroupSetup();
229
+ this.refreshData();
223
230
 
224
231
  this.trackChanges();
225
232
  }
226
233
 
227
234
  setGroupValues(groupValues){
228
235
  this.table.options.groupValues = groupValues;
229
- this.initialize();
230
- this.refreshData(false, "display");
236
+ this.configureGroupSetup();
237
+ this.refreshData();
231
238
 
232
239
  this.trackChanges();
233
240
  }
234
241
 
235
242
  setGroupStartOpen(values){
236
243
  this.table.options.groupStartOpen = values;
237
- this.initialize();
244
+ this.configureGroupSetup();
238
245
 
239
246
  if(this.table.options.groupBy){
240
247
  this.refreshData();
@@ -247,7 +254,7 @@ class GroupRows extends Module{
247
254
 
248
255
  setGroupHeader(values){
249
256
  this.table.options.groupHeader = values;
250
- this.initialize();
257
+ this.configureGroupSetup();
251
258
 
252
259
  if(this.table.options.groupBy){
253
260
  this.refreshData();
@@ -328,7 +335,7 @@ class GroupRows extends Module{
328
335
 
329
336
  //return appropriate rows with group headers
330
337
  getRows(rows){
331
- if(this.groupIDLookups.length){
338
+ if(this.table.options.groupBy && this.groupIDLookups.length){
332
339
 
333
340
  this.dispatchExternal("dataGrouping");
334
341
 
@@ -443,7 +450,7 @@ class GroupRows extends Module{
443
450
  var oldGroups = this.groups;
444
451
 
445
452
  this.groups = {};
446
- this.groupList =[];
453
+ this.groupList = [];
447
454
 
448
455
  if(this.allowedValues && this.allowedValues[0]){
449
456
  this.allowedValues[0].forEach((value) => {
@@ -1,4 +1,6 @@
1
1
  import Module from '../../core/Module.js';
2
+ import Row from '../../core/row/Row.js';
3
+ import Cell from '../../core/cell/Cell.js';
2
4
 
3
5
  import defaultUndoers from './defaults/undoers.js';
4
6
  import defaultRedoers from './defaults/redoers.js';
@@ -58,7 +60,7 @@ class History extends Module{
58
60
  }
59
61
  }
60
62
 
61
- this.history.action("rowDelete", row, {data:row.getData(), pos:!index, index:index});
63
+ this.action("rowDelete", row, {data:row.getData(), pos:!index, index:index});
62
64
  }
63
65
 
64
66
  cellUpdated(cell){
@@ -165,7 +165,9 @@ class MoveColumns extends Module{
165
165
  }
166
166
 
167
167
  startMove(e, column){
168
- var element = column.getElement();
168
+ var element = column.getElement(),
169
+ headerElement = this.table.columnManager.getElement(),
170
+ headersElement = this.table.columnManager.getHeadersElement();
169
171
 
170
172
  this.moving = column;
171
173
  this.startX = (this.touchMove ? e.touches[0].pageX : e.pageX) - Helpers.elOffset(element).left;
@@ -186,7 +188,7 @@ class MoveColumns extends Module{
186
188
  this.table.columnManager.getElement().appendChild(this.hoverElement);
187
189
 
188
190
  this.hoverElement.style.left = "0";
189
- this.hoverElement.style.bottom = "0";
191
+ this.hoverElement.style.bottom = (headerElement.clientHeight - headersElement.offsetHeight) + "px";
190
192
 
191
193
  if(!this.touchMove){
192
194
  this._bindMouseMove();
@@ -224,7 +226,7 @@ class MoveColumns extends Module{
224
226
  column.getCells().forEach(function(cell, i){
225
227
  var cellEl = cell.getElement(true);
226
228
 
227
- if(cellEl.parentNode){
229
+ if(cellEl.parentNode && movingCells[i]){
228
230
  cellEl.parentNode.insertBefore(movingCells[i].getElement(), cellEl.nextSibling);
229
231
  }
230
232
  });
@@ -232,7 +234,7 @@ class MoveColumns extends Module{
232
234
  column.getCells().forEach(function(cell, i){
233
235
  var cellEl = cell.getElement(true);
234
236
 
235
- if(cellEl.parentNode){
237
+ if(cellEl.parentNode && movingCells[i]){
236
238
  cellEl.parentNode.insertBefore(movingCells[i].getElement(), cellEl);
237
239
  }
238
240
  });
@@ -35,7 +35,7 @@ class SelectRow extends Module{
35
35
  this.subscribe("row-init", this.initializeRow.bind(this));
36
36
  this.subscribe("row-deleting", this.rowDeleted.bind(this));
37
37
  this.subscribe("rows-wipe", this.clearSelectionData.bind(this));
38
- this.subscribe("rows-retrieve", this.clearSelectionData.bind(this));
38
+ this.subscribe("rows-retrieve", this.rowRetrieve.bind(this));
39
39
 
40
40
  if(this.table.options.selectable && this.table.options.selectablePersistence){
41
41
  this.subscribe("data-refeshing", this.deselectRows.bind(this));
@@ -51,7 +51,6 @@ class SelectRow extends Module{
51
51
  this._deselectRow(row, true);
52
52
  }
53
53
 
54
-
55
54
  clearSelectionData(silent){
56
55
  this.selecting = false;
57
56
  this.lastClickedRow = false;