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 | 1×
1×
1×
1×
2021×
1×
1417×
1417×
1417×
1417×
1417×
496×
361×
361×
1417×
83×
83×
1417×
52×
52×
1417×
1417×
7225×
1417×
2×
1417×
1417×
51×
1×
336×
336×
3023×
336×
35×
11×
24×
35×
35×
87×
87×
35×
87×
87×
87×
25×
62×
12×
1×
1×
7873×
1×
7872×
7872×
7872×
7872×
4386×
4386×
284×
4386×
22×
4386×
1×
4423×
12×
12×
4423×
4423×
4423×
4423×
4423×
4411×
12×
12×
4423×
4423×
4411×
12×
12×
4423×
1×
1×
1×
1×
4423×
57×
1×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
1×
18×
18×
18×
1×
36×
36×
36×
36×
411×
49×
96×
36×
1×
159×
788×
159×
1×
62799×
19×
62799×
28621×
34178×
34178×
17×
34161×
2×
34159×
1×
9319×
9319×
54821×
54821×
54821×
23×
54821×
27369×
9319×
1×
28×
28×
28×
28×
28×
28×
28×
1×
28×
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++) {
Iif (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 (this.parent.width !== 'auto' && this.parent.width.toString().indexOf('%') === -1) {
this.setMinwidthBycalculation(totalColumnsWidth);
}
};
ColumnWidthService.prototype.setMinwidthBycalculation = function (tWidth) {
var difference = 0;
var collection = this.parent.getColumns().filter(function (a) {
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 = (typeof this.parent.width === 'string' ? parseInt(this.parent.width, 10) : this.parent.width) - 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) {
this.setMinwidthBycalculation(tgridWidth);
}
if ((this.parent.allowResizing && module === 'resize')) {
this.setWidthToTable();
}
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++) {
if (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)]);
}
}
}
Iif (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);
Iif (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 (ej2_base_1.isNullOrUndefined(column.width) && this.parent.allowResizing
&& ej2_base_1.isNullOrUndefined(column.minWidth) && !this.isWidthUndefined()) {
column.width = 200;
}
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) {
var tWidth = 0;
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
var column = columns_1[_i];
var cWidth = this.getWidth(column);
if (column.width === 'auto') {
cWidth = 0;
}
if (column.visible !== false && cWidth !== null) {
tWidth += parseInt(cWidth.toString(), 10);
}
}
return tWidth;
};
ColumnWidthService.prototype.setWidthToTable = function () {
var tWidth = ej2_base_2.formatUnit(this.getTableWidth(this.parent.getColumns()));
Iif (this.parent.detailTemplate || this.parent.childGrid) {
this.setColumnWidth(new column_1.Column({ width: '30px' }));
}
tWidth = this.isAutoResize() ? '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');
Iif (edit) {
edit.style.width = tWidth;
}
};
ColumnWidthService.prototype.isAutoResize = function () {
return this.parent.allowResizing && this.parent.resizeSettings.mode === 'Auto';
};
return ColumnWidthService;
}());
exports.ColumnWidthService = ColumnWidthService;
});
|