UNPKG

11.5 kBJavaScriptView Raw
1/**
2 * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
3 * @version v18.1.2
4 * @link http://www.ag-grid.com/
5 * @license MIT
6 */
7"use strict";
8var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
9 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
12 return c > 3 && r && Object.defineProperty(target, key, r), r;
13};
14var __metadata = (this && this.__metadata) || function (k, v) {
15 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16};
17Object.defineProperty(exports, "__esModule", { value: true });
18var column_1 = require("./column");
19var eventService_1 = require("../eventService");
20var context_1 = require("../context/context");
21var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
22var columnApi_1 = require("../columnController/columnApi");
23var gridApi_1 = require("../gridApi");
24var ColumnGroup = (function () {
25 function ColumnGroup(originalColumnGroup, groupId, instanceId) {
26 // depends on the open/closed state of the group, only displaying columns are stored here
27 this.displayedChildren = [];
28 this.localEventService = new eventService_1.EventService();
29 this.groupId = groupId;
30 this.instanceId = instanceId;
31 this.originalColumnGroup = originalColumnGroup;
32 }
33 // this is static, a it is used outside of this class
34 ColumnGroup.createUniqueId = function (groupId, instanceId) {
35 return groupId + '_' + instanceId;
36 };
37 // as the user is adding and removing columns, the groups are recalculated.
38 // this reset clears out all children, ready for children to be added again
39 ColumnGroup.prototype.reset = function () {
40 this.parent = null;
41 this.children = null;
42 this.displayedChildren = null;
43 };
44 ColumnGroup.prototype.getParent = function () {
45 return this.parent;
46 };
47 ColumnGroup.prototype.setParent = function (parent) {
48 this.parent = parent;
49 };
50 ColumnGroup.prototype.getUniqueId = function () {
51 return ColumnGroup.createUniqueId(this.groupId, this.instanceId);
52 };
53 ColumnGroup.prototype.isEmptyGroup = function () {
54 return this.displayedChildren.length === 0;
55 };
56 ColumnGroup.prototype.isMoving = function () {
57 var allLeafColumns = this.getOriginalColumnGroup().getLeafColumns();
58 if (!allLeafColumns || allLeafColumns.length === 0) {
59 return false;
60 }
61 var allMoving = true;
62 allLeafColumns.forEach(function (col) {
63 if (!col.isMoving()) {
64 allMoving = false;
65 }
66 });
67 return allMoving;
68 };
69 ColumnGroup.prototype.checkLeft = function () {
70 // first get all children to setLeft, as it impacts our decision below
71 this.displayedChildren.forEach(function (child) {
72 if (child instanceof ColumnGroup) {
73 child.checkLeft();
74 }
75 });
76 // set our left based on first displayed column
77 if (this.displayedChildren.length > 0) {
78 if (this.gridOptionsWrapper.isEnableRtl()) {
79 var lastChild = this.displayedChildren[this.displayedChildren.length - 1];
80 var lastChildLeft = lastChild.getLeft();
81 this.setLeft(lastChildLeft);
82 }
83 else {
84 var firstChildLeft = this.displayedChildren[0].getLeft();
85 this.setLeft(firstChildLeft);
86 }
87 }
88 else {
89 // this should never happen, as if we have no displayed columns, then
90 // this groups should not even exist.
91 this.setLeft(null);
92 }
93 };
94 ColumnGroup.prototype.getLeft = function () {
95 return this.left;
96 };
97 ColumnGroup.prototype.getOldLeft = function () {
98 return this.oldLeft;
99 };
100 ColumnGroup.prototype.setLeft = function (left) {
101 this.oldLeft = left;
102 if (this.left !== left) {
103 this.left = left;
104 this.localEventService.dispatchEvent(this.createAgEvent(ColumnGroup.EVENT_LEFT_CHANGED));
105 }
106 };
107 ColumnGroup.prototype.createAgEvent = function (type) {
108 return {
109 type: type,
110 };
111 };
112 ColumnGroup.prototype.addEventListener = function (eventType, listener) {
113 this.localEventService.addEventListener(eventType, listener);
114 };
115 ColumnGroup.prototype.removeEventListener = function (eventType, listener) {
116 this.localEventService.removeEventListener(eventType, listener);
117 };
118 ColumnGroup.prototype.getGroupId = function () {
119 return this.groupId;
120 };
121 ColumnGroup.prototype.getInstanceId = function () {
122 return this.instanceId;
123 };
124 ColumnGroup.prototype.isChildInThisGroupDeepSearch = function (wantedChild) {
125 var result = false;
126 this.children.forEach(function (foundChild) {
127 if (wantedChild === foundChild) {
128 result = true;
129 }
130 if (foundChild instanceof ColumnGroup) {
131 if (foundChild.isChildInThisGroupDeepSearch(wantedChild)) {
132 result = true;
133 }
134 }
135 });
136 return result;
137 };
138 ColumnGroup.prototype.getActualWidth = function () {
139 var groupActualWidth = 0;
140 if (this.displayedChildren) {
141 this.displayedChildren.forEach(function (child) {
142 groupActualWidth += child.getActualWidth();
143 });
144 }
145 return groupActualWidth;
146 };
147 ColumnGroup.prototype.isResizable = function () {
148 if (!this.displayedChildren) {
149 return false;
150 }
151 // if at least one child is resizable, then the group is resizable
152 var result = false;
153 this.displayedChildren.forEach(function (child) {
154 if (child.isResizable()) {
155 result = true;
156 }
157 });
158 return result;
159 };
160 ColumnGroup.prototype.getMinWidth = function () {
161 var result = 0;
162 this.displayedChildren.forEach(function (groupChild) {
163 result += groupChild.getMinWidth();
164 });
165 return result;
166 };
167 ColumnGroup.prototype.addChild = function (child) {
168 if (!this.children) {
169 this.children = [];
170 }
171 this.children.push(child);
172 };
173 ColumnGroup.prototype.getDisplayedChildren = function () {
174 return this.displayedChildren;
175 };
176 ColumnGroup.prototype.getLeafColumns = function () {
177 var result = [];
178 this.addLeafColumns(result);
179 return result;
180 };
181 ColumnGroup.prototype.getDisplayedLeafColumns = function () {
182 var result = [];
183 this.addDisplayedLeafColumns(result);
184 return result;
185 };
186 // why two methods here doing the same thing?
187 ColumnGroup.prototype.getDefinition = function () {
188 return this.originalColumnGroup.getColGroupDef();
189 };
190 ColumnGroup.prototype.getColGroupDef = function () {
191 return this.originalColumnGroup.getColGroupDef();
192 };
193 ColumnGroup.prototype.isPadding = function () {
194 return this.originalColumnGroup.isPadding();
195 };
196 ColumnGroup.prototype.isExpandable = function () {
197 return this.originalColumnGroup.isExpandable();
198 };
199 ColumnGroup.prototype.isExpanded = function () {
200 return this.originalColumnGroup.isExpanded();
201 };
202 ColumnGroup.prototype.setExpanded = function (expanded) {
203 this.originalColumnGroup.setExpanded(expanded);
204 };
205 ColumnGroup.prototype.addDisplayedLeafColumns = function (leafColumns) {
206 this.displayedChildren.forEach(function (child) {
207 if (child instanceof column_1.Column) {
208 leafColumns.push(child);
209 }
210 else if (child instanceof ColumnGroup) {
211 child.addDisplayedLeafColumns(leafColumns);
212 }
213 });
214 };
215 ColumnGroup.prototype.addLeafColumns = function (leafColumns) {
216 this.children.forEach(function (child) {
217 if (child instanceof column_1.Column) {
218 leafColumns.push(child);
219 }
220 else if (child instanceof ColumnGroup) {
221 child.addLeafColumns(leafColumns);
222 }
223 });
224 };
225 ColumnGroup.prototype.getChildren = function () {
226 return this.children;
227 };
228 ColumnGroup.prototype.getColumnGroupShow = function () {
229 return this.originalColumnGroup.getColumnGroupShow();
230 };
231 ColumnGroup.prototype.getOriginalColumnGroup = function () {
232 return this.originalColumnGroup;
233 };
234 ColumnGroup.prototype.calculateDisplayedColumns = function () {
235 var _this = this;
236 // clear out last time we calculated
237 this.displayedChildren = [];
238 // it not expandable, everything is visible
239 if (!this.originalColumnGroup.isExpandable()) {
240 this.displayedChildren = this.children;
241 }
242 else {
243 // and calculate again
244 this.children.forEach(function (abstractColumn) {
245 var headerGroupShow = abstractColumn.getColumnGroupShow();
246 switch (headerGroupShow) {
247 case ColumnGroup.HEADER_GROUP_SHOW_OPEN:
248 // when set to open, only show col if group is open
249 if (_this.originalColumnGroup.isExpanded()) {
250 _this.displayedChildren.push(abstractColumn);
251 }
252 break;
253 case ColumnGroup.HEADER_GROUP_SHOW_CLOSED:
254 // when set to open, only show col if group is open
255 if (!_this.originalColumnGroup.isExpanded()) {
256 _this.displayedChildren.push(abstractColumn);
257 }
258 break;
259 default:
260 // default is always show the column
261 _this.displayedChildren.push(abstractColumn);
262 break;
263 }
264 });
265 }
266 this.localEventService.dispatchEvent(this.createAgEvent(ColumnGroup.EVENT_DISPLAYED_CHILDREN_CHANGED));
267 };
268 ColumnGroup.HEADER_GROUP_SHOW_OPEN = 'open';
269 ColumnGroup.HEADER_GROUP_SHOW_CLOSED = 'closed';
270 ColumnGroup.EVENT_LEFT_CHANGED = 'leftChanged';
271 ColumnGroup.EVENT_DISPLAYED_CHILDREN_CHANGED = 'displayedChildrenChanged';
272 __decorate([
273 context_1.Autowired('gridOptionsWrapper'),
274 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
275 ], ColumnGroup.prototype, "gridOptionsWrapper", void 0);
276 __decorate([
277 context_1.Autowired('columnApi'),
278 __metadata("design:type", columnApi_1.ColumnApi)
279 ], ColumnGroup.prototype, "columnApi", void 0);
280 __decorate([
281 context_1.Autowired('gridApi'),
282 __metadata("design:type", gridApi_1.GridApi)
283 ], ColumnGroup.prototype, "gridApi", void 0);
284 return ColumnGroup;
285}());
286exports.ColumnGroup = ColumnGroup;