@refinitiv-ui/efx-grid 6.0.103 → 6.0.105
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/lib/core/dist/core.js +14 -137
- package/lib/core/dist/core.min.js +1 -1
- package/lib/core/es6/data/DataCache.d.ts +0 -8
- package/lib/core/es6/data/DataCache.js +13 -136
- package/lib/core/es6/grid/Core.js +1 -1
- package/lib/grid/index.js +1 -1
- package/lib/rt-grid/dist/rt-grid.js +356 -734
- package/lib/rt-grid/dist/rt-grid.min.js +1 -1
- package/lib/rt-grid/es6/FieldDefinition.js +4 -4
- package/lib/rt-grid/es6/Grid.d.ts +1 -1
- package/lib/rt-grid/es6/Grid.js +8 -49
- package/lib/rt-grid/es6/RowDefinition.d.ts +5 -3
- package/lib/rt-grid/es6/RowDefinition.js +49 -20
- package/lib/tr-grid-column-fitter/es6/ColumnFitter.js +523 -708
- package/lib/tr-grid-column-resizing/es6/ColumnResizing.d.ts +16 -16
- package/lib/tr-grid-column-resizing/es6/ColumnResizing.js +131 -109
- package/lib/types/es6/ColumnResizing.d.ts +16 -16
- package/lib/types/es6/Core/data/DataCache.d.ts +0 -8
- package/lib/types/es6/RealtimeGrid/FieldDefinition.d.ts +1 -1
- package/lib/types/es6/RealtimeGrid/Grid.d.ts +1 -1
- package/lib/types/es6/RealtimeGrid/RowDefinition.d.ts +5 -3
- package/lib/versions.json +2 -2
- package/package.json +3 -2
@@ -1,5 +1,6 @@
|
|
1
1
|
import { Ext } from '../../tr-grid-util/es6/Ext.js';
|
2
2
|
import { GridPlugin } from '../../tr-grid-util/es6/GridPlugin.js';
|
3
|
+
|
3
4
|
/** @typedef {Object} ColumnFitterPlugin~Options
|
4
5
|
* @description The options can be specified by `columnFitting` property of the main grid's options
|
5
6
|
* @property {boolean=} proportion=false Proportionally expand columns, if there is enough space
|
@@ -23,392 +24,331 @@ import { GridPlugin } from '../../tr-grid-util/es6/GridPlugin.js';
|
|
23
24
|
* @param {ColumnFitterPlugin~Options=} options
|
24
25
|
* @extends {GridPlugin}
|
25
26
|
*/
|
27
|
+
let ColumnFitterPlugin = function (options) {
|
28
|
+
this._onItemResizeThisColumnClicked = this._onItemResizeThisColumnClicked.bind(this);
|
29
|
+
this._onItemResizeAllColumnClicked = this._onItemResizeAllColumnClicked.bind(this);
|
30
|
+
this._onPostSectionDataBinding = this._onPostSectionDataBinding.bind(this);
|
31
|
+
this._onColumnAdded = this._onColumnAdded.bind(this);
|
32
|
+
this._onTimeout = this._onTimeout.bind(this);
|
26
33
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
this._onPostSectionDataBinding = this._onPostSectionDataBinding.bind(this);
|
31
|
-
this._onColumnAdded = this._onColumnAdded.bind(this);
|
32
|
-
this._onTimeout = this._onTimeout.bind(this);
|
33
|
-
this._hosts = [];
|
34
|
-
this._dummyCells = [];
|
35
|
-
this._cellPaddings = [];
|
36
|
-
this.config(options);
|
37
|
-
};
|
34
|
+
this._hosts = [];
|
35
|
+
this._dummyCells = [];
|
36
|
+
this._cellPaddings = [];
|
38
37
|
|
38
|
+
this.config(options);
|
39
|
+
};
|
39
40
|
Ext.inherits(ColumnFitterPlugin, GridPlugin);
|
41
|
+
|
40
42
|
/** @type {number}
|
41
43
|
* @private
|
42
44
|
*/
|
43
|
-
|
44
45
|
ColumnFitterPlugin.prototype._paddingSize = 2;
|
45
46
|
/** @type {boolean}
|
46
47
|
* @private
|
47
48
|
*/
|
48
|
-
|
49
49
|
ColumnFitterPlugin.prototype._defaultPadding = true;
|
50
50
|
/** @type {boolean}
|
51
51
|
* @private
|
52
52
|
*/
|
53
|
-
|
54
53
|
ColumnFitterPlugin.prototype._autoAdjust = false;
|
55
54
|
/** @type {boolean}
|
56
55
|
* @private
|
57
56
|
*/
|
58
|
-
|
59
57
|
ColumnFitterPlugin.prototype._constraint = false;
|
60
58
|
/** @type {boolean}
|
61
59
|
* @private
|
62
60
|
*/
|
63
|
-
|
64
61
|
ColumnFitterPlugin.prototype._proportion = false;
|
65
62
|
/** If true, include title sections into the calculation
|
66
63
|
* @type {boolean}
|
67
64
|
* @private
|
68
65
|
*/
|
69
|
-
|
70
66
|
ColumnFitterPlugin.prototype._title = false;
|
71
67
|
/** Column can be shrunken after initial fitting
|
72
68
|
* @type {boolean}
|
73
69
|
* @private
|
74
70
|
*/
|
75
|
-
|
76
71
|
ColumnFitterPlugin.prototype._shrinkable = false;
|
72
|
+
|
77
73
|
/** @type {number}
|
78
74
|
* @private
|
79
75
|
*/
|
80
|
-
|
81
76
|
ColumnFitterPlugin.prototype._interval = 300;
|
82
77
|
/** @type {number}
|
83
78
|
* @private
|
84
79
|
*/
|
85
|
-
|
86
80
|
ColumnFitterPlugin.prototype._timerId = 0;
|
87
81
|
/** @type {Array.<Element>}
|
88
82
|
* @private
|
89
83
|
*/
|
90
|
-
|
91
84
|
ColumnFitterPlugin.prototype._dummyCells = null;
|
92
85
|
/** @type {Array.<number>}
|
93
86
|
* @private
|
94
87
|
*/
|
95
|
-
|
96
88
|
ColumnFitterPlugin.prototype._cellPaddings = null;
|
97
89
|
/** @type {number}
|
98
90
|
* @private
|
99
91
|
*/
|
100
|
-
|
101
92
|
ColumnFitterPlugin.prototype._synchronousRendering = true;
|
93
|
+
|
94
|
+
|
102
95
|
/** @public
|
103
96
|
* @return {string}
|
104
97
|
*/
|
105
|
-
|
106
98
|
ColumnFitterPlugin.prototype.getName = function () {
|
107
|
-
|
99
|
+
return "ColumnFitterPlugin"; // Read Only
|
108
100
|
};
|
101
|
+
|
109
102
|
/**
|
110
103
|
* @override
|
111
104
|
* @return {boolean}
|
112
105
|
*/
|
113
|
-
|
114
|
-
|
115
106
|
ColumnFitterPlugin.prototype.hasMultiTableSupport = function () {
|
116
|
-
|
107
|
+
return true;
|
117
108
|
};
|
109
|
+
|
118
110
|
/** @public
|
119
111
|
* @param {Object} host core grid object
|
120
112
|
* @param {Object=} options
|
121
113
|
*/
|
122
|
-
|
123
|
-
|
124
114
|
ColumnFitterPlugin.prototype.initialize = function (host, options) {
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
if (this._autoAdjust) {
|
143
|
-
host.listen("postSectionDataBinding", this._onPostSectionDataBinding);
|
144
|
-
}
|
145
|
-
|
146
|
-
host.listen("columnAdded", this._onColumnAdded); // In case of lazy loading
|
147
|
-
|
148
|
-
this._onPostSectionDataBinding();
|
115
|
+
if (this._hosts.indexOf(host) >= 0) { return; }
|
116
|
+
|
117
|
+
// In case of multi-grid, grace period will be used multiple times because extension is a single instance.
|
118
|
+
this._synchronousRendering = true;
|
119
|
+
this._hosts.push(host);
|
120
|
+
|
121
|
+
if (options) {
|
122
|
+
let pluginOptions = options["columnFitting"] || {}; // Avoid using properties from the main object
|
123
|
+
pluginOptions.columns = options["columns"]; // Retrieved property defined in the column
|
124
|
+
this.config(pluginOptions);
|
125
|
+
}
|
126
|
+
if (this._autoAdjust) {
|
127
|
+
host.listen("postSectionDataBinding", this._onPostSectionDataBinding);
|
128
|
+
}
|
129
|
+
host.listen("columnAdded", this._onColumnAdded);
|
130
|
+
// In case of lazy loading
|
131
|
+
this._onPostSectionDataBinding();
|
149
132
|
};
|
150
133
|
/** @public
|
151
134
|
* @param {Object} host core grid object
|
152
135
|
*/
|
153
|
-
|
154
|
-
|
155
136
|
ColumnFitterPlugin.prototype.unload = function (host) {
|
156
|
-
|
137
|
+
let at = this._hosts.indexOf(host);
|
138
|
+
if (at < 0) { return; }
|
139
|
+
this._hosts.splice(at, 1);
|
157
140
|
|
158
|
-
|
159
|
-
|
160
|
-
}
|
141
|
+
host.unlisten("postSectionDataBinding", this._onPostSectionDataBinding);
|
142
|
+
host.unlisten("columnAdded", this._onColumnAdded);
|
161
143
|
|
162
|
-
|
144
|
+
if (!this._hosts.length) {
|
145
|
+
if (this._timerId) {
|
146
|
+
clearTimeout(this._timerId);
|
147
|
+
this._timerId = 0;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
};
|
163
151
|
|
164
|
-
host.unlisten("postSectionDataBinding", this._onPostSectionDataBinding);
|
165
|
-
host.unlisten("columnAdded", this._onColumnAdded);
|
166
152
|
|
167
|
-
if (!this._hosts.length) {
|
168
|
-
if (this._timerId) {
|
169
|
-
clearTimeout(this._timerId);
|
170
|
-
this._timerId = 0;
|
171
|
-
}
|
172
|
-
}
|
173
|
-
};
|
174
153
|
/** @public
|
175
154
|
* @param {ColumnFitterPlugin~Options=} options
|
176
155
|
*/
|
177
|
-
|
178
|
-
|
179
156
|
ColumnFitterPlugin.prototype.config = function (options) {
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
if (typeof val === "number") {
|
227
|
-
this._interval = val;
|
228
|
-
}
|
229
|
-
}
|
230
|
-
|
231
|
-
var paddingSize =
|
232
|
-
/** @type {number} */
|
233
|
-
options["paddingSize"];
|
234
|
-
|
235
|
-
if (paddingSize != null) {
|
236
|
-
this._defaultPadding = false;
|
237
|
-
this._paddingSize = paddingSize;
|
238
|
-
}
|
239
|
-
|
240
|
-
if (this._defaultPadding) {
|
241
|
-
// Title section need extra padding to avoid ellipsis
|
242
|
-
this._paddingSize = this._title ? 4 : 2;
|
243
|
-
}
|
157
|
+
if (!options) { return; }
|
158
|
+
|
159
|
+
let columns = options["columns"];
|
160
|
+
if (columns) {
|
161
|
+
let column, len = columns.length;
|
162
|
+
for (let c = 0; c < len; ++c) {
|
163
|
+
column = columns[c];
|
164
|
+
this._retrieveBooleanColumnOption(column, "noFitting", c);
|
165
|
+
this._retrieveBooleanColumnOption(column, "contentFitting", c);
|
166
|
+
this._retrieveColumnOption(column, "width", c);
|
167
|
+
this._retrieveColumnOption(column, "scalable", c);
|
168
|
+
this._retrieveColumnOption(column, "minWidth", c); // NOTE: minWidth is also used in core grid. This will make minWidth option redundant.
|
169
|
+
this._retrieveColumnOption(column, "maxWidth", c);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
this._proportion = ColumnFitterPlugin._readBoolean(options, "proportion", this._proportion);
|
174
|
+
this._constraint = ColumnFitterPlugin._readBoolean(options, "constraint", this._constraint);
|
175
|
+
this._title = ColumnFitterPlugin._readBoolean(options, "title", this._title);
|
176
|
+
this._shrinkable = ColumnFitterPlugin._readBoolean(options, "shrinkable", this._shrinkable);
|
177
|
+
|
178
|
+
if (this._proportion) {
|
179
|
+
let host = this._hosts[this._hosts.length - 1];
|
180
|
+
if (host) {
|
181
|
+
host.preserveProportion(true);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
let val = options["autoAdjust"] || options["autoAdjusting"];
|
186
|
+
if (val != null) {
|
187
|
+
this._autoAdjust = val ? true : false;
|
188
|
+
if (typeof val === "number") {
|
189
|
+
this._interval = val;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
let paddingSize = /** @type {number} */(options["paddingSize"]);
|
194
|
+
if (paddingSize != null) {
|
195
|
+
this._defaultPadding = false;
|
196
|
+
this._paddingSize = paddingSize;
|
197
|
+
}
|
198
|
+
if (this._defaultPadding) {
|
199
|
+
// Title section need extra padding to avoid ellipsis
|
200
|
+
this._paddingSize = (this._title) ? 4 : 2;
|
201
|
+
}
|
244
202
|
};
|
203
|
+
|
245
204
|
/** @public
|
246
205
|
* @param {Object=} gridOptions
|
247
206
|
* @return {!Object}
|
248
207
|
*/
|
249
|
-
|
250
|
-
|
251
208
|
ColumnFitterPlugin.prototype.getConfigObject = function (gridOptions) {
|
252
|
-
|
253
|
-
var columns = obj.columns;
|
254
|
-
|
255
|
-
if (!columns) {
|
256
|
-
columns = obj.columns = [];
|
257
|
-
}
|
209
|
+
let obj = gridOptions || {};
|
258
210
|
|
259
|
-
|
211
|
+
let columns = obj.columns;
|
212
|
+
if (!columns) {
|
213
|
+
columns = obj.columns = [];
|
214
|
+
}
|
260
215
|
|
261
|
-
|
262
|
-
|
216
|
+
let len = this.getColumnCount();
|
217
|
+
for (let i = 0; i < len; ++i) {
|
218
|
+
let column = columns[i];
|
219
|
+
if (!column) {
|
220
|
+
column = columns[i] = {};
|
221
|
+
}
|
263
222
|
|
264
|
-
|
265
|
-
|
266
|
-
|
223
|
+
let colOptions = this._getColumnOption(i, "noFitting");
|
224
|
+
if (colOptions) {
|
225
|
+
column.noFitting = true;
|
226
|
+
}
|
227
|
+
}
|
267
228
|
|
268
|
-
|
229
|
+
let extOptions = obj.columnFitting;
|
230
|
+
if (!extOptions) {
|
231
|
+
extOptions = obj.columnFitting = {};
|
232
|
+
}
|
269
233
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
}
|
234
|
+
if (this._proportion) {
|
235
|
+
extOptions.proportion = true;
|
236
|
+
}
|
274
237
|
|
275
|
-
|
238
|
+
if (this._constraint) {
|
239
|
+
extOptions.constraint = true;
|
240
|
+
}
|
276
241
|
|
277
|
-
|
278
|
-
|
279
|
-
|
242
|
+
if (this._title) {
|
243
|
+
extOptions.title = true;
|
244
|
+
}
|
280
245
|
|
281
|
-
|
282
|
-
|
283
|
-
|
246
|
+
if (this._shrinkable) {
|
247
|
+
extOptions.shrinkable = true;
|
248
|
+
}
|
284
249
|
|
285
|
-
|
286
|
-
|
287
|
-
|
250
|
+
if (this._autoAdjust) {
|
251
|
+
extOptions.autoAdjust = true;
|
252
|
+
}
|
288
253
|
|
289
|
-
|
290
|
-
|
291
|
-
|
254
|
+
if (!this._defaultPadding) {
|
255
|
+
extOptions.paddingSize = this._paddingSize;
|
256
|
+
}
|
292
257
|
|
293
|
-
|
294
|
-
extOptions.shrinkable = true;
|
295
|
-
}
|
296
|
-
|
297
|
-
if (this._autoAdjust) {
|
298
|
-
extOptions.autoAdjust = true;
|
299
|
-
}
|
300
|
-
|
301
|
-
if (!this._defaultPadding) {
|
302
|
-
extOptions.paddingSize = this._paddingSize;
|
303
|
-
}
|
304
|
-
|
305
|
-
return obj;
|
258
|
+
return obj;
|
306
259
|
};
|
260
|
+
|
307
261
|
/** Function for ColumnMenuExtension to collect config of column menu
|
308
262
|
* @public
|
309
263
|
* @param {number} colIndex Column index
|
310
264
|
* @param {Object} config Column Menu configuration
|
311
265
|
* @return {!Object}
|
312
266
|
*/
|
313
|
-
|
314
|
-
|
315
267
|
ColumnFitterPlugin.prototype.getColumnMenu = function (colIndex, config) {
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
Array.prototype.push.apply(menu.menuItems, extMenuItems);
|
352
|
-
return config;
|
268
|
+
if (!config) {
|
269
|
+
config = {};
|
270
|
+
}
|
271
|
+
|
272
|
+
let menus = config.menus;
|
273
|
+
if (!menus) {
|
274
|
+
menus = config.menus = [];
|
275
|
+
}
|
276
|
+
|
277
|
+
let menu = menus[0];
|
278
|
+
if (!menu) {
|
279
|
+
menu = menus[0] = {
|
280
|
+
menuItems: []
|
281
|
+
};
|
282
|
+
}
|
283
|
+
|
284
|
+
// Menu items for this extension
|
285
|
+
let group = "USED_ONCE";
|
286
|
+
let extMenuItems = [{
|
287
|
+
indexScore: 2,
|
288
|
+
label: "Autosize This Column",
|
289
|
+
group: group,
|
290
|
+
value: { colIndex: colIndex },
|
291
|
+
click: this._onItemResizeThisColumnClicked
|
292
|
+
}, {
|
293
|
+
indexScore: 1,
|
294
|
+
label: "Autosize All Columns",
|
295
|
+
group: group,
|
296
|
+
click: this._onItemResizeAllColumnClicked
|
297
|
+
}];
|
298
|
+
|
299
|
+
// Push menu items to config
|
300
|
+
Array.prototype.push.apply(menu.menuItems, extMenuItems);
|
301
|
+
|
302
|
+
return config;
|
353
303
|
};
|
304
|
+
|
354
305
|
/** @private
|
355
306
|
* @param {Object} e
|
356
307
|
*/
|
357
|
-
|
358
|
-
|
359
308
|
ColumnFitterPlugin.prototype._onItemResizeThisColumnClicked = function (e) {
|
360
|
-
|
361
|
-
|
362
|
-
this._hideColumnMenu();
|
309
|
+
this.adjustColumnWidth(e.currentTarget.value.colIndex);
|
310
|
+
this._hideColumnMenu();
|
363
311
|
};
|
312
|
+
|
364
313
|
/** @private
|
365
314
|
* @param {Object} e
|
366
315
|
*/
|
367
|
-
|
368
|
-
|
369
316
|
ColumnFitterPlugin.prototype._onItemResizeAllColumnClicked = function (e) {
|
370
|
-
|
371
|
-
|
372
|
-
this._hideColumnMenu();
|
317
|
+
this.adjustAllColumns();
|
318
|
+
this._hideColumnMenu();
|
373
319
|
};
|
320
|
+
|
374
321
|
/** @private
|
375
322
|
*/
|
376
|
-
|
377
|
-
|
378
323
|
ColumnFitterPlugin.prototype._hideColumnMenu = function () {
|
379
|
-
|
380
|
-
|
381
|
-
|
324
|
+
let host = this._hosts[0];
|
325
|
+
let columnMenuExt = host.getPlugin('ColumnMenuPlugin');
|
326
|
+
columnMenuExt.hide();
|
382
327
|
};
|
328
|
+
|
383
329
|
/** @private
|
384
330
|
* @param {Object} column
|
385
331
|
* @param {string} propName
|
386
332
|
* @param {number} colIndex
|
387
333
|
*/
|
388
|
-
|
389
|
-
|
390
334
|
ColumnFitterPlugin.prototype._retrieveBooleanColumnOption = function (column, propName, colIndex) {
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
}
|
335
|
+
if (column) {
|
336
|
+
let bool = ColumnFitterPlugin._readBoolean(column, propName, false);
|
337
|
+
this._newColumnData(colIndex)[propName] = bool;
|
338
|
+
}
|
396
339
|
};
|
397
340
|
/** @private
|
398
341
|
* @param {Object} column
|
399
342
|
* @param {string} propName
|
400
343
|
* @param {number} colIndex
|
401
344
|
*/
|
402
|
-
|
403
|
-
|
404
345
|
ColumnFitterPlugin.prototype._retrieveColumnOption = function (column, propName, colIndex) {
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
}
|
346
|
+
if (column) {
|
347
|
+
let val = column[propName];
|
348
|
+
if (val != null) {
|
349
|
+
this._newColumnData(colIndex)[propName] = val;
|
350
|
+
}
|
351
|
+
}
|
412
352
|
};
|
413
353
|
/** Guarantee boolean value
|
414
354
|
* @private
|
@@ -418,26 +358,21 @@ ColumnFitterPlugin.prototype._retrieveColumnOption = function (column, propName,
|
|
418
358
|
* @param {boolean} defaultVal
|
419
359
|
* @return {boolean}
|
420
360
|
*/
|
421
|
-
|
422
|
-
|
423
361
|
ColumnFitterPlugin._readBoolean = function (obj, propName, defaultVal) {
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
}
|
362
|
+
let val = obj[propName];
|
363
|
+
if (val != null) {
|
364
|
+
return val ? true : false;
|
365
|
+
} else {
|
366
|
+
return defaultVal;
|
367
|
+
}
|
431
368
|
};
|
432
369
|
/** Force update and calculation on a single column. It is not recommended to be used multiple time successively
|
433
370
|
* @public
|
434
371
|
* @param {Array.<number>=} colIndex Column indices
|
435
372
|
* @return {boolean} True if there is any change, otherwise false
|
436
373
|
*/
|
437
|
-
|
438
|
-
|
439
374
|
ColumnFitterPlugin.prototype.adjustColumnWidth = function (colIndex) {
|
440
|
-
|
375
|
+
return this.adjustColumns([colIndex]);
|
441
376
|
};
|
442
377
|
/** Force update and calculation on specific columns
|
443
378
|
* @public
|
@@ -445,146 +380,114 @@ ColumnFitterPlugin.prototype.adjustColumnWidth = function (colIndex) {
|
|
445
380
|
* @param {boolean=} force=true Force adjust the columns regardless of noFitting flag
|
446
381
|
* @return {boolean} True if there is any change, otherwise false
|
447
382
|
*/
|
448
|
-
|
449
|
-
|
450
383
|
ColumnFitterPlugin.prototype.adjustColumns = function (colIndices, force) {
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
if (host.isProportionPreserved()) {
|
517
|
-
// Get proportion mode from grid
|
518
|
-
var columnScalability = [];
|
519
|
-
|
520
|
-
for (var columnIndex = 0; columnIndex < len; columnIndex++) {
|
521
|
-
columnScalability.push(host.getColumnScalability(columnIndex));
|
522
|
-
}
|
523
|
-
|
524
|
-
dirty |= host.setColumnWidths(widths, columnScalability);
|
525
|
-
} else {
|
526
|
-
dirty |= host.setColumnWidths(widths);
|
527
|
-
}
|
528
|
-
}
|
529
|
-
}
|
530
|
-
|
531
|
-
this._synchronousRendering = false; // Next time will render asynchronously
|
532
|
-
|
533
|
-
return !!dirty;
|
384
|
+
if (force == null) {
|
385
|
+
force = true;
|
386
|
+
}
|
387
|
+
let candidates = this._collectCandidates(colIndices, force);
|
388
|
+
let len = candidates.length;
|
389
|
+
if (!len) {
|
390
|
+
return false; // No valid column to be processed
|
391
|
+
}
|
392
|
+
|
393
|
+
let i, cd;
|
394
|
+
for (i = 0; i < len; ++i) {
|
395
|
+
cd = candidates[i];
|
396
|
+
if (cd.text) {
|
397
|
+
cd.elem.appendChild(this._getDummyCell(cd.index, cd.text)); // TODO: Handle case where the column is hidden or virtualized.
|
398
|
+
}
|
399
|
+
}
|
400
|
+
|
401
|
+
let host = this._hosts[0];
|
402
|
+
let widths = new Array(host.getColumnCount());
|
403
|
+
for (i = 0; i < len; ++i) {
|
404
|
+
cd = candidates[i];
|
405
|
+
let width = this._calculateCellWidth(cd.index, host, cd.width);// WARNING: Only the first host is used
|
406
|
+
let prevW = cd.elem._caclWidth || 0;
|
407
|
+
if (width > prevW) { // Exclude zero width
|
408
|
+
widths[cd.index] = width;
|
409
|
+
if (this._autoAdjust && !this._shrinkable) {
|
410
|
+
cd.elem._caclWidth = width;
|
411
|
+
}
|
412
|
+
}
|
413
|
+
}
|
414
|
+
|
415
|
+
// Remove all dummy cells
|
416
|
+
for (i = 0; i < len; ++i) {
|
417
|
+
let dummy = this._dummyCells[candidates[i].index];
|
418
|
+
if (dummy && dummy.parentNode) {
|
419
|
+
dummy.parentNode.removeChild(dummy);
|
420
|
+
dummy.textContent = ""; // Reduce cache memory
|
421
|
+
}
|
422
|
+
}
|
423
|
+
|
424
|
+
let dirty = 0;
|
425
|
+
let hostCount = this._hosts.length;
|
426
|
+
if (this._constraint) {
|
427
|
+
for (i = 0; i < hostCount; ++i) {
|
428
|
+
host = this._hosts[i];
|
429
|
+
dirty |= host.setMinimumColumnWidths(widths);
|
430
|
+
}
|
431
|
+
} else {
|
432
|
+
for (i = 0; i < hostCount; ++i) {
|
433
|
+
host = this._hosts[i];
|
434
|
+
if(host.isProportionPreserved()) { // Get proportion mode from grid
|
435
|
+
let columnScalability = [];
|
436
|
+
for (let columnIndex = 0; columnIndex < len; columnIndex++) {
|
437
|
+
columnScalability.push(host.getColumnScalability(columnIndex));
|
438
|
+
}
|
439
|
+
dirty |= host.setColumnWidths(widths, columnScalability);
|
440
|
+
} else {
|
441
|
+
dirty |= host.setColumnWidths(widths);
|
442
|
+
}
|
443
|
+
}
|
444
|
+
}
|
445
|
+
|
446
|
+
this._synchronousRendering = false; // Next time will render asynchronously
|
447
|
+
|
448
|
+
return !!dirty;
|
534
449
|
};
|
535
450
|
/** Force update and calculation on all columns
|
536
451
|
* @public
|
537
452
|
* @return {boolean} True if there is any change, otherwise false
|
538
453
|
*/
|
539
|
-
|
540
|
-
|
541
454
|
ColumnFitterPlugin.prototype.adjustAllColumns = function () {
|
542
|
-
|
455
|
+
return this.adjustColumns();
|
543
456
|
};
|
457
|
+
|
544
458
|
/** @public
|
545
459
|
* @param {number} colIndex
|
546
460
|
* @return {number}
|
547
461
|
*/
|
548
|
-
|
549
|
-
|
550
462
|
ColumnFitterPlugin.prototype.calculateColumnWidth = function (colIndex) {
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
dummyCell = this._getDummyCell(colIndex, text);
|
581
|
-
var columnElem = colObj.getElement();
|
582
|
-
columnElem.appendChild(dummyCell);
|
583
|
-
width = this._calculateCellWidth(colIndex, host);
|
584
|
-
columnElem.removeChild(dummyCell);
|
585
|
-
}
|
586
|
-
|
587
|
-
return width;
|
463
|
+
let host = this._hosts[0];
|
464
|
+
let section = host ? host.getSection("content") : null;
|
465
|
+
if (!section) {
|
466
|
+
return NaN;
|
467
|
+
}
|
468
|
+
let colObj = section.getColumn(colIndex);
|
469
|
+
if (!colObj) {
|
470
|
+
return NaN; // The given column does not exist
|
471
|
+
}
|
472
|
+
let noFitting = this._getColumnOption(colIndex, "noFitting");
|
473
|
+
if (noFitting) {
|
474
|
+
return NaN;
|
475
|
+
}
|
476
|
+
|
477
|
+
let width, dummyCell;
|
478
|
+
let contentFitting = this._getColumnOption(colIndex, "contentFitting");
|
479
|
+
if (contentFitting) {
|
480
|
+
width = this._getColumnFitContentWidth(colIndex);
|
481
|
+
width = this._calculateCellWidth(colIndex, host, width);
|
482
|
+
} else {
|
483
|
+
let text = this._getColumnFitContentText(colIndex);
|
484
|
+
dummyCell = this._getDummyCell(colIndex, text);
|
485
|
+
let columnElem = colObj.getElement();
|
486
|
+
columnElem.appendChild(dummyCell);
|
487
|
+
width = this._calculateCellWidth(colIndex, host);
|
488
|
+
columnElem.removeChild(dummyCell);
|
489
|
+
}
|
490
|
+
return width;
|
588
491
|
};
|
589
492
|
/** This is for backward compatability with old ColumnWidthAdjustingPlugin. The method is an alias of {@link ColumnFitterPlugin#calculateColumnWidth}
|
590
493
|
* @public
|
@@ -592,109 +495,81 @@ ColumnFitterPlugin.prototype.calculateColumnWidth = function (colIndex) {
|
|
592
495
|
* @param {number} colIndex
|
593
496
|
* @return {number}
|
594
497
|
*/
|
595
|
-
|
596
|
-
|
597
498
|
ColumnFitterPlugin.prototype.getAdjustedColumnWidth = ColumnFitterPlugin.prototype.calculateColumnWidth;
|
499
|
+
|
598
500
|
/** Set all column widths to percentage width
|
599
501
|
* @public
|
600
502
|
*/
|
601
|
-
|
602
503
|
ColumnFitterPlugin.prototype.resetAllColumns = function () {
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
}
|
619
|
-
}
|
620
|
-
}
|
504
|
+
let hosts = this._hosts;
|
505
|
+
let colCount = this.getColumnCount();
|
506
|
+
let host, width, proportion;
|
507
|
+
for (let i = 0; i < hosts.length; i++ ) {
|
508
|
+
host = hosts[i];
|
509
|
+
for (let c = 0; c < colCount; c++) {
|
510
|
+
width = this._getColumnOption(c, "width");
|
511
|
+
proportion = this._getColumnOption(c, "scalable");
|
512
|
+
if (width != null) {
|
513
|
+
host.setColumnWidth(c, width, false);
|
514
|
+
} else {
|
515
|
+
host.setColumnWidth(c, 100, proportion !== false);
|
516
|
+
}
|
517
|
+
}
|
518
|
+
}
|
621
519
|
};
|
622
|
-
/** @private */
|
623
520
|
|
624
521
|
|
522
|
+
/** @private */
|
625
523
|
ColumnFitterPlugin.prototype._onPostSectionDataBinding = function () {
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
if (!this._timerId) {
|
636
|
-
this._timerId = setTimeout(this._onTimeout, this._interval);
|
637
|
-
}
|
524
|
+
if (!this._autoAdjust) { return; }
|
525
|
+
if (this._synchronousRendering) {
|
526
|
+
this.adjustColumns(null, false);
|
527
|
+
return;
|
528
|
+
}
|
529
|
+
if (!this._timerId) {
|
530
|
+
this._timerId = setTimeout(this._onTimeout, this._interval);
|
531
|
+
}
|
638
532
|
};
|
639
533
|
/** @private
|
640
534
|
* @param {Object} e
|
641
535
|
*/
|
642
|
-
|
643
|
-
|
644
536
|
ColumnFitterPlugin.prototype._onColumnAdded = function (e) {
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
this._retrieveColumnOption(context, "scalable", colIndex);
|
655
|
-
|
656
|
-
this._retrieveColumnOption(context, "minWidth", colIndex); // NOTE: minWidth is also used in core grid. This will make minWidth option redundant.
|
657
|
-
|
658
|
-
|
659
|
-
this._retrieveColumnOption(context, "maxWidth", colIndex);
|
660
|
-
|
661
|
-
this._synchronousRendering = true;
|
537
|
+
let context = e.context;
|
538
|
+
let colIndex = e.colIndex;
|
539
|
+
this._retrieveBooleanColumnOption(context, "noFitting", colIndex);
|
540
|
+
this._retrieveBooleanColumnOption(context, "contentFitting", colIndex);
|
541
|
+
this._retrieveColumnOption(context, "width", colIndex);
|
542
|
+
this._retrieveColumnOption(context, "scalable", colIndex);
|
543
|
+
this._retrieveColumnOption(context, "minWidth", colIndex); // NOTE: minWidth is also used in core grid. This will make minWidth option redundant.
|
544
|
+
this._retrieveColumnOption(context, "maxWidth", colIndex);
|
545
|
+
this._synchronousRendering = true;
|
662
546
|
};
|
663
547
|
/** @private */
|
664
|
-
|
665
|
-
|
666
548
|
ColumnFitterPlugin.prototype._onTimeout = function () {
|
667
|
-
|
668
|
-
|
549
|
+
this._timerId = 0;
|
550
|
+
this.adjustColumns(null, false);
|
669
551
|
};
|
552
|
+
|
670
553
|
/** @private
|
671
554
|
* @param {Array.<number>=} colIndices Column indices
|
672
555
|
* @param {boolean} force
|
673
556
|
* @return {!Array.<Object>}
|
674
557
|
*/
|
675
|
-
|
676
|
-
|
677
558
|
ColumnFitterPlugin.prototype._collectCandidates = function (colIndices, force) {
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
if (candidate) {
|
693
|
-
candidates.push(candidate);
|
694
|
-
}
|
695
|
-
}
|
696
|
-
|
697
|
-
return candidates;
|
559
|
+
let host = this._hosts[0];
|
560
|
+
let section = host ? host.getSection("content") : null;
|
561
|
+
if (!section) { return []; }
|
562
|
+
|
563
|
+
let candidate;
|
564
|
+
let candidates = [];
|
565
|
+
let len = colIndices ? colIndices.length : host.getColumnCount();
|
566
|
+
for (let i = 0; i < len; ++i) {
|
567
|
+
candidate = this._collectCandidate(section, colIndices ? colIndices[i] : i, force);
|
568
|
+
if (candidate) {
|
569
|
+
candidates.push(candidate);
|
570
|
+
}
|
571
|
+
}
|
572
|
+
return candidates;
|
698
573
|
};
|
699
574
|
/** @private
|
700
575
|
* @param {Object} section ILayoutGrid
|
@@ -702,301 +577,241 @@ ColumnFitterPlugin.prototype._collectCandidates = function (colIndices, force) {
|
|
702
577
|
* @param {boolean} force
|
703
578
|
* @return {Object}
|
704
579
|
*/
|
705
|
-
|
706
|
-
|
707
580
|
ColumnFitterPlugin.prototype._collectCandidate = function (section, colIndex, force) {
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
}
|
733
|
-
}
|
734
|
-
|
735
|
-
return obj;
|
736
|
-
}
|
737
|
-
|
738
|
-
return null;
|
581
|
+
let colObj = section.getColumn(colIndex);
|
582
|
+
if (colObj) {
|
583
|
+
let obj = {
|
584
|
+
index: colIndex,
|
585
|
+
elem: colObj.getElement()
|
586
|
+
};
|
587
|
+
let noFitting = force ? false : this._getColumnOption(colIndex, "noFitting");
|
588
|
+
let contentFitting = this._getColumnOption(colIndex, "contentFitting");
|
589
|
+
if (!noFitting) {
|
590
|
+
if (contentFitting) {
|
591
|
+
let width = this._getColumnFitContentWidth(colIndex);
|
592
|
+
if (width > 0) {
|
593
|
+
obj.width = width;
|
594
|
+
}
|
595
|
+
} else {
|
596
|
+
let text = this._getColumnFitContentText(colIndex);
|
597
|
+
if (text) {
|
598
|
+
obj.text = text;
|
599
|
+
}
|
600
|
+
}
|
601
|
+
}
|
602
|
+
return obj;
|
603
|
+
}
|
604
|
+
return null;
|
739
605
|
};
|
740
606
|
/** @private
|
741
607
|
* @description Calculate width of cell's custom rendered content
|
742
608
|
* @param {number} colIndex
|
743
609
|
* @return {number}
|
744
610
|
*/
|
745
|
-
|
746
|
-
|
747
611
|
ColumnFitterPlugin.prototype._getColumnFitContentWidth = function (colIndex) {
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
}
|
794
|
-
}
|
795
|
-
}
|
796
|
-
}
|
797
|
-
}
|
798
|
-
|
799
|
-
if (!width) {
|
800
|
-
// If there is no with, clear cell padding cache.
|
801
|
-
this._cellPaddings[colIndex] = 0;
|
802
|
-
return 0;
|
803
|
-
}
|
804
|
-
|
805
|
-
return width + cellPadding;
|
612
|
+
let w, contentWidth;
|
613
|
+
let width = 0;
|
614
|
+
let cellPadding = this._getCellPadding(colIndex);
|
615
|
+
for (let i = this._hosts.length; --i >= 0;) {
|
616
|
+
let host = this._hosts[i];
|
617
|
+
let sections = host.getAllSections("content");
|
618
|
+
let sectionCount = sections.length;
|
619
|
+
for (let s = 0; s < sectionCount; s++) {
|
620
|
+
let section = sections[s];
|
621
|
+
let fi = section.getFirstIndexInView();
|
622
|
+
let li = section.getLastIndexInView() + 1;
|
623
|
+
for (let r = fi; r < li; r++) {
|
624
|
+
let cell = section.getCell(colIndex, r, false);
|
625
|
+
if (!cell) {
|
626
|
+
continue;
|
627
|
+
}
|
628
|
+
let cellElem = cell.getElement();
|
629
|
+
if (cellElem.classList.contains("tr-stretched")) {
|
630
|
+
continue;
|
631
|
+
}
|
632
|
+
let content = cell.getContent();
|
633
|
+
|
634
|
+
if (content && cellElem && cell.isVisible()) {
|
635
|
+
w = contentWidth = content.offsetWidth;
|
636
|
+
let children = content.children;
|
637
|
+
|
638
|
+
let isWidth100Pct = ColumnFitterPlugin._almost100Pct(contentWidth + cellPadding, cellElem.offsetWidth);
|
639
|
+
let hasChild = children.length > 0;
|
640
|
+
|
641
|
+
if (isWidth100Pct && hasChild) { // Content width is 100% of cell.
|
642
|
+
w = ColumnFitterPlugin._sumChildrenWidth(children); // Use children to calculate width
|
643
|
+
}
|
644
|
+
if (w > width) {
|
645
|
+
width = w;
|
646
|
+
}
|
647
|
+
}
|
648
|
+
}
|
649
|
+
}
|
650
|
+
}
|
651
|
+
if (!width) {
|
652
|
+
// If there is no with, clear cell padding cache.
|
653
|
+
this._cellPaddings[colIndex] = 0;
|
654
|
+
return 0;
|
655
|
+
}
|
656
|
+
return width + cellPadding;
|
806
657
|
};
|
807
658
|
/** @private
|
808
659
|
* @param {number} colIndex
|
809
660
|
* @return {string}
|
810
661
|
*/
|
811
|
-
|
812
|
-
|
813
662
|
ColumnFitterPlugin.prototype._getColumnFitContentText = function (colIndex) {
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
}
|
851
|
-
} else {
|
852
|
-
maxLen = textLen;
|
853
|
-
texts.push(text);
|
854
|
-
}
|
855
|
-
}
|
856
|
-
}
|
857
|
-
}
|
858
|
-
}
|
859
|
-
|
860
|
-
return texts.length ? texts.join("\n") : "";
|
663
|
+
let maxLen = NaN;
|
664
|
+
let filteringChars = 3; // TODO: Change this default value
|
665
|
+
let texts = [];
|
666
|
+
for (let i = this._hosts.length; --i >= 0;) {
|
667
|
+
let host = this._hosts[i];
|
668
|
+
let sections = host.getAllSections("content"); // TODO: Get data from the datasource
|
669
|
+
if (this._title) {
|
670
|
+
sections = host.getAllSections("title").concat(sections);
|
671
|
+
}
|
672
|
+
let sectionCount = sections.length;
|
673
|
+
for (let s = 0; s < sectionCount; s++) {
|
674
|
+
let section = sections[s];
|
675
|
+
let fi = section.getFirstIndexInView();
|
676
|
+
let li = section.getLastIndexInView() + 1;
|
677
|
+
for (let r = fi; r < li; r++) {
|
678
|
+
let cell = section.getCell(colIndex, r, false); // Ignore cell span
|
679
|
+
if (!cell) {
|
680
|
+
continue;
|
681
|
+
}
|
682
|
+
|
683
|
+
let text = cell.getTextContent(); // Content can only be string
|
684
|
+
if (text && cell.getElement() && cell.isVisible()) { // Due to timer nature of the algorithm
|
685
|
+
let textLen = text.length;
|
686
|
+
if (textLen <= maxLen) {
|
687
|
+
if (textLen >= maxLen - filteringChars) {
|
688
|
+
texts.push(text);
|
689
|
+
}
|
690
|
+
} else {
|
691
|
+
maxLen = textLen;
|
692
|
+
texts.push(text);
|
693
|
+
}
|
694
|
+
}
|
695
|
+
}
|
696
|
+
}
|
697
|
+
}
|
698
|
+
return texts.length ? texts.join("\n") : "";
|
861
699
|
};
|
862
700
|
/** @private
|
863
701
|
* @param {number} colIndex
|
864
702
|
* @param {string=} text
|
865
703
|
* @return {Element}
|
866
704
|
*/
|
867
|
-
|
868
|
-
|
869
705
|
ColumnFitterPlugin.prototype._getDummyCell = function (colIndex, text) {
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
}
|
880
|
-
|
881
|
-
return dummyCell;
|
706
|
+
let dummyCell = this._dummyCells[colIndex];
|
707
|
+
if (!dummyCell) {
|
708
|
+
dummyCell = this._dummyCells[colIndex] = ColumnFitterPlugin._createDummyCell();
|
709
|
+
}
|
710
|
+
if (text) {
|
711
|
+
// TODO: Check if we can find a better way to improve innerText
|
712
|
+
dummyCell.innerText = text; // innerText will populate <br> tag from the newline character '\n'
|
713
|
+
}
|
714
|
+
return dummyCell;
|
882
715
|
};
|
716
|
+
|
883
717
|
/** @private
|
884
718
|
* @param {number} colIndex
|
885
719
|
* @return {number}
|
886
720
|
*/
|
887
|
-
|
888
|
-
|
889
721
|
ColumnFitterPlugin.prototype._getCellPadding = function (colIndex) {
|
890
|
-
|
891
|
-
|
892
|
-
if (cellPadding > 0) {
|
893
|
-
return cellPadding;
|
894
|
-
}
|
722
|
+
let cellPadding = this._cellPaddings[colIndex];
|
895
723
|
|
896
|
-
|
897
|
-
|
898
|
-
|
724
|
+
if (cellPadding > 0) {
|
725
|
+
return cellPadding;
|
726
|
+
}
|
899
727
|
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
728
|
+
let host = this._hosts[0];
|
729
|
+
let section = host ? host.getSection("content") : null;
|
730
|
+
let colObj = section.getColumn(colIndex);
|
731
|
+
if (!colObj) {
|
732
|
+
cellPadding = this._cellPaddings[colIndex] = NaN;
|
733
|
+
return cellPadding;
|
734
|
+
}
|
904
735
|
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
columnElem.removeChild(dummyCell);
|
912
|
-
return width;
|
736
|
+
let columnElem = colObj.getElement();
|
737
|
+
let dummyCell = ColumnFitterPlugin._createDummyCell();
|
738
|
+
columnElem.appendChild(dummyCell);
|
739
|
+
let width = this._cellPaddings[colIndex] = dummyCell.offsetWidth;
|
740
|
+
columnElem.removeChild(dummyCell);
|
741
|
+
return width;
|
913
742
|
};
|
743
|
+
|
914
744
|
/** @private
|
915
745
|
* @param {number} colIndex
|
916
746
|
* @param {Object} grid core grid object
|
917
747
|
* @param {number=} opt_width Optional initial width
|
918
748
|
* @return {number}
|
919
749
|
*/
|
920
|
-
|
921
|
-
|
922
750
|
ColumnFitterPlugin.prototype._calculateCellWidth = function (colIndex, grid, opt_width) {
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
if (width < minWidth) {
|
953
|
-
width = minWidth;
|
954
|
-
}
|
955
|
-
}
|
956
|
-
|
957
|
-
return width;
|
751
|
+
let minWidth = NaN;
|
752
|
+
let maxWidth = NaN;
|
753
|
+
let colDef = grid.getColumnData(colIndex);
|
754
|
+
if (colDef) {
|
755
|
+
minWidth = colDef["minWidth"] || NaN;
|
756
|
+
maxWidth = colDef["maxWidth"] || NaN;
|
757
|
+
}
|
758
|
+
|
759
|
+
let width;
|
760
|
+
if (opt_width) {
|
761
|
+
width = opt_width;
|
762
|
+
} else {
|
763
|
+
let dummyCell = this._dummyCells[colIndex];
|
764
|
+
if (dummyCell) {
|
765
|
+
// NOTE: If font isn't cached, comparison is being done against Arial instead of Proxima Nova, thus yielding wrong offsetwidth
|
766
|
+
width = dummyCell.offsetWidth; // TODO: Handle case where the column is hidden or virtualized
|
767
|
+
}
|
768
|
+
}
|
769
|
+
if (width) {
|
770
|
+
width += this._paddingSize;
|
771
|
+
if (width > maxWidth) {
|
772
|
+
width = maxWidth;
|
773
|
+
}
|
774
|
+
if (width < minWidth) {
|
775
|
+
width = minWidth;
|
776
|
+
}
|
777
|
+
}
|
778
|
+
return width;
|
958
779
|
};
|
780
|
+
|
959
781
|
/** @private
|
960
782
|
* @param {NodeList} childNodes
|
961
783
|
* @return {number}
|
962
784
|
*/
|
963
|
-
|
964
|
-
|
965
785
|
ColumnFitterPlugin._sumChildrenWidth = function (childNodes) {
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
return 0;
|
786
|
+
let len = childNodes.length;
|
787
|
+
if (len > 0) {
|
788
|
+
let last = childNodes[len - 1];
|
789
|
+
let first = childNodes[0];
|
790
|
+
return last.offsetWidth + last.offsetLeft - first.offsetLeft;
|
791
|
+
}
|
792
|
+
return 0;
|
975
793
|
};
|
794
|
+
|
976
795
|
/** @private
|
977
796
|
* @return {Element}
|
978
797
|
*/
|
979
|
-
|
980
|
-
|
981
798
|
ColumnFitterPlugin._createDummyCell = function () {
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
return dummyCell;
|
799
|
+
let dummyCell = document.createElement("div");
|
800
|
+
dummyCell.className = "cell";
|
801
|
+
dummyCell.style.whiteSpace = "nowrap"; // Inline style will override everything
|
802
|
+
dummyCell.style.width = "auto";
|
803
|
+
dummyCell.style.display = "table";
|
804
|
+
return dummyCell;
|
989
805
|
};
|
990
806
|
/** @private
|
991
807
|
* @param {number} val1
|
992
808
|
* @param {number} val2
|
993
809
|
* @return {boolean}
|
994
810
|
*/
|
995
|
-
|
996
|
-
|
997
811
|
ColumnFitterPlugin._almost100Pct = function (val1, val2) {
|
998
|
-
|
812
|
+
return (val1 > val2 ? val2 / val1 : val1 / val2) >= 0.97;
|
999
813
|
};
|
1000
814
|
|
815
|
+
|
1001
816
|
export default ColumnFitterPlugin;
|
1002
|
-
export { ColumnFitterPlugin, ColumnFitterPlugin as ColumnFitter, ColumnFitterPlugin as ColumnFitterExtension };
|
817
|
+
export { ColumnFitterPlugin, ColumnFitterPlugin as ColumnFitter, ColumnFitterPlugin as ColumnFitterExtension };
|