tabulator-tables 5.1.5 → 5.1.8

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.8",
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,19 @@ 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", this.clearVisRowCache.bind(this));
80
+ this.subscribe("data-refreshed", this.clearVisRowCache.bind(this));
81
+ }
82
+
83
+ clearVisRowCache(){
84
+ this.visibleRows = null;
85
+ }
75
86
 
76
87
  //////////////////////////////////////
77
88
  ///////// Public Functions ///////////
@@ -80,6 +91,7 @@ export default class VirtualDomHorizontal extends Renderer{
80
91
  renderColumns(row, force){
81
92
  this.dataChange();
82
93
  }
94
+
83
95
 
84
96
  scrollColumns(left, dir){
85
97
  if(this.scrollLeft != left){
@@ -88,20 +100,20 @@ export default class VirtualDomHorizontal extends Renderer{
88
100
  this.scroll(left - (this.vDomScrollPosLeft + this.windowBuffer));
89
101
  }
90
102
  }
91
-
103
+
92
104
  calcWindowBuffer(){
93
105
  var buffer = this.elementVertical.clientWidth;
94
-
106
+
95
107
  this.table.columnManager.columnsByIndex.forEach((column) => {
96
108
  if(column.visible){
97
109
  var width = column.getWidth();
98
-
110
+
99
111
  if(width > buffer){
100
112
  buffer = width;
101
113
  }
102
114
  }
103
115
  });
104
-
116
+
105
117
  this.windowBuffer = buffer * 2;
106
118
  }
107
119
 
@@ -119,20 +131,20 @@ export default class VirtualDomHorizontal extends Renderer{
119
131
  }
120
132
 
121
133
  this.clear();
122
-
134
+
123
135
  this.calcWindowBuffer();
124
136
 
125
137
  this.scrollLeft = this.elementVertical.scrollLeft;
126
138
 
127
139
  this.vDomScrollPosLeft = this.scrollLeft - this.windowBuffer;
128
140
  this.vDomScrollPosRight = this.scrollLeft + this.elementVertical.clientWidth + this.windowBuffer;
129
-
141
+
130
142
  this.table.columnManager.columnsByIndex.forEach((column) => {
131
143
  var config = {};
132
144
 
133
145
  if(column.visible){
134
146
  var width = column.getWidth();
135
-
147
+
136
148
  config.leftPos = colPos;
137
149
  config.rightPos = colPos + width;
138
150
 
@@ -259,18 +271,18 @@ export default class VirtualDomHorizontal extends Renderer{
259
271
 
260
272
  collsWidth += cell.column.getWidth();
261
273
 
262
- if(collsWidth > this.vDomScrollPosRight){
263
- break;
264
- }
274
+ // if(collsWidth > this.vDomScrollPosRight){
275
+ // break;
276
+ // }
265
277
  }
266
278
 
267
279
  rowEl.parentNode.removeChild(rowEl);
268
280
 
269
- this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
281
+ // this.fitDataColAvg = Math.floor(collsWidth / (colEnd + 1));
270
282
 
271
- for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
272
- this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
273
- }
283
+ // for(colEnd; colEnd < this.table.columnManager.columnsByIndex.length; colEnd++){
284
+ // this.table.columnManager.columnsByIndex[colEnd].setWidth(this.fitDataColAvg);
285
+ // }
274
286
 
275
287
  this.rerenderColumns(false, true);
276
288
  }
@@ -301,17 +313,25 @@ export default class VirtualDomHorizontal extends Renderer{
301
313
  }
302
314
 
303
315
  reinitializeRows(){
304
- var rows = this.table.rowManager.getVisibleRows();
316
+ var rows = this.getVisibleRows();
305
317
  rows.forEach((row) => {
306
318
  this.reinitializeRow(row, true);
307
319
  });
308
320
  }
309
321
 
322
+ getVisibleRows(){
323
+ if (!this.visibleRows){
324
+ this.visibleRows = this.table.rowManager.getVisibleRows();
325
+ }
326
+
327
+ return this.visibleRows;
328
+ }
329
+
310
330
  scroll(diff){
311
331
  this.vDomScrollPosLeft += diff;
312
332
  this.vDomScrollPosRight += diff;
313
-
314
- if(diff > (this.elementVertical.clientWidth * .8)){
333
+
334
+ if(Math.abs(diff) > (this.windowBuffer / 2)){
315
335
  this.rerenderColumns();
316
336
  }else{
317
337
  if(diff > 0){
@@ -336,131 +356,165 @@ export default class VirtualDomHorizontal extends Renderer{
336
356
  }
337
357
 
338
358
  addColRight(){
339
- var column = this.columns[this.rightCol + 1],
340
- rows, newWidth, widthDiff;
359
+ var changes = false;
341
360
 
342
- if(column && column.modules.vdomHoz.leftPos <= this.vDomScrollPosRight){
343
- rows = this.table.rowManager.getVisibleRows();
361
+ while(true){
344
362
 
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
- });
352
-
353
- this.fitDataColActualWidthCheck(column);
354
-
355
- this.rightCol++; // Don't move this below the >= check below
363
+ let column = this.columns[this.rightCol + 1];
356
364
 
357
- if(this.rightCol >= (this.columns.length - 1)){
358
- 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
+ }
359
389
  }else{
360
- this.vDomPadRight -= column.getWidth();
390
+ break;
361
391
  }
362
-
392
+ }
393
+
394
+ if(changes){
363
395
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
364
-
365
- this.addColRight();
366
396
  }
367
397
  }
368
398
 
369
399
  addColLeft(){
370
- var column = this.columns[this.leftCol - 1],
371
- rows;
400
+ var changes = false;
372
401
 
373
- if(column && column.modules.vdomHoz.rightPos >= this.vDomScrollPosLeft){
374
- var rows = this.table.rowManager.getVisibleRows();
402
+ while(true){
403
+ let column = this.columns[this.leftCol - 1];
375
404
 
376
- rows.forEach((row) => {
377
- if(row.type !== "group"){
378
- var cell = row.getCell(column);
379
- row.getElement().prepend(cell.getElement());
380
- 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;
381
434
  }
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
435
  }else{
391
- this.vDomPadLeft -= column.getWidth();
436
+ break;
392
437
  }
393
-
438
+ }
439
+
440
+ if(changes){
394
441
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
395
-
396
-
397
- this.addColLeft();
398
442
  }
399
443
  }
400
444
 
401
- removeColRight(column){
402
- var column = this.columns[this.rightCol],
403
- rows;
445
+ removeColRight(){
446
+ var changes = false;
404
447
 
405
- if(column && column.modules.vdomHoz.leftPos > this.vDomScrollPosRight){
406
- rows = this.table.rowManager.getVisibleRows();
448
+ while(true){
449
+ let column = this.columns[this.rightCol];
407
450
 
408
- column.modules.vdomHoz.visible = false;
409
-
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
- }
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;
418
471
  }
419
- });
420
-
421
- this.vDomPadRight += column.getWidth();
472
+ }else{
473
+ break;
474
+ }
475
+ }
476
+
477
+ if(changes){
422
478
  this.tableElement.style.paddingRight = this.vDomPadRight + "px";
423
-
424
- this.rightCol --;
425
-
426
- this.removeColRight();
427
479
  }
428
480
  }
429
481
 
430
482
  removeColLeft(){
431
- var column = this.columns[this.leftCol],
432
- rows;
483
+ var changes = false;
433
484
 
434
- if(column && column.modules.vdomHoz.rightPos < this.vDomScrollPosLeft){
435
- rows = this.table.rowManager.getVisibleRows();
485
+ while(true){
486
+ let column = this.columns[this.leftCol];
436
487
 
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){
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
+
447
496
  try {
448
- row.getElement().removeChild(el);
497
+ row.getElement().removeChild(cell.getElement());
449
498
  } catch (ex) {
450
499
  console.warn("Could not removeColLeft", ex.message)
451
500
  }
452
501
  }
453
- }
502
+ });
503
+
504
+ this.vDomPadLeft += column.getWidth();
505
+ this.leftCol ++;
506
+ }else{
507
+ break;
454
508
  }
455
- });
456
-
457
- this.vDomPadLeft += column.getWidth();
509
+ }else{
510
+ break;
511
+ }
512
+ }
513
+
514
+ if(changes){
458
515
  this.tableElement.style.paddingLeft = this.vDomPadLeft + "px";
459
-
460
- this.leftCol ++;
461
-
462
- this.removeColLeft();
463
516
  }
