tabulator-tables 5.1.2 → 5.1.5

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.
@@ -1,10 +1,10 @@
1
1
  import Module from '../../core/Module.js';
2
2
 
3
3
  class FrozenColumns extends Module{
4
-
4
+
5
5
  constructor(table){
6
6
  super(table);
7
-
7
+
8
8
  this.leftColumns = [];
9
9
  this.rightColumns = [];
10
10
  this.leftMargin = 0;
@@ -13,10 +13,11 @@ class FrozenColumns extends Module{
13
13
  this.initializationMode = "left";
14
14
  this.active = false;
15
15
  this.scrollEndTimer = false;
16
-
16
+ this.blocked = true;
17
+
17
18
  this.registerColumnOption("frozen");
18
19
  }
19
-
20
+
20
21
  //reset initial state
21
22
  reset(){
22
23
  this.initializationMode = "left";
@@ -26,11 +27,11 @@ class FrozenColumns extends Module{
26
27
  this.rightMargin = 0;
27
28
  this.rightMargin = 0;
28
29
  this.active = false;
29
-
30
+
30
31
  this.table.columnManager.headersElement.style.marginLeft = 0;
31
32
  this.table.columnManager.element.style.paddingRight = 0;
32
33
  }
33
-
34
+
34
35
  initialize(){
35
36
  this.subscribe("cell-layout", this.layoutCell.bind(this));
36
37
  this.subscribe("column-init", this.initializeColumn.bind(this));
@@ -40,179 +41,197 @@ class FrozenColumns extends Module{
40
41
  this.subscribe("scroll-horizontal", this.scrollHorizontal.bind(this));
41
42
  this.subscribe("columns-loading", this.reset.bind(this));
42
43
  this.subscribe("table-redraw", this.layout.bind(this));
44
+ this.subscribe("layout-refreshing", this.blockLayout.bind(this));
45
+ this.subscribe("layout-refreshed", this.unblockLayout.bind(this));
43
46
  }
44
-
47
+
48
+ blockLayout(){
49
+ this.blocked = true;
50
+ }
51
+
52
+ unblockLayout(){
53
+ this.blocked = false;
54
+ }
55
+
45
56
  layoutCell(cell){
46
57
  this.layoutElement(cell.element, cell.column)
47
58
  }
48
-
59
+
49
60
  //initialize specific column
50
61
  initializeColumn(column){
51
62
  var config = {margin:0, edge:false};
52
-
63
+
53
64
  if(!column.isGroup){
54
-
65
+
55
66
  if(this.frozenCheck(column)){
56
-
67
+
57
68
  config.position = this.initializationMode;
58
-
69
+
59
70
  if(this.initializationMode == "left"){
60
71
  this.leftColumns.push(column);
61
72
  }else{
62
73
  this.rightColumns.unshift(column);
63
74
  }
64
-
75
+
65
76
  this.active = true;
66
-
77
+
67
78
  column.modules.frozen = config;
68
79
  }else{
69
80
  this.initializationMode = "right";
70
81
  }
71
82
  }
72
83
  }
73
-
84
+
74
85
  frozenCheck(column){
75
86
  var frozen = false;
76
-
87
+
77
88
  if(column.parent.isGroup && column.definition.frozen){
78
89
  console.warn("Frozen Column Error - Parent column group must be frozen, not individual columns or sub column groups");
79
90
  }
80
-
91
+
81
92
  if(column.parent.isGroup){
82
93
  return this.frozenCheck(column.parent);
83
94
  }else{
84
95
  return column.definition.frozen;
85
96
  }
86
-
97
+
87
98
  return frozen;
88
99
  }
89
-
100
+
90
101
  //quick layout to smooth horizontal scrolling
91
102
  scrollHorizontal(){
92
103
  var rows;
93
-
104
+
94
105
  if(this.active){
95
106
  clearTimeout(this.scrollEndTimer);
96
107
 
97
- //layout all rows after scroll is complete
98
- this.scrollEndTimer = setTimeout(() => {
99
- this.layout();
100
- }, 100);
101
-
102
108
  rows = this.table.rowManager.getVisibleRows();
103
-
104
- this.calcMargins();
105
-
109
+
110
+ this.calcMargins(true);
111
+
106
112
  this.layoutColumnPosition();
107
-
113
+
108
114
  this.layoutCalcRows();
109
-
115
+
110
116
  rows.forEach((row) => {
111
117
  if(row.type === "row"){
112
118
  this.layoutRow(row);
113
119
  }
114
120
  });
115
-
116
- this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
117
121
  }
118
122
  }
119
-
123
+
120
124
  //calculate margins for rows
121
- calcMargins(){
122
- this.leftMargin = this._calcSpace(this.leftColumns, this.leftColumns.length) + "px";
123
- this.table.columnManager.headersElement.style.marginLeft = this.leftMargin;
124
-
125
- this.rightMargin = this._calcSpace(this.rightColumns, this.rightColumns.length) + "px";
126
- this.table.columnManager.element.style.paddingRight = this.rightMargin;
127
-
125
+ calcMargins(scroll){
126
+
127
+ if(!scroll){
128
+ this.leftMargin = this._calcSpace(this.leftColumns, this.leftColumns.length) + "px";
129
+ this.rightMargin = this._calcSpace(this.rightColumns, this.rightColumns.length) + "px";
130
+ this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
131
+ }
132
+
128
133
  //calculate right frozen columns
129
134
  this.rightPadding = this.table.rowManager.element.clientWidth + this.table.columnManager.scrollLeft;
130
135
  }
131
-
136
+
132
137
  //layout calculation rows
133
138
  layoutCalcRows(){
134
139
  if(this.table.modExists("columnCalcs")){
135
140
  if(this.table.modules.columnCalcs.topInitialized && this.table.modules.columnCalcs.topRow){
136
141
  this.layoutRow(this.table.modules.columnCalcs.topRow);
137
142
  }
138
-
143
+
139
144
  if(this.table.modules.columnCalcs.botInitialized && this.table.modules.columnCalcs.botRow){
140
145
  this.layoutRow(this.table.modules.columnCalcs.botRow);
141
146
  }
142
-
147
+
143
148
  if(this.table.modExists("groupRows")){
144
149
  this.layoutGroupCalcs(this.table.modules.groupRows.getGroups())
145
150
  }
146
151
  }
147
152
  }
148
-
153
+
149
154
  layoutGroupCalcs(groups){
150
155
  groups.forEach((group) => {
151
156
  if(group.calcs.top){
152
157
  this.layoutRow(group.calcs.top);
153
158
  }
154
-
159
+
155
160
  if(group.calcs.bottom){
156
161
  this.layoutRow(group.calcs.bottom);
157
162
  }
158
-
163
+
159
164
  if(group.groupList && group.groupList.length){
160
165
  this.layoutGroupCalcs(group.groupList && group.groupList);
161
166
  }
162
167
  });
163
168
  }
164
-
169
+
165
170
  //calculate column positions and layout headers
166
171
  layoutColumnPosition(allCells){
167
-
168
172
  var leftParents = [];
173
+
174
+ var leftMargin = 0;
175
+ var rightMargin = 0;
176
+
177
+ this.table.columnManager.headersElement.style.marginLeft = this.leftMargin;
178
+ this.table.columnManager.element.style.paddingRight = this.rightMargin;
169
179
 
170
- this.leftColumns.forEach((column, i) => {
171
- column.modules.frozen.margin = (this._calcSpace(this.leftColumns, i) + this.table.columnManager.scrollLeft) + "px";
180
+ this.leftColumns.forEach((column, i) => {
181
+ column.modules.frozen.margin = (leftMargin + this.table.columnManager.scrollLeft) + "px";
172
182
 
183
+ if(column.visible){
184
+ leftMargin += column.getWidth();
185
+ }
186
+
173
187
  if(i == this.leftColumns.length - 1){
174
188
  column.modules.frozen.edge = true;
175
189
  }else{
176
190
  column.modules.frozen.edge = false;
177
191
  }
178
-
192
+
179
193
  if(column.parent.isGroup){
180
194
  var parentEl = this.getColGroupParentElement(column);
181
195
  if(!leftParents.includes(parentEl)){
182
196
  this.layoutElement(parentEl, column);
183
197
  leftParents.push(parentEl);
184
198
  }
185
-
199
+
186
200
  if(column.modules.frozen.edge){
187
201
  parentEl.classList.add("tabulator-frozen-" + column.modules.frozen.position);
188
202
  }
189
203
  }else{
190
204
  this.layoutElement(column.getElement(), column);
191
205
  }
192
-
206
+
193
207
  if(allCells){
194
208
  column.cells.forEach((cell) => {
195
209
  this.layoutElement(cell.getElement(true), column);
196
210
  });
197
211
  }
198
212
  });
199
-
213
+
200
214
  this.rightColumns.forEach((column, i) => {
201
- column.modules.frozen.margin = (this.rightPadding - this._calcSpace(this.rightColumns, i + 1)) + "px";
202
215
 
216
+ if(column.visible){
217
+ rightMargin += column.getWidth();
218
+ }
219
+
220
+ column.modules.frozen.margin = (this.rightPadding - rightMargin) + "px";
221
+
203
222
  if(i == this.rightColumns.length - 1){
204
223
  column.modules.frozen.edge = true;
205
224
  }else{
206
225
  column.modules.frozen.edge = false;
207
226
  }
208
-
209
-
227
+
228
+
210
229
  if(column.parent.isGroup){
211
230
  this.layoutElement(this.getColGroupParentElement(column), column);
212
231
  }else{
213
232
  this.layoutElement(column.getElement(), column);
214
233
  }
215
-
234
+
216
235
  if(allCells){
217
236
  column.cells.forEach((cell) => {
218
237
  this.layoutElement(cell.getElement(true), column);
@@ -220,80 +239,79 @@ class FrozenColumns extends Module{
220
239
  }
221
240
  });
222
241
  }
223
-
242
+
224
243
  getColGroupParentElement(column){
225
244
  return column.parent.isGroup ? this.getColGroupParentElement(column.parent) : column.getElement();
226
245
  }
227
-
228
- //layout columns appropropriatly
246
+
247
+ //layout columns appropriately
229
248
  layout(){
230
- var rightMargin = 0;
231
-
232
- if(this.active){
233
-
249
+ if(this.active && !this.blocked){
234
250
  //calculate row padding
235
251
  this.calcMargins();
236
-
252
+
237
253
  this.table.rowManager.getDisplayRows().forEach((row) =>{
238
254
  if(row.type === "row"){
239
255
  this.layoutRow(row);
240
256
  }
241
257
  });
242
-
258
+
243
259
  this.layoutCalcRows();
244
-
260
+
245
261
  //calculate left columns
246
262
  this.layoutColumnPosition(true);
247
-
248
- this.table.rowManager.tableElement.style.marginRight = this.rightMargin;
249
263
  }
250
264
  }
251
-
265
+
252
266
  layoutRow(row){
253
267
  var rowEl = row.getElement();
254
-
268
+
255
269
  rowEl.style.paddingLeft = this.leftMargin;
256
-
270
+
271
+ if(this.table.options.layout === "fitDataFill" && this.rightColumns.length){
272
+ this.table.rowManager.getTableElement().style.minWidth = "calc(100% - " + this.rightMargin + ")";
273
+ }
274
+
257
275
  this.leftColumns.forEach((column) => {
258
276
  var cell = row.getCell(column);
259
-
277
+
260
278
  if(cell){
261
279
  this.layoutElement(cell.getElement(true), column);
262
280
  }
263
281
  });
264
-
282
+
265
283
  this.rightColumns.forEach((column) => {
266
284
  var cell = row.getCell(column);
267
-
285
+
268
286
  if(cell){
269
287
  this.layoutElement(cell.getElement(true), column);
270
288
  }
271
289
  });
272
290
  }
273
-
291
+
274
292
  layoutElement(element, column){
275
-
293
+
276
294
  if(column.modules.frozen){
277
295
  element.style.position = "absolute";
278
296
  element.style.left = column.modules.frozen.margin;
279
-
297
+
280
298
  element.classList.add("tabulator-frozen");
281
-
299
+
282
300
  if(column.modules.frozen.edge){
283
301
  element.classList.add("tabulator-frozen-" + column.modules.frozen.position);
284
302
  }
285
303
  }
286
304
  }
287
-
305
+
288
306
  _calcSpace(columns, index){
289
307
  var width = 0;
290
-
308
+
291
309
  for (let i = 0; i < index; i++){
292
310
  if(columns[i].visible){
293
311
  width += columns[i].getWidth();
294
312
  }
295
313
  }
296
-
314
+
297
315
  return width;
298
316
  }
299
317
  }