-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
gridOptionsWrapper.ts
409 lines (363 loc) · 22.2 KB
/
gridOptionsWrapper.ts
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import {RowNode} from "./entities/rowNode";
import {
GridOptions,
NodeChildDetails,
GetContextMenuItems,
GetMainMenuItems,
ProcessRowParams,
ProcessCellForExportParams, GetRowNodeIdFunc
} from "./entities/gridOptions";
import {EventService} from "./eventService";
import {Constants} from "./constants";
import {ComponentUtil} from "./components/componentUtil";
import {GridApi} from "./gridApi";
import {ColDef, IAggFunc, ColGroupDef} from "./entities/colDef";
import {Bean, Qualifier, Autowired, PostConstruct, PreDestroy} from "./context/context";
import {ColumnController, ColumnApi} from "./columnController/columnController";
import {Events} from "./events";
import {Utils as _} from "./utils";
import {IViewportDatasource} from "./interfaces/iViewportDatasource";
import {ICellRendererFunc, ICellRenderer} from "./rendering/cellRenderers/iCellRenderer";
import {Logger, LoggerFactory} from "./logger";
import {IFrameworkFactory} from "./interfaces/iFrameworkFactory";
var DEFAULT_ROW_HEIGHT = 25;
var DEFAULT_VIEWPORT_ROW_MODEL_PAGE_SIZE = 5;
var DEFAULT_VIEWPORT_ROW_MODEL_BUFFER_SIZE = 5;
function isTrue(value: any): boolean {
return value === true || value === 'true';
}
function positiveNumberOrZero(value: any, defaultValue: number): number {
if (value > 0) {
return value;
} else {
// zero gets returned if number is missing or the wrong type
return defaultValue;
}
}
@Bean('gridOptionsWrapper')
export class GridOptionsWrapper {
private static MIN_COL_WIDTH = 10;
public static PROP_HEADER_HEIGHT = 'headerHeight';
@Autowired('gridOptions') private gridOptions: GridOptions;
@Autowired('columnController') private columnController: ColumnController;
@Autowired('eventService') private eventService: EventService;
@Autowired('enterprise') private enterprise: boolean;
@Autowired('frameworkFactory') private frameworkFactory: IFrameworkFactory;
private propertyEventService: EventService = new EventService();
private fullWidthCellRenderer : {new(): ICellRenderer} | ICellRendererFunc | string;
private groupRowRenderer : {new(): ICellRenderer} | ICellRendererFunc | string;
private groupRowInnerRenderer : {new(): ICellRenderer} | ICellRendererFunc | string;
private agWire(@Qualifier('gridApi') gridApi: GridApi, @Qualifier('columnApi') columnApi: ColumnApi): void {
this.gridOptions.api = gridApi;
this.gridOptions.columnApi = columnApi;
this.checkForDeprecated();
}
@PreDestroy
private destroy(): void {
// need to remove these, as we don't own the lifecycle of the gridOptions, we need to
// remove the references in case the user keeps the grid options, we want the rest
// of the grid to be picked up by the garbage collector
this.gridOptions.api = null;
this.gridOptions.columnApi = null;
}
@PostConstruct
public init(): void {
this.eventService.addGlobalListener(this.globalEventHandler.bind(this));
this.setupCellRenderers();
if (this.isGroupSelectsChildren() && this.isSuppressParentsInRowNodes()) {
console.warn('ag-Grid: groupSelectsChildren does not work wth suppressParentsInRowNodes, this selection method needs the part in rowNode to work');
}
if (this.isGroupSelectsChildren() && !this.isRowSelectionMulti()) {
console.warn('ag-Grid: rowSelectionMulti must be true for groupSelectsChildren to make sense');
}
}
private setupCellRenderers(): void {
this.fullWidthCellRenderer = this.frameworkFactory.gridOptionsFullWidthCellRenderer(this.gridOptions);
this.groupRowRenderer = this.frameworkFactory.gridOptionsGroupRowRenderer(this.gridOptions);
this.groupRowInnerRenderer = this.frameworkFactory.gridOptionsGroupRowInnerRenderer(this.gridOptions);
}
// the cellRenderers come from the instances for this class, not from gridOptions, which allows
// the baseFrameworkFactory to replace with framework specific ones
public getFullWidthCellRenderer(): {new(): ICellRenderer} | ICellRendererFunc | string { return this.fullWidthCellRenderer; }
public getGroupRowRenderer(): {new(): ICellRenderer} | ICellRendererFunc | string { return this.groupRowRenderer; }
public getGroupRowInnerRenderer(): {new(): ICellRenderer} | ICellRendererFunc | string { return this.groupRowInnerRenderer; }
public isEnterprise() { return this.enterprise;}
public isRowSelection() { return this.gridOptions.rowSelection === "single" || this.gridOptions.rowSelection === "multiple"; }
public isRowDeselection() { return isTrue(this.gridOptions.rowDeselection); }
public isRowSelectionMulti() { return this.gridOptions.rowSelection === 'multiple'; }
public getContext() { return this.gridOptions.context; }
public isPivotMode() { return isTrue(this.gridOptions.pivotMode); }
public isRowModelPagination() { return this.gridOptions.rowModelType === Constants.ROW_MODEL_TYPE_PAGINATION; }
public isRowModelVirtual() { return this.gridOptions.rowModelType === Constants.ROW_MODEL_TYPE_VIRTUAL; }
public isRowModelViewport() { return this.gridOptions.rowModelType === Constants.ROW_MODEL_TYPE_VIEWPORT; }
public isRowModelDefault() { return !(this.isRowModelPagination() || this.isRowModelVirtual() || this.isRowModelViewport()); }
public isFullRowEdit() { return this.gridOptions.editType === 'fullRow'; }
public isSuppressFocusAfterRefresh() { return isTrue(this.gridOptions.suppressFocusAfterRefresh); }
public isShowToolPanel() { return isTrue(this.gridOptions.showToolPanel); }
public isToolPanelSuppressRowGroups() { return isTrue(this.gridOptions.toolPanelSuppressRowGroups); }
public isToolPanelSuppressValues() { return isTrue(this.gridOptions.toolPanelSuppressValues); }
public isToolPanelSuppressPivots() { return isTrue(this.gridOptions.toolPanelSuppressPivots); }
public isToolPanelSuppressPivotMode() { return isTrue(this.gridOptions.toolPanelSuppressPivotMode); }
public isEnableCellChangeFlash() { return isTrue(this.gridOptions.enableCellChangeFlash); }
public isGroupSelectsChildren() { return isTrue(this.gridOptions.groupSelectsChildren); }
public isGroupIncludeFooter() { return isTrue(this.gridOptions.groupIncludeFooter); }
public isGroupSuppressBlankHeader() { return isTrue(this.gridOptions.groupSuppressBlankHeader); }
public isSuppressRowClickSelection() { return isTrue(this.gridOptions.suppressRowClickSelection); }
public isSuppressCellSelection() { return isTrue(this.gridOptions.suppressCellSelection); }
public isSuppressMultiSort() { return isTrue(this.gridOptions.suppressMultiSort); }
public isGroupSuppressAutoColumn() { return isTrue(this.gridOptions.groupSuppressAutoColumn); }
public isSuppressDragLeaveHidesColumns() { return isTrue(this.gridOptions.suppressDragLeaveHidesColumns); }
public isForPrint() { return isTrue(this.gridOptions.forPrint); }
public isSuppressHorizontalScroll() { return isTrue(this.gridOptions.suppressHorizontalScroll); }
public isSuppressLoadingOverlay() { return isTrue(this.gridOptions.suppressLoadingOverlay); }
public isSuppressNoRowsOverlay() { return isTrue(this.gridOptions.suppressNoRowsOverlay); }
public isSuppressFieldDotNotation() { return isTrue(this.gridOptions.suppressFieldDotNotation); }
public getFloatingTopRowData(): any[] { return this.gridOptions.floatingTopRowData; }
public getFloatingBottomRowData(): any[] { return this.gridOptions.floatingBottomRowData; }
public isFunctionsPassive() { return isTrue(this.gridOptions.functionsPassive); }
public getQuickFilterText(): string { return this.gridOptions.quickFilterText; }
public isUnSortIcon() { return isTrue(this.gridOptions.unSortIcon); }
public isSuppressMenuHide() { return isTrue(this.gridOptions.suppressMenuHide); }
public getRowStyle() { return this.gridOptions.rowStyle; }
public getRowClass() { return this.gridOptions.rowClass; }
public getRowStyleFunc() { return this.gridOptions.getRowStyle; }
public getRowClassFunc() { return this.gridOptions.getRowClass; }
public getDoesDataFlowerFunc(): (data: any)=>boolean { return this.gridOptions.doesDataFlower; }
public getIsFullWidthCellFunc(): (rowNode: RowNode)=> boolean { return this.gridOptions.isFullWidthCell; }
public getFullWidthCellRendererParams() { return this.gridOptions.fullWidthCellRendererParams; }
public getBusinessKeyForNodeFunc() { return this.gridOptions.getBusinessKeyForNode; }
public getHeaderCellRenderer() { return this.gridOptions.headerCellRenderer; }
public getApi(): GridApi { return this.gridOptions.api; }
public getColumnApi(): ColumnApi { return this.gridOptions.columnApi; }
public isEnableColResize() { return isTrue(this.gridOptions.enableColResize); }
public isSingleClickEdit() { return isTrue(this.gridOptions.singleClickEdit); }
public getGroupDefaultExpanded(): number { return this.gridOptions.groupDefaultExpanded; }
public getAutoSizePadding(): number { return this.gridOptions.autoSizePadding; }
public getMaxConcurrentDatasourceRequests(): number { return this.gridOptions.maxConcurrentDatasourceRequests; }
public getMaxPagesInCache(): number { return this.gridOptions.maxPagesInCache; }
public getPaginationOverflowSize(): number { return this.gridOptions.paginationOverflowSize; }
public getPaginationPageSize(): number { return this.gridOptions.paginationPageSize; }
public getPaginationInitialRowCount(): number { return this.gridOptions.paginationInitialRowCount; }
public getRowData(): any[] { return this.gridOptions.rowData; }
public isGroupUseEntireRow() { return isTrue(this.gridOptions.groupUseEntireRow); }
public getGroupColumnDef(): ColDef { return this.gridOptions.groupColumnDef; }
public isGroupSuppressRow() { return isTrue(this.gridOptions.groupSuppressRow); }
public getRowGroupPanelShow() { return this.gridOptions.rowGroupPanelShow; }
public getPivotPanelShow() { return this.gridOptions.pivotPanelShow; }
public isAngularCompileRows() { return isTrue(this.gridOptions.angularCompileRows); }
public isAngularCompileFilters() { return isTrue(this.gridOptions.angularCompileFilters); }
public isAngularCompileHeaders() { return isTrue(this.gridOptions.angularCompileHeaders); }
public isDebug() { return isTrue(this.gridOptions.debug); }
public getColumnDefs() { return this.gridOptions.columnDefs; }
public getDatasource() { return this.gridOptions.datasource; }
public getViewportDatasource(): IViewportDatasource { return this.gridOptions.viewportDatasource; }
public isEnableSorting() { return isTrue(this.gridOptions.enableSorting) || isTrue(this.gridOptions.enableServerSideSorting); }
public isEnableCellExpressions() { return isTrue(this.gridOptions.enableCellExpressions); }
public isSuppressMiddleClickScrolls() { return isTrue(this.gridOptions.suppressMiddleClickScrolls); }
public isSuppressPreventDefaultOnMouseWheel() { return isTrue(this.gridOptions.suppressPreventDefaultOnMouseWheel); }
public isEnableServerSideSorting() { return isTrue(this.gridOptions.enableServerSideSorting); }
public isSuppressColumnVirtualisation() { return isTrue(this.gridOptions.suppressColumnVirtualisation); }
public isSuppressContextMenu() { return isTrue(this.gridOptions.suppressContextMenu); }
public isSuppressCopyRowsToClipboard() { return isTrue(this.gridOptions.suppressCopyRowsToClipboard); }
public isEnableFilter() { return isTrue(this.gridOptions.enableFilter) || isTrue(this.gridOptions.enableServerSideFilter); }
public isEnableServerSideFilter() { return this.gridOptions.enableServerSideFilter; }
public isSuppressScrollLag() { return isTrue(this.gridOptions.suppressScrollLag); }
public isSuppressMovableColumns() { return isTrue(this.gridOptions.suppressMovableColumns); }
public isSuppressColumnMoveAnimation() { return isTrue(this.gridOptions.suppressColumnMoveAnimation); }
public isSuppressMenuColumnPanel() { return isTrue(this.gridOptions.suppressMenuColumnPanel); }
public isSuppressMenuFilterPanel() { return isTrue(this.gridOptions.suppressMenuFilterPanel); }
public isSuppressUseColIdForGroups() { return isTrue(this.gridOptions.suppressUseColIdForGroups); }
public isSuppressAggFuncInHeader() { return isTrue(this.gridOptions.suppressAggFuncInHeader); }
public isSuppressMenuMainPanel() { return isTrue(this.gridOptions.suppressMenuMainPanel); }
public isEnableRangeSelection(): boolean { return isTrue(this.gridOptions.enableRangeSelection); }
public isRememberGroupStateWhenNewData(): boolean { return isTrue(this.gridOptions.rememberGroupStateWhenNewData); }
public getIcons() { return this.gridOptions.icons; }
public getAggFuncs(): {[key: string]: IAggFunc} { return this.gridOptions.aggFuncs; }
public getIsScrollLag() { return this.gridOptions.isScrollLag; }
public getSortingOrder(): string[] { return this.gridOptions.sortingOrder; }
public getSlaveGrids(): GridOptions[] { return this.gridOptions.slaveGrids; }
public getGroupRowRendererParams() { return this.gridOptions.groupRowRendererParams; }
public getOverlayLoadingTemplate() { return this.gridOptions.overlayLoadingTemplate; }
public getOverlayNoRowsTemplate() { return this.gridOptions.overlayNoRowsTemplate; }
public getCheckboxSelection(): (params: any)=>boolean { return this.gridOptions.checkboxSelection; }
public isSuppressAutoSize() { return isTrue(this.gridOptions.suppressAutoSize); }
public isSuppressParentsInRowNodes() { return isTrue(this.gridOptions.suppressParentsInRowNodes); }
public isEnableStatusBar() { return isTrue(this.gridOptions.enableStatusBar); }
public isFunctionsReadOnly() { return isTrue(this.gridOptions.functionsReadOnly); }
public getDefaultColDef(): ColDef { return this.gridOptions.defaultColDef; }
public getDefaultColGroupDef(): ColGroupDef { return this.gridOptions.defaultColGroupDef; }
public getHeaderCellTemplate() { return this.gridOptions.headerCellTemplate; }
public getHeaderCellTemplateFunc() { return this.gridOptions.getHeaderCellTemplate; }
public getNodeChildDetailsFunc(): ((dataItem: any)=> NodeChildDetails) { return this.gridOptions.getNodeChildDetails; }
public getGroupRowAggNodesFunc() { return this.gridOptions.groupRowAggNodes; }
public getContextMenuItemsFunc(): GetContextMenuItems { return this.gridOptions.getContextMenuItems; }
public getMainMenuItemsFunc(): GetMainMenuItems { return this.gridOptions.getMainMenuItems; }
public getRowNodeIdFunc(): GetRowNodeIdFunc { return this.gridOptions.getRowNodeId; }
public getProcessSecondaryColDefFunc(): (colDef: ColDef)=>void { return this.gridOptions.processSecondaryColDef; }
public getProcessSecondaryColGroupDefFunc(): (colGroupDef: ColGroupDef)=>void { return this.gridOptions.processSecondaryColGroupDef; }
public getProcessCellForClipboardFunc(): (params: ProcessCellForExportParams)=>any { return this.gridOptions.processCellForClipboard; }
public getViewportRowModelPageSize(): number { return positiveNumberOrZero(this.gridOptions.viewportRowModelPageSize, DEFAULT_VIEWPORT_ROW_MODEL_PAGE_SIZE); }
public getViewportRowModelBufferSize(): number { return positiveNumberOrZero(this.gridOptions.viewportRowModelBufferSize, DEFAULT_VIEWPORT_ROW_MODEL_BUFFER_SIZE); }
// public getCellRenderers(): {[key: string]: {new(): ICellRenderer} | ICellRendererFunc} { return this.gridOptions.cellRenderers; }
// public getCellEditors(): {[key: string]: {new(): ICellEditor}} { return this.gridOptions.cellEditors; }
public setProperty(key: string, value: any): void {
var gridOptionsNoType = <any> this.gridOptions;
var previousValue = gridOptionsNoType[key];
gridOptionsNoType[key] = value;
this.propertyEventService.dispatchEvent(key, {currentValue: value, previousValue: previousValue});
}
public addEventListener(key: string, listener: Function): void {
this.propertyEventService.addEventListener(key, listener);
}
public removeEventListener(key: string, listener: Function): void {
this.propertyEventService.removeEventListener(key, listener);
}
public executeProcessRowPostCreateFunc(params: ProcessRowParams): void {
if (this.gridOptions.processRowPostCreate) {
this.gridOptions.processRowPostCreate(params);
}
}
// properties
public getHeaderHeight(): number {
if (typeof this.gridOptions.headerHeight === 'number') {
return this.gridOptions.headerHeight;
} else {
return 25;
}
}
public isExternalFilterPresent() {
if (typeof this.gridOptions.isExternalFilterPresent === 'function') {
return this.gridOptions.isExternalFilterPresent();
} else {
return false;
}
}
public doesExternalFilterPass(node: RowNode) {
if (typeof this.gridOptions.doesExternalFilterPass === 'function') {
return this.gridOptions.doesExternalFilterPass(node);
} else {
return false;
}
}
public getLayoutInterval(): number {
if (typeof this.gridOptions.layoutInterval === 'number') {
return this.gridOptions.layoutInterval;
} else {
return Constants.LAYOUT_INTERVAL;
}
}
public getMinColWidth() {
if (this.gridOptions.minColWidth > GridOptionsWrapper.MIN_COL_WIDTH) {
return this.gridOptions.minColWidth;
} else {
return GridOptionsWrapper.MIN_COL_WIDTH;
}
}
public getMaxColWidth() {
if (this.gridOptions.maxColWidth > GridOptionsWrapper.MIN_COL_WIDTH) {
return this.gridOptions.maxColWidth;
} else {
return null;
}
}
public getColWidth() {
if (typeof this.gridOptions.colWidth !== 'number' || this.gridOptions.colWidth < GridOptionsWrapper.MIN_COL_WIDTH) {
return 200;
} else {
return this.gridOptions.colWidth;
}
}
public getRowBuffer() {
if (typeof this.gridOptions.rowBuffer === 'number') {
if (this.gridOptions.rowBuffer < 0) {
console.warn('ag-Grid: rowBuffer should not be negative')
}
return this.gridOptions.rowBuffer;
} else {
return Constants.ROW_BUFFER_SIZE;
}
}
private checkForDeprecated() {
// casting to generic object, so typescript compiles even though
// we are looking for attributes that don't exist
var options: any = this.gridOptions;
if (options.suppressUnSort) {
console.warn('ag-grid: as of v1.12.4 suppressUnSort is not used. Please use sortOrder instead.');
}
if (options.suppressDescSort) {
console.warn('ag-grid: as of v1.12.4 suppressDescSort is not used. Please use sortOrder instead.');
}
if (options.groupAggFields) {
console.warn('ag-grid: as of v3 groupAggFields is not used. Please add appropriate agg fields to your columns.');
}
if (options.groupHidePivotColumns) {
console.warn('ag-grid: as of v3 groupHidePivotColumns is not used as pivot columns are now called rowGroup columns. Please refer to the documentation');
}
if (options.groupKeys) {
console.warn('ag-grid: as of v3 groupKeys is not used. You need to set rowGroupIndex on the columns to group. Please refer to the documentation');
}
if (options.ready || options.onReady) {
console.warn('ag-grid: as of v3.3 ready event is now called gridReady, so the callback should be onGridReady');
}
if (typeof options.groupDefaultExpanded === 'boolean') {
console.warn('ag-grid: groupDefaultExpanded can no longer be boolean. for groupDefaultExpanded=true, use groupDefaultExpanded=9999 instead, to expand all the groups');
}
if (options.onRowDeselected || options.rowDeselected) {
console.warn('ag-grid: since version 3.4 event rowDeselected no longer exists, please check the docs');
}
if (options.rowsAlreadyGrouped) {
console.warn('ag-grid: since version 3.4 rowsAlreadyGrouped no longer exists, please use getNodeChildDetails() instead');
}
if (options.groupAggFunction) {
console.warn('ag-grid: since version 4.3.x groupAggFunction is now called groupRowAggNodes');
}
}
public getLocaleTextFunc() {
if (this.gridOptions.localeTextFunc) {
return this.gridOptions.localeTextFunc;
}
var that = this;
return function (key: any, defaultValue: any) {
var localeText = that.gridOptions.localeText;
if (localeText && localeText[key]) {
return localeText[key];
} else {
return defaultValue;
}
};
}
// responsible for calling the onXXX functions on gridOptions
public globalEventHandler(eventName: string, event?: any): void {
var callbackMethodName = ComponentUtil.getCallbackForEvent(eventName);
if (typeof (<any>this.gridOptions)[callbackMethodName] === 'function') {
(<any>this.gridOptions)[callbackMethodName](event);
}
}
// we don't allow dynamic row height for virtual paging
public getRowHeightAsNumber(): number {
var rowHeight = this.gridOptions.rowHeight;
if (_.missing(rowHeight)) {
return DEFAULT_ROW_HEIGHT;
} else if (typeof this.gridOptions.rowHeight === 'number') {
return this.gridOptions.rowHeight;
} else {
console.warn('ag-Grid row height must be a number if not using standard row model');
return DEFAULT_ROW_HEIGHT;
}
}
public getRowHeightForNode(rowNode: RowNode): number {
if (typeof this.gridOptions.rowHeight === 'number') {
return this.gridOptions.rowHeight;
} else if (typeof this.gridOptions.getRowHeight === 'function') {
var params = {
node: rowNode,
data: rowNode.data,
api: this.gridOptions.api,
context: this.gridOptions.context
};
return this.gridOptions.getRowHeight(params);
} else {
return DEFAULT_ROW_HEIGHT;
}
}
}