517
+
464
518
  }
465
519
 
466
520
  fitDataColActualWidthCheck(column){
@@ -475,12 +529,14 @@ export default class VirtualDomHorizontal extends Renderer{
475
529
  if(widthDiff){
476
530
  column.modules.vdomHoz.rightPos += widthDiff;
477
531
  column.modules.vdomHoz.width = newWidth;
478
- this.colPositionAdjust(this.rightCol + 2, this.columns.length, widthDiff);
532
+ this.colPositionAdjust(this.columns.indexOf(column) + 1, this.columns.length, widthDiff);
479
533
  }
480
534
 
481
535
  column.modules.vdomHoz.fitDataCheck = false;
482
536
  }
483
- };
537
+
538
+ return widthDiff;
539
+ }
484
540
 
485
541
  initializeRow(row){
486
542
  if(row.type !== "group"){
@@ -12,14 +12,14 @@ export default class ComponentFunctionBinder{
12
12
  }
13
13
 
14
14
  if(this.bindings[type][funcName]){
15
- console.warn("Unable to bind component handler, a matching function name is already bound", type, funcName, hanlder)
15
+ console.warn("Unable to bind component handler, a matching function name is already bound", type, funcName, handler)
16
16
  }else{
17
17
  this.bindings[type][funcName] = handler;
18
18
  }
19
19
  }
20
20
 
21
21
  handle(type, component, name){
22
- if(this.bindings[type] && this.bindings[type][name]){
22
+ if(this.bindings[type] && this.bindings[type][name] && typeof this.bindings[type][name].bind === 'function'){
23
23
  return this.bindings[type][name].bind(null, component);
24
24
  }else{
25
25
  if(name !== "then" && typeof name === "string" && !name.startsWith("_")){
@@ -27,4 +27,4 @@ export default class ComponentFunctionBinder{
27
27
  }
28
28
  }
29
29
  }
30
- }
30
+ }
@@ -638,6 +638,7 @@ class Edit extends Module{
638
638
  cell.column.definition.cellEditing.call(this.table, component);
639
639
  }
640
640
 
641
+ this.dispatch("cell-editing", cell);
641
642
  this.dispatchExternal("cellEditing", component);
642
643
 
643
644
  params = typeof cell.column.modules.edit.params === "function" ? cell.column.modules.edit.params(component) : cell.column.modules.edit.params;
@@ -480,6 +480,7 @@ export default function(cell, onRendered, success, cancel, editorParams){
480
480
  if(!input.value){
481
481
  unsetItems();
482
482
  chooseItems();
483
+ showList();
483
484
  }
484
485
  });
