1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272 | 1×
1×
1×
1×
3673×
1×
1730×
1730×
1730×
1730×
1730×
590×
450×
1×
1×
449×
1730×
92×
92×
1730×
56×
56×
1730×
1730×
8356×
1730×
2×
1730×
1730×
1722×
71×
1722×
8322×
1722×
1722×
1722×
1×
487×
487×
487×
4169×
430×
3739×
487×
36×
12×
24×
36×
36×
92×
92×
36×
92×
92×
92×
25×
67×
12×
1×
1×
3×
2×
2×
1×
9156×
1×
9155×
9155×
9155×
9155×
5411×
5411×
415×
5411×
109×
109×
5411×
1×
5450×
12×
12×
5450×
5450×
5450×
5450×
5450×
5438×
12×
12×
5450×
5450×
5438×
12×
12×
5450×
16×
16×
16×
25×
25×
105×
16×
15×
5450×
107×
1×
118×
118×
118×
1×
117×
117×
117×
117×
117×
117×
117×
117×
117×
117×
1×
33×
33×
33×
1×
66×
66×
66×
66×
873×
96×
196×
66×
1×
155×
766×
155×
1×
66481×
209×
21×
188×
66481×
27768×
38713×
38713×
19×
38694×
8×
38686×
1×
11014×
11014×
11014×
62274×
62274×
57211×
57211×
24086×
176×
172×
23910×
57211×
57052×
11014×
11014×
1×
127×
127×
1×
127×
127×
127×
127×
127×
1×
1×
127×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/constant", "../models/column", "../base/util", "../base/string-literals"], function (require, exports, ej2_base_1, ej2_base_2, constant_1, column_1, util_1, literals) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ColumnWidthService = (function () {
function ColumnWidthService(parent) {
this.parent = parent;
}
ColumnWidthService.prototype.setWidthToColumns = function () {
var i = 0;
var indexes = this.parent.getColumnIndexesInView();
var wFlag = true;
var totalColumnsWidth = 0;
if (this.parent.allowGrouping) {
for (var len = this.parent.groupSettings.columns.length; i < len; i++) {
if (this.parent.enableColumnVirtualization && indexes.indexOf(i) === -1) {
wFlag = false;
continue;
}
this.setColumnWidth(new column_1.Column({ width: '30px' }), i);
}
}
if (this.parent.detailTemplate || this.parent.childGrid) {
this.setColumnWidth(new column_1.Column({ width: '30px' }), i);
i++;
}
if (this.parent.isRowDragable() && this.parent.getFrozenMode() !== 'Right') {
this.setColumnWidth(new column_1.Column({ width: '30px' }), i);
i++;
}
var columns = this.parent.getColumns();
for (var j = 0; j < columns.length; j++) {
this.setColumnWidth(columns[parseInt(j.toString(), 10)], wFlag && this.parent.enableColumnVirtualization ? undefined : j + i);
}
if (this.parent.isRowDragable() && this.parent.getFrozenMode() === 'Right') {
this.setColumnWidth(new column_1.Column({ width: '30px' }), this.parent.groupSettings.columns.length + columns.length);
}
totalColumnsWidth = this.getTableWidth(this.parent.getColumns());
if (totalColumnsWidth !== 'auto') {
if (this.parent.width !== 'auto' && this.parent.width.toString().indexOf('%') === -1) {
this.setMinwidthBycalculation(totalColumnsWidth);
}
var maxWidthColumns = columns.filter(function (a) {
return !ej2_base_1.isNullOrUndefined(a.maxWidth);
});
var header = this.parent.getHeaderTable();
var content = this.parent.getContentTable();
Iif (this.parent.allowResizing && this.parent.element.getBoundingClientRect().width > totalColumnsWidth &&
maxWidthColumns.length === columns.length && header && content) {
ej2_base_1.addClass([header, content], ['e-tableborder']);
}
}
};
ColumnWidthService.prototype.setMinwidthBycalculation = function (tWidth) {
var _this = this;
var difference = 0;
var collection = this.parent.getColumns().filter(function (a) {
if (_this.parent.allowResizing) {
return (ej2_base_1.isNullOrUndefined(a.width) || a.width === 'auto') && ej2_base_1.isNullOrUndefined(a.maxWidth);
}
else {
return ej2_base_1.isNullOrUndefined(a.width) || a.width === 'auto';
}
});
if (collection.length) {
if (!ej2_base_1.isNullOrUndefined(this.parent.width) && this.parent.width !== 'auto' &&
typeof (this.parent.width) === 'string' && this.parent.width.indexOf('%') === -1) {
difference = parseInt(this.parent.width, 10) - tWidth;
}
else {
difference = this.parent.element.getBoundingClientRect().width - tWidth;
}
var tmWidth = 0;
for (var _i = 0, collection_1 = collection; _i < collection_1.length; _i++) {
var cols = collection_1[_i];
tmWidth += !ej2_base_1.isNullOrUndefined(cols.minWidth) ?
((typeof cols.minWidth === 'string' ? parseInt(cols.minWidth, 10) : cols.minWidth)) : 0;
}
for (var i = 0; i < collection.length; i++) {
Iif (tWidth === 0 && this.parent.allowResizing && this.isWidthUndefined() && (i !== collection.length - 1)) {
this.setUndefinedColumnWidth(collection);
}
var index = this.parent.getColumnIndexByField(collection[parseInt(i.toString(), 10)].field) + this.parent.getIndentCount();
if (tWidth !== 0 && difference < tmWidth) {
this.setWidth(collection[parseInt(i.toString(), 10)].minWidth, index);
}
else if (tWidth !== 0 && difference > tmWidth) {
this.setWidth('', index, true);
}
}
}
};
ColumnWidthService.prototype.setUndefinedColumnWidth = function (collection) {
for (var k = 0; k < collection.length; k++) {
if (k !== collection.length - 1) {
collection[parseInt(k.toString(), 10)].width = 200;
this.setWidth(200, this.parent.getColumnIndexByField(collection[parseInt(k.toString(), 10)].field));
}
}
};
ColumnWidthService.prototype.setColumnWidth = function (column, index, module) {
if (this.parent.getColumns().length < 1) {
return;
}
var columnIndex = ej2_base_1.isNullOrUndefined(index) ? this.parent.getNormalizedColumnIndex(column.uid) : index;
var cWidth = this.getWidth(column);
var tgridWidth = this.getTableWidth(this.parent.getColumns());
if (cWidth !== null) {
this.setWidth(cWidth, columnIndex);
if (this.parent.width !== 'auto' && this.parent.width.toString().indexOf('%') === -1 && tgridWidth !== 'auto') {
this.setMinwidthBycalculation(tgridWidth);
}
if (this.parent.allowResizing && (module === 'resize' || this.parent.getFrozenColumns())) {
var contentTable = this.parent.getContentTable();
this.setWidthToTable(this.parent.getFrozenColumns() && contentTable.style.width.indexOf('px') === -1);
}
this.parent.notify(constant_1.columnWidthChanged, { index: columnIndex, width: cWidth, column: column, module: module });
}
};
ColumnWidthService.prototype.setWidth = function (width, index, clear) {
if (this.parent.groupSettings.columns.length > index && util_1.ispercentageWidth(this.parent)) {
var elementWidth = this.parent.element.offsetWidth;
width = (30 / elementWidth * 100).toFixed(1) + '%';
}
var header = this.parent.getHeaderTable();
var content = this.parent.getContentTable();
var fWidth = ej2_base_2.formatUnit(width);
var headerCol = header.querySelector(literals.colGroup)
.children[parseInt(index.toString(), 10)];
if (headerCol && !clear) {
headerCol.style.width = fWidth;
}
else Eif (headerCol && clear) {
headerCol.style.width = '';
}
var contentCol = content.querySelector(literals.colGroup).children[parseInt(index.toString(), 10)];
if (contentCol && !clear) {
contentCol.style.width = fWidth;
}
else Eif (contentCol && clear) {
contentCol.style.width = '';
}
if (!this.parent.enableColumnVirtualization && this.parent.isEdit) {
var edit = this.parent.element.querySelectorAll('.e-table.e-inline-edit');
var editTableCol = [];
for (var i = 0; i < edit.length; i++) {
Eif (util_1.parentsUntil(edit[parseInt(i.toString(), 10)], 'e-grid').id === this.parent.element.id) {
for (var j = 0; j < edit[parseInt(i.toString(), 10)].querySelector('colgroup').children.length; j++) {
editTableCol.push(edit[parseInt(i.toString(), 10)].querySelector('colgroup').children[parseInt(j.toString(), 10)]);
}
}
}
if (edit.length && editTableCol.length && editTableCol[parseInt(index.toString(), 10)]) {
editTableCol[parseInt(index.toString(), 10)].style.width = fWidth;
}
}
if (this.parent.isFrozenGrid() && this.parent.enableColumnVirtualization) {
this.refreshFrozenScrollbar();
}
};
ColumnWidthService.prototype.refreshFrozenScrollbar = function () {
var args = { cancel: false };
this.parent.notify(constant_1.preventFrozenScrollRefresh, args);
if (args.cancel) {
return;
}
var scrollWidth = util_1.getScrollBarWidth();
var movableScrollbar = this.parent.element.querySelector('.e-movablescrollbar');
var movableWidth = this.parent.getContent().firstElementChild.getBoundingClientRect().width;
Eif (this.parent.enableColumnVirtualization) {
var placeHolder = this.parent.getContent().querySelector('.e-virtualtrack');
Eif (placeHolder) {
movableWidth = placeHolder.scrollWidth;
}
}
Eif (this.parent.height !== 'auto') {
movableWidth = movableWidth + scrollWidth;
}
movableScrollbar.firstElementChild.style.width = movableWidth + 'px';
};
ColumnWidthService.prototype.getSiblingsHeight = function (element) {
var previous = this.getHeightFromDirection(element, 'previous');
var next = this.getHeightFromDirection(element, 'next');
return previous + next;
};
ColumnWidthService.prototype.getHeightFromDirection = function (element, direction) {
var sibling = element[direction + 'ElementSibling'];
var result = 0;
var classList = [literals.gridHeader, literals.gridFooter, 'e-groupdroparea', 'e-gridpager', 'e-toolbar', 'e-temp-toolbar'];
while (sibling) {
if (classList.some(function (value) { return sibling.classList.contains(value); })) {
result += sibling.offsetHeight;
}
sibling = sibling[direction + 'ElementSibling'];
}
return result;
};
ColumnWidthService.prototype.isWidthUndefined = function () {
var isWidUndefCount = this.parent.getColumns().filter(function (col) {
return ej2_base_1.isNullOrUndefined(col.width) && ej2_base_1.isNullOrUndefined(col.minWidth);
}).length;
return (this.parent.getColumns().length === isWidUndefCount);
};
ColumnWidthService.prototype.getWidth = function (column) {
if (this.parent.allowResizing && ej2_base_1.isNullOrUndefined(column.width)) {
if (ej2_base_1.isNullOrUndefined(column.minWidth) && ej2_base_1.isNullOrUndefined(column.maxWidth)
&& !this.isWidthUndefined()) {
column.width = 200;
}
else Iif (column.maxWidth) {
column.width = column.maxWidth;
}
}
if (!column.width) {
return null;
}
var width = parseInt(column.width.toString(), 10);
if (column.minWidth && width < parseInt(column.minWidth.toString(), 10)) {
return column.minWidth;
}
else if (column.maxWidth && width > parseInt(column.maxWidth.toString(), 10)) {
return column.maxWidth;
}
else {
return column.width;
}
};
ColumnWidthService.prototype.getTableWidth = function (columns, resetIndentWidth) {
var tWidth = 0;
var isAutoColumn = false;
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
var column = columns_1[_i];
if (column.visible !== false) {
var cWidth = this.getWidth(column);
if (column.width === 'auto' || !column.width) {
if (this.parent.allowResizing && !resetIndentWidth) {
if (!column.maxWidth) {
isAutoColumn = true;
}
}
else {
cWidth = 0;
}
}
if (cWidth !== null) {
tWidth += parseInt(cWidth.toString(), 10);
}
}
}
tWidth = isAutoColumn ? 'auto' : tWidth;
return tWidth;
};
ColumnWidthService.prototype.setWidthToTable = function (isMaxWidth) {
var tWidth = ej2_base_2.formatUnit(this.getTableWidth(this.parent.getColumns()));
if (this.parent.detailTemplate || this.parent.childGrid) {
this.setColumnWidth(new column_1.Column({ width: '30px' }));
}
tWidth = (this.isAutoResize() || tWidth === 'auto' || isMaxWidth) ? '100%' : tWidth;
this.parent.getHeaderTable().style.width = tWidth;
this.parent.getContentTable().style.width = tWidth;
var edit = this.parent.element.querySelector('.e-table.e-inline-edit');
if (edit) {
edit.style.width = tWidth;
}
};
ColumnWidthService.prototype.isAutoResize = function () {
return this.parent.allowResizing && this.parent.resizeSettings.mode === 'Auto';
};
return ColumnWidthService;
}());
exports.ColumnWidthService = ColumnWidthService;
});
|