485
486
 
@@ -9,14 +9,12 @@ export default function(cell, formatterParams, onRendered){
9
9
  var newDatetime = inputFormat === "iso" ? DT.fromISO(String(value)) : DT.fromFormat(String(value), inputFormat);
10
10
 
11
11
  if(newDatetime.isValid){
12
-
13
12
  if(formatterParams.timezone){
14
- newDatetime = newDatetime.shiftTimezone(formatterParams.timezone);
13
+ newDatetime = newDatetime.setZone(formatterParams.timezone);
15
14
  }
16
15
 
17
16
  return newDatetime.toFormat(outputFormat);
18
17
  }else{
19
-
20
18
  if(invalid === true || !value){
21
19
  return value;
22
20
  }else if(typeof invalid === "function"){
@@ -313,6 +313,7 @@ class Menu extends Module{
313
313
 
314
314
  setTimeout(() => {
315
315
  this.table.rowManager.element.addEventListener("scroll", this.blurEvent);
316
+ this.subscribe("cell-editing", this.blurEvent);
316
317
  document.body.addEventListener("click", this.blurEvent);
317
318
  document.body.addEventListener("contextmenu", this.blurEvent);
318
319
  window.addEventListener("resize", this.blurEvent);
@@ -335,13 +336,11 @@ class Menu extends Module{
335
336
  }
336
337
 
337
338
  //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
-
339
+ if((y + element.offsetHeight) > this.menuContainer.offsetHeight) {
341
340
  if(parentEl){
342
- element.style.bottom = (this.menuContainer.offsetHeight - parentOffset.top - parentEl.offsetHeight - 1) + "px";
341
+ element.style.top = (parseInt(element.style.top) - element.offsetHeight + parentEl.offsetHeight + 1) + "px";
343
342
  }else{
344
- element.style.bottom = (this.menuContainer.offsetHeight - y) + "px";
343
+ element.style.top = (parseInt(element.style.top) - element.offsetHeight) + "px";
345
344
  }
346
345
  }
347
346
  }
@@ -368,6 +367,7 @@ class Menu extends Module{
368
367
  document.body.removeEventListener("contextmenu", this.blurEvent);
369
368
  window.removeEventListener("resize", this.blurEvent);
370
369
  this.table.rowManager.element.removeEventListener("scroll", this.blurEvent);
370
+ this.unsubscribe("cell-editing", this.blurEvent);
371
371
 
372
372
  if(this.currentComponent){
373
373
  this.dispatchExternal("menuClosed", this.currentComponent.getComponent());
@@ -378,4 +378,4 @@ class Menu extends Module{
378
378
 
379
379
  Menu.moduleName = "menu";
380
380
 
381
- export default Menu;
381
+ export default Menu;