UNPKG

46.4 kBPlain TextView Raw
1import {RowNode} from "./entities/rowNode";
2import {
3 GetContextMenuItems,
4 GetMainMenuItems,
5 GetRowNodeIdFunc,
6 GridOptions,
7 IsRowMaster,
8 IsRowSelectable,
9 NavigateToNextCellParams,
10 NodeChildDetails,
11 PaginationNumberFormatterParams,
12 PostProcessPopupParams, ProcessDataFromClipboardParams,
13 TabToNextCellParams
14} from "./entities/gridOptions";
15import {EventService} from "./eventService";
16import {Constants} from "./constants";
17import {ComponentUtil} from "./components/componentUtil";
18import {GridApi} from "./gridApi";
19import {ColDef, ColGroupDef, IAggFunc} from "./entities/colDef";
20import {Autowired, Bean, PostConstruct, PreDestroy, Qualifier} from "./context/context";
21import {ColumnApi} from "./columnController/columnApi";
22import {ColumnController} from "./columnController/columnController";
23import {Utils as _} from "./utils";
24import {IViewportDatasource} from "./interfaces/iViewportDatasource";
25import {IFrameworkFactory} from "./interfaces/iFrameworkFactory";
26import {IDatasource} from "./rowModels/iDatasource";
27import {GridCellDef} from "./entities/gridCell";
28import {IServerSideDatasource} from "./interfaces/iServerSideDatasource";
29import {BaseExportParams, ProcessCellForExportParams, ProcessHeaderForExportParams} from "./exportParams";
30import {AgEvent} from "./events";
31import {Environment} from "./environment";
32import {PropertyKeys} from "./propertyKeys";
33import {ColDefUtil} from "./components/colDefUtil";
34import {Events} from "./eventKeys";
35import {AutoHeightCalculator} from "./rendering/autoHeightCalculator";
36
37let DEFAULT_ROW_HEIGHT = 25;
38let DEFAULT_DETAIL_ROW_HEIGHT = 300;
39let DEFAULT_VIEWPORT_ROW_MODEL_PAGE_SIZE = 5;
40let DEFAULT_VIEWPORT_ROW_MODEL_BUFFER_SIZE = 5;
41
42let legacyThemes = [
43 'ag-fresh',
44 'ag-bootstrap',
45 'ag-blue',
46 'ag-dark',
47 'ag-material'
48];
49
50function isTrue(value: any): boolean {
51 return value === true || value === 'true';
52}
53
54function zeroOrGreater(value: any, defaultValue: number): number {
55 if (value >= 0) {
56 return value;
57 } else {
58 // zero gets returned if number is missing or the wrong type
59 return defaultValue;
60 }
61}
62
63function oneOrGreater(value: any, defaultValue: number): number {
64 if (value > 0) {
65 return value;
66 } else {
67 // zero gets returned if number is missing or the wrong type
68 return defaultValue;
69 }
70}
71
72export interface PropertyChangedEvent extends AgEvent {
73 currentValue: any;
74 previousValue: any;
75}
76
77@Bean('gridOptionsWrapper')
78export class GridOptionsWrapper {
79
80 private static MIN_COL_WIDTH = 10;
81
82 public static PROP_HEADER_HEIGHT = 'headerHeight';
83 public static PROP_GROUP_REMOVE_SINGLE_CHILDREN = 'groupRemoveSingleChildren';
84 public static PROP_GROUP_REMOVE_LOWEST_SINGLE_CHILDREN = 'groupRemoveLowestSingleChildren';
85 public static PROP_PIVOT_HEADER_HEIGHT = 'pivotHeaderHeight';
86 public static PROP_SUPPRESS_CLIPBOARD_PASTE = 'suppressClipboardPaste';
87
88 public static PROP_GROUP_HEADER_HEIGHT = 'groupHeaderHeight';
89 public static PROP_PIVOT_GROUP_HEADER_HEIGHT = 'pivotGroupHeaderHeight';
90
91 public static PROP_FLOATING_FILTERS_HEIGHT = 'floatingFiltersHeight';
92
93 public static PROP_SUPPRESS_ROW_DRAG = 'suppressRowDrag';
94 public static PROP_POPUP_PARENT = 'popupParent';
95
96 public static PROP_GRID_AUTO_HEIGHT = 'gridAutoHeight';
97
98 @Autowired('gridOptions') private gridOptions: GridOptions;
99 @Autowired('columnController') private columnController: ColumnController;
100 @Autowired('eventService') private eventService: EventService;
101 @Autowired('enterprise') private enterprise: boolean;
102 @Autowired('frameworkFactory') private frameworkFactory: IFrameworkFactory;
103 @Autowired('gridApi') private gridApi: GridApi;
104 @Autowired('columnApi') private columnApi: ColumnApi;
105 @Autowired('environment') private environment: Environment;
106 @Autowired('autoHeightCalculator') private autoHeightCalculator: AutoHeightCalculator;
107
108 private propertyEventService: EventService = new EventService();
109
110 private domDataKey = '__AG_'+Math.random().toString();
111
112 private layoutElements: HTMLElement[] = [];
113
114 private agWire(@Qualifier('gridApi') gridApi: GridApi, @Qualifier('columnApi') columnApi: ColumnApi): void {
115 this.gridOptions.api = gridApi;
116 this.gridOptions.columnApi = columnApi;
117 this.checkForDeprecated();
118 }
119
120 @PreDestroy
121 private destroy(): void {
122 // need to remove these, as we don't own the lifecycle of the gridOptions, we need to
123 // remove the references in case the user keeps the grid options, we want the rest
124 // of the grid to be picked up by the garbage collector
125 this.gridOptions.api = null;
126 this.gridOptions.columnApi = null;
127 }
128
129 @PostConstruct
130 public init(): void {
131
132 if (! (this.gridOptions.suppressPropertyNamesCheck === true)) {
133 this.checkGridOptionsProperties();
134 this.checkColumnDefProperties();
135 }
136
137 let async = this.useAsyncEvents();
138 this.eventService.addGlobalListener(this.globalEventHandler.bind(this), async);
139
140 if (this.isGroupSelectsChildren() && this.isSuppressParentsInRowNodes()) {
141 console.warn('ag-Grid: groupSelectsChildren does not work wth suppressParentsInRowNodes, this selection method needs the part in rowNode to work');
142 }
143
144 if (this.isGroupSelectsChildren()) {
145 if (!this.isRowSelectionMulti()) {
146 console.warn(`ag-Grid: rowSelection must be 'multiple' for groupSelectsChildren to make sense`);
147 }
148 if (this.isRowModelServerSide()) {
149 console.warn('ag-Grid: group selects children is NOT support for Server Side Row Model. ' +
150 'This is because the rows are lazy loaded, so selecting a group is not possible as' +
151 'the grid has no way of knowing what the children are.');
152 }
153 }
154
155 if (this.isGroupRemoveSingleChildren() && this.isGroupHideOpenParents()) {
156 console.warn('ag-Grid: groupRemoveSingleChildren and groupHideOpenParents do not work with each other, you need to pick one. And don\'t ask us how to us these together on our support forum either you will get the same answer!');
157 }
158
159 this.addEventListener(GridOptionsWrapper.PROP_GRID_AUTO_HEIGHT, this.updateLayoutClasses.bind(this));
160 }
161
162 private checkColumnDefProperties() {
163 if (this.gridOptions.columnDefs == null) return;
164
165 this.gridOptions.columnDefs.forEach(colDef=>{
166 let userProperties: string [] = Object.getOwnPropertyNames(colDef);
167 let validProperties: string [] = ColDefUtil.ALL_PROPERTIES.concat(ColDefUtil.FRAMEWORK_PROPERTIES);
168
169 this.checkProperties(
170 userProperties,
171 validProperties,
172 validProperties,
173 'colDef',
174 'https://www.ag-grid.com/javascript-grid-column-properties/'
175 );
176 })
177 }
178
179 private checkGridOptionsProperties() {
180 let userProperties: string [] = Object.getOwnPropertyNames(this.gridOptions);
181 let validProperties: string [] = PropertyKeys.ALL_PROPERTIES.concat(PropertyKeys.FRAMEWORK_PROPERTIES);
182 Object.keys(Events).forEach(it=>validProperties.push (ComponentUtil.getCallbackForEvent((<any>Events)[it])));
183 let validPropertiesAndExceptions: string [] = validProperties.concat('api', 'columnApi');
184
185 this.checkProperties(
186 userProperties,
187 validPropertiesAndExceptions,
188 validProperties,
189 'gridOptions',
190 'https://www.ag-grid.com/javascript-grid-properties/'
191 );
192 }
193
194
195 private checkProperties(
196 userProperties: string[],
197 validPropertiesAndExceptions: string[],
198 validProperties: string[],
199 containerName: string,
200 docsUrl: string
201 ) {
202 let invalidProperties: { [p: string]: string[] } = _.fuzzyCheckStrings(
203 userProperties,
204 validPropertiesAndExceptions,
205 validProperties
206 );
207
208 let invalidPropertyKeys = Object.keys(invalidProperties);
209 invalidPropertyKeys.forEach(invalidPropertyKey => {
210 let fuzzySuggestions: string[] = invalidProperties [invalidPropertyKey];
211 console.warn(`ag-grid: invalid ${containerName} property '${invalidPropertyKey}' did you mean any of these: ${fuzzySuggestions.slice(0, 8).join(",")}`)
212 });
213
214 if (invalidPropertyKeys.length > 0) {
215 console.warn(`ag-grid: to see all the valid ${containerName} properties please check: ${docsUrl}`)
216 }
217 }
218
219// returns the dom data, or undefined if not found
220 public getDomData(element: Node, key: string): any {
221 let domData = (<any>element)[this.domDataKey];
222 if (domData) {
223 return domData[key];
224 } else {
225 return undefined;
226 }
227 }
228
229 public setDomData(element: Element, key: string, value: any): any {
230 let domData = (<any>element)[this.domDataKey];
231 if (_.missing(domData)) {
232 domData = {};
233 (<any>element)[this.domDataKey] = domData;
234 }
235 domData[key] = value;
236 }
237
238 public isEnterprise() { return this.enterprise;}
239 public isRowSelection() { return this.gridOptions.rowSelection === "single" || this.gridOptions.rowSelection === "multiple"; }
240 public isRowDeselection() { return isTrue(this.gridOptions.rowDeselection); }
241 public isRowSelectionMulti() { return this.gridOptions.rowSelection === 'multiple'; }
242 public isRowMultiSelectWithClick() { return isTrue(this.gridOptions.rowMultiSelectWithClick); }
243 public getContext() { return this.gridOptions.context; }
244 public isPivotMode() { return isTrue(this.gridOptions.pivotMode); }
245 public isPivotTotals() { return isTrue(this.gridOptions.pivotTotals); }
246 public getPivotColumnGroupTotals() { return this.gridOptions.pivotColumnGroupTotals; }
247 public getPivotRowTotals() { return this.gridOptions.pivotRowTotals; }
248 public isRowModelInfinite() { return this.gridOptions.rowModelType === Constants.ROW_MODEL_TYPE_INFINITE; }
249 public isRowModelViewport() { return this.gridOptions.rowModelType === Constants.ROW_MODEL_TYPE_VIEWPORT; }
250 public isRowModelServerSide() { return this.gridOptions.rowModelType === Constants.ROW_MODEL_TYPE_SERVER_SIDE; }
251 public isRowModelDefault() {
252 return _.missing(this.gridOptions.rowModelType) ||
253 this.gridOptions.rowModelType === Constants.ROW_MODEL_TYPE_CLIENT_SIDE ||
254 this.gridOptions.rowModelType === Constants.DEPRECATED_ROW_MODEL_TYPE_NORMAL;
255 }
256
257 public isFullRowEdit() { return this.gridOptions.editType === 'fullRow'; }
258 public isSuppressFocusAfterRefresh() { return isTrue(this.gridOptions.suppressFocusAfterRefresh); }
259 public isShowToolPanel() { return isTrue(this.gridOptions.showToolPanel); }
260 public isToolPanelSuppressValues() { return isTrue(this.gridOptions.toolPanelSuppressValues); }
261 public isToolPanelSuppressPivots() {
262 // we don't allow pivots when doing tree data
263 return isTrue(this.gridOptions.toolPanelSuppressPivots) || this.isTreeData();
264 }
265 public isToolPanelSuppressRowGroups() {
266 // we don't allow row grouping when doing tree data
267 return isTrue(this.gridOptions.toolPanelSuppressRowGroups) || this.isTreeData();
268 }
269 public isToolPanelSuppressSideButtons() { return isTrue(this.gridOptions.toolPanelSuppressSideButtons); }
270 public isToolPanelSuppressPivotMode() { return isTrue(this.gridOptions.toolPanelSuppressPivotMode) || this.isTreeData();}
271 public isContractColumnSelection() { return isTrue(this.gridOptions.contractColumnSelection); }
272
273 public isToolPanelSuppressColumnFilter() { return isTrue(this.gridOptions.toolPanelSuppressColumnFilter); }
274 public isToolPanelSuppressColumnSelectAll() { return isTrue(this.gridOptions.toolPanelSuppressColumnSelectAll); }
275 public isToolPanelSuppressColumnExpandAll() { return isTrue(this.gridOptions.toolPanelSuppressColumnExpandAll); }
276
277 public isSuppressTouch() { return isTrue(this.gridOptions.suppressTouch); }
278 public isSuppressRowTransform() { return isTrue(this.gridOptions.suppressRowTransform); }
279 public useAsyncEvents() { return !isTrue(this.gridOptions.suppressAsyncEvents); }
280 public isEnableCellChangeFlash() { return isTrue(this.gridOptions.enableCellChangeFlash); }
281 public isGroupSelectsChildren() {
282 let result = isTrue(this.gridOptions.groupSelectsChildren);
283 if (result && this.isTreeData()) {
284 console.warn('ag-Grid: groupSelectsChildren does not work with tree data');
285 return false;
286 } else {
287 return result;
288 }
289 }
290
291 public isSuppressRowHoverHighlight() { return isTrue(this.gridOptions.suppressRowHoverHighlight); }
292 public isGroupSelectsFiltered() { return isTrue(this.gridOptions.groupSelectsFiltered); }
293 public isGroupHideOpenParents() { return isTrue(this.gridOptions.groupHideOpenParents); }
294 // if we are doing hideOpenParents, then we always have groupMultiAutoColumn, otherwise hideOpenParents would not work
295 public isGroupMultiAutoColumn() { return isTrue(this.gridOptions.groupMultiAutoColumn) || isTrue(this.gridOptions.groupHideOpenParents); }
296 public isGroupRemoveSingleChildren() { return isTrue(this.gridOptions.groupRemoveSingleChildren); }
297 public isGroupRemoveLowestSingleChildren() { return isTrue(this.gridOptions.groupRemoveLowestSingleChildren); }
298 public isGroupIncludeFooter() { return isTrue(this.gridOptions.groupIncludeFooter); }
299 public isGroupIncludeTotalFooter() { return isTrue(this.gridOptions.groupIncludeTotalFooter); }
300 public isGroupSuppressBlankHeader() { return isTrue(this.gridOptions.groupSuppressBlankHeader); }
301 public isSuppressRowClickSelection() { return isTrue(this.gridOptions.suppressRowClickSelection); }
302 public isSuppressCellSelection() { return isTrue(this.gridOptions.suppressCellSelection); }
303 public isSuppressMultiSort() { return isTrue(this.gridOptions.suppressMultiSort); }
304 public isMultiSortKeyCtrl() { return this.gridOptions.multiSortKey === 'ctrl'; }
305 public isGroupSuppressAutoColumn() { return isTrue(this.gridOptions.groupSuppressAutoColumn); }
306 public isSuppressDragLeaveHidesColumns() { return isTrue(this.gridOptions.suppressDragLeaveHidesColumns); }
307 public isSuppressScrollOnNewData() { return isTrue(this.gridOptions.suppressScrollOnNewData); }
308 public isRowDragManaged() { return isTrue(this.gridOptions.rowDragManaged); }
309 public isSuppressRowDrag() { return isTrue(this.gridOptions.suppressRowDrag); }
310
311 public isGridAutoHeight() { return isTrue(this.gridOptions.gridAutoHeight); }
312
313 public isSuppressHorizontalScroll() { return isTrue(this.gridOptions.suppressHorizontalScroll); }
314 public isSuppressLoadingOverlay() { return isTrue(this.gridOptions.suppressLoadingOverlay); }
315 public isSuppressNoRowsOverlay() { return isTrue(this.gridOptions.suppressNoRowsOverlay); }
316 public isSuppressFieldDotNotation() { return isTrue(this.gridOptions.suppressFieldDotNotation); }
317 public getPinnedTopRowData(): any[] { return this.gridOptions.pinnedTopRowData; }
318 public getPinnedBottomRowData(): any[] { return this.gridOptions.pinnedBottomRowData; }
319 public isFunctionsPassive() { return isTrue(this.gridOptions.functionsPassive); }
320 public isSuppressTabbing() { return isTrue(this.gridOptions.suppressTabbing); }
321 public isSuppressChangeDetection() { return isTrue(this.gridOptions.suppressChangeDetection); }
322 public isSuppressAnimationFrame() { return isTrue(this.gridOptions.suppressAnimationFrame); }
323
324 public getQuickFilterText(): string { return this.gridOptions.quickFilterText; }
325 public isCacheQuickFilter() { return isTrue(this.gridOptions.cacheQuickFilter); }
326 public isUnSortIcon() { return isTrue(this.gridOptions.unSortIcon); }
327 public isSuppressMenuHide() { return isTrue(this.gridOptions.suppressMenuHide); }
328 public isEnterMovesDownAfterEdit() { return isTrue(this.gridOptions.enterMovesDownAfterEdit); }
329 public isEnterMovesDown() { return isTrue(this.gridOptions.enterMovesDown); }
330 public getRowStyle() { return this.gridOptions.rowStyle; }
331 public getRowClass() { return this.gridOptions.rowClass; }
332 public getRowStyleFunc() { return this.gridOptions.getRowStyle; }
333 public getRowClassFunc() { return this.gridOptions.getRowClass; }
334 public rowClassRules() { return this.gridOptions.rowClassRules; }
335 public getPopupParent() { return this.gridOptions.popupParent; }
336 public getPostProcessPopupFunc(): (params: PostProcessPopupParams)=>void { return this.gridOptions.postProcessPopup; }
337 public getDoesDataFlowerFunc(): (data: any)=>boolean { return this.gridOptions.doesDataFlower; }
338 public getPaginationNumberFormatterFunc(): (params: PaginationNumberFormatterParams)=>string { return this.gridOptions.paginationNumberFormatter; }
339 public getChildCountFunc() { return this.gridOptions.getChildCount; }
340 public getDefaultGroupSortComparator() { return this.gridOptions.defaultGroupSortComparator; }
341
342 public getIsFullWidthCellFunc(): (rowNode: RowNode)=> boolean { return this.gridOptions.isFullWidthCell; }
343 public getFullWidthCellRendererParams() { return this.gridOptions.fullWidthCellRendererParams; }
344 public isEmbedFullWidthRows() { return isTrue(this.gridOptions.embedFullWidthRows); }
345 public getBusinessKeyForNodeFunc() { return this.gridOptions.getBusinessKeyForNode; }
346 public getApi(): GridApi { return this.gridOptions.api; }
347 public getColumnApi(): ColumnApi { return this.gridOptions.columnApi; }
348 public isDeltaRowDataMode() { return isTrue(this.gridOptions.deltaRowDataMode); }
349 public isEnsureDomOrder() { return isTrue(this.gridOptions.ensureDomOrder); }
350 public isEnableColResize() { return isTrue(this.gridOptions.enableColResize); }
351 public getColResizeDefault() { return this.gridOptions.colResizeDefault; }
352 public isSingleClickEdit() { return isTrue(this.gridOptions.singleClickEdit); }
353 public isSuppressClickEdit() { return isTrue(this.gridOptions.suppressClickEdit); }
354 public isStopEditingWhenGridLosesFocus() { return isTrue(this.gridOptions.stopEditingWhenGridLosesFocus); }
355 public getGroupDefaultExpanded(): number { return this.gridOptions.groupDefaultExpanded; }
356
357 public getMaxConcurrentDatasourceRequests(): number { return this.gridOptions.maxConcurrentDatasourceRequests; }
358 public getMaxBlocksInCache(): number { return this.gridOptions.maxBlocksInCache; }
359 public getCacheOverflowSize(): number { return this.gridOptions.cacheOverflowSize; }
360 public getPaginationPageSize(): number { return this.gridOptions.paginationPageSize; }
361 public getCacheBlockSize(): number { return this.gridOptions.cacheBlockSize; }
362 public getInfiniteInitialRowCount(): number { return this.gridOptions.infiniteInitialRowCount; }
363 public isPurgeClosedRowNodes() { return isTrue(this.gridOptions.purgeClosedRowNodes); }
364 public isSuppressPaginationPanel() { return isTrue(this.gridOptions.suppressPaginationPanel); }
365
366 public getRowData(): any[] { return this.gridOptions.rowData; }
367 public isGroupUseEntireRow() { return isTrue(this.gridOptions.groupUseEntireRow); }
368 public isEnableRtl() { return isTrue(this.gridOptions.enableRtl); }
369 public getAutoGroupColumnDef(): ColDef { return this.gridOptions.autoGroupColumnDef; }
370 public isGroupSuppressRow() { return isTrue(this.gridOptions.groupSuppressRow); }
371 public getRowGroupPanelShow() { return this.gridOptions.rowGroupPanelShow; }
372 public getPivotPanelShow() { return this.gridOptions.pivotPanelShow; }
373 public isAngularCompileRows() { return isTrue(this.gridOptions.angularCompileRows); }
374 public isAngularCompileFilters() { return isTrue(this.gridOptions.angularCompileFilters); }
375 public isAngularCompileHeaders() { return isTrue(this.gridOptions.angularCompileHeaders); }
376 public isDebug() { return isTrue(this.gridOptions.debug); }
377 public getColumnDefs() { return this.gridOptions.columnDefs; }
378 public getColumnTypes(): {[key: string]: ColDef} { return this.gridOptions.columnTypes; }
379 public getDatasource(): IDatasource { return this.gridOptions.datasource; }
380 public getViewportDatasource(): IViewportDatasource { return this.gridOptions.viewportDatasource; }
381 public getServerSideDatasource(): IServerSideDatasource { return this.gridOptions.serverSideDatasource; }
382 public isEnableSorting() { return isTrue(this.gridOptions.enableSorting) || isTrue(this.gridOptions.enableServerSideSorting); }
383 public isAccentedSort() { return isTrue(this.gridOptions.accentedSort) }
384 public isEnableCellExpressions() { return isTrue(this.gridOptions.enableCellExpressions); }
385 public isEnableGroupEdit() { return isTrue(this.gridOptions.enableGroupEdit); }
386 public isSuppressMiddleClickScrolls() { return isTrue(this.gridOptions.suppressMiddleClickScrolls); }
387 public isSuppressPreventDefaultOnMouseWheel() { return isTrue(this.gridOptions.suppressPreventDefaultOnMouseWheel); }
388 public isSuppressColumnVirtualisation() { return isTrue(this.gridOptions.suppressColumnVirtualisation); }
389 public isSuppressContextMenu() { return isTrue(this.gridOptions.suppressContextMenu); }
390 public isAllowContextMenuWithControlKey() { return isTrue(this.gridOptions.allowContextMenuWithControlKey); }
391 public isSuppressCopyRowsToClipboard() { return isTrue(this.gridOptions.suppressCopyRowsToClipboard); }
392 public isSuppressClipboardPaste() { return isTrue(this.gridOptions.suppressClipboardPaste); }
393 public isEnableFilter() { return isTrue(this.gridOptions.enableFilter) || isTrue(this.gridOptions.enableServerSideFilter); }
394 public isPagination() { return isTrue(this.gridOptions.pagination); }
395 public isSuppressEnterpriseResetOnNewColumns() { return isTrue(this.gridOptions.suppressEnterpriseResetOnNewColumns); }
396 public getProcessDataFromClipboardFunc(): ((params: ProcessDataFromClipboardParams)=>string[][]) { return this.gridOptions.processDataFromClipboard;}
397 public getBatchUpdateWaitMillis(): number {
398 return _.exists(this.gridOptions.batchUpdateWaitMillis) ? this.gridOptions.batchUpdateWaitMillis : Constants.BATCH_WAIT_MILLIS;
399 }
400
401 // these are deprecated, should remove them when we take out server side pagination
402 public isEnableServerSideFilter() { return this.gridOptions.enableServerSideFilter; }
403 public isEnableServerSideSorting() { return isTrue(this.gridOptions.enableServerSideSorting); }
404
405 public isSuppressMovableColumns() { return isTrue(this.gridOptions.suppressMovableColumns); }
406 public isAnimateRows() {
407 // never allow animating if enforcing the row order
408 if (this.isEnsureDomOrder()) { return false; }
409 return isTrue(this.gridOptions.animateRows);
410 }
411 public isSuppressColumnMoveAnimation() { return isTrue(this.gridOptions.suppressColumnMoveAnimation); }
412 public isSuppressAggFuncInHeader() { return isTrue(this.gridOptions.suppressAggFuncInHeader); }
413 public isSuppressAggAtRootLevel() { return isTrue(this.gridOptions.suppressAggAtRootLevel); }
414 public isEnableRangeSelection(): boolean { return isTrue(this.gridOptions.enableRangeSelection); }
415 public isSuppressMultiRangeSelection(): boolean { return isTrue(this.gridOptions.suppressMultiRangeSelection); }
416 public isPaginationAutoPageSize(): boolean { return isTrue(this.gridOptions.paginationAutoPageSize); }
417 public isRememberGroupStateWhenNewData(): boolean { return isTrue(this.gridOptions.rememberGroupStateWhenNewData); }
418 public getIcons() { return this.gridOptions.icons; }
419 public getAggFuncs(): {[key: string]: IAggFunc} { return this.gridOptions.aggFuncs; }
420 public getSortingOrder(): string[] { return this.gridOptions.sortingOrder; }
421 public getAlignedGrids(): GridOptions[] { return this.gridOptions.alignedGrids; }
422 public isMasterDetail() {
423 let usingMasterDetail = isTrue(this.gridOptions.masterDetail);
424
425 _.doOnce(() => {
426 if (usingMasterDetail && !this.enterprise) {
427 console.warn('ag-grid: Master Detail is an Enterprise feature of ag-Grid.')
428 }
429 }, 'MasterDetailEnterpriseCheck');
430
431 return usingMasterDetail && this.enterprise;
432 }
433 public getIsRowMasterFunc(): IsRowMaster { return this.gridOptions.isRowMaster; }
434 public getIsRowSelectableFunc(): IsRowSelectable { return this.gridOptions.isRowSelectable; }
435 public getGroupRowRendererParams() { return this.gridOptions.groupRowRendererParams; }
436 public getOverlayLoadingTemplate() { return this.gridOptions.overlayLoadingTemplate; }
437 public getOverlayNoRowsTemplate() { return this.gridOptions.overlayNoRowsTemplate; }
438 public isSuppressAutoSize() { return isTrue(this.gridOptions.suppressAutoSize); }
439 public isSuppressParentsInRowNodes() { return isTrue(this.gridOptions.suppressParentsInRowNodes); }
440 public isEnableStatusBar() { return isTrue(this.gridOptions.enableStatusBar); }
441 public isAlwaysShowStatusBar() { return isTrue(this.gridOptions.alwaysShowStatusBar); }
442 public isFunctionsReadOnly() { return isTrue(this.gridOptions.functionsReadOnly); }
443 public isFloatingFilter(): boolean { return this.gridOptions.floatingFilter; }
444 public isEnableOldSetFilterModel(): boolean { return isTrue(this.gridOptions.enableOldSetFilterModel); }
445 // public isFloatingFilter(): boolean { return true; }
446
447 public getDefaultColDef(): ColDef { return this.gridOptions.defaultColDef; }
448 public getDefaultColGroupDef(): ColGroupDef { return this.gridOptions.defaultColGroupDef; }
449 public getDefaultExportParams(): BaseExportParams { return this.gridOptions.defaultExportParams; }
450 public isSuppressCsvExport() { return isTrue(this.gridOptions.suppressCsvExport); }
451 public isSuppressExcelExport() { return isTrue(this.gridOptions.suppressExcelExport); }
452 public isSuppressMakeColumnVisibleAfterUnGroup() { return isTrue(this.gridOptions.suppressMakeColumnVisibleAfterUnGroup); }
453
454 public getNodeChildDetailsFunc(): ((dataItem: any)=> NodeChildDetails) { return this.gridOptions.getNodeChildDetails; }
455 public getDataPathFunc(): ((dataItem: any) => string[]) { return this.gridOptions.getDataPath; }
456 // public getIsGroupFunc(): ((dataItem: any) => boolean) { return this.gridOptions.isGroup }
457 public getGroupRowAggNodesFunc() { return this.gridOptions.groupRowAggNodes; }
458 public getContextMenuItemsFunc(): GetContextMenuItems { return this.gridOptions.getContextMenuItems; }
459 public getMainMenuItemsFunc(): GetMainMenuItems { return this.gridOptions.getMainMenuItems; }
460 public getRowNodeIdFunc(): GetRowNodeIdFunc { return this.gridOptions.getRowNodeId; }
461 public getNavigateToNextCellFunc(): (params: NavigateToNextCellParams)=>GridCellDef { return this.gridOptions.navigateToNextCell; }
462 public getTabToNextCellFunc(): (params: TabToNextCellParams)=>GridCellDef { return this.gridOptions.tabToNextCell; }
463
464 public isTreeData(): boolean { return isTrue(this.gridOptions.treeData); }
465 public isValueCache(): boolean { return isTrue(this.gridOptions.valueCache); }
466 public isValueCacheNeverExpires(): boolean { return isTrue(this.gridOptions.valueCacheNeverExpires); }
467 public isAggregateOnlyChangedColumns(): boolean { return isTrue(this.gridOptions.aggregateOnlyChangedColumns); }
468
469 public getProcessSecondaryColDefFunc(): (colDef: ColDef)=>void { return this.gridOptions.processSecondaryColDef; }
470 public getProcessSecondaryColGroupDefFunc(): (colGroupDef: ColGroupDef)=>void { return this.gridOptions.processSecondaryColGroupDef; }
471 public getSendToClipboardFunc() { return this.gridOptions.sendToClipboard; }
472 public getProcessRowPostCreateFunc() : any { return this.gridOptions.processRowPostCreate; }
473
474 public getProcessCellForClipboardFunc(): (params: ProcessCellForExportParams)=>any { return this.gridOptions.processCellForClipboard; }
475 public getProcessHeaderForClipboardFunc(): (params: ProcessHeaderForExportParams)=>any { return this.gridOptions.processHeaderForClipboard; }
476 public getProcessCellFromClipboardFunc(): (params: ProcessCellForExportParams)=>any { return this.gridOptions.processCellFromClipboard; }
477 public getViewportRowModelPageSize(): number { return oneOrGreater(this.gridOptions.viewportRowModelPageSize, DEFAULT_VIEWPORT_ROW_MODEL_PAGE_SIZE); }
478 public getViewportRowModelBufferSize(): number { return zeroOrGreater(this.gridOptions.viewportRowModelBufferSize, DEFAULT_VIEWPORT_ROW_MODEL_BUFFER_SIZE); }
479 // public getCellRenderers(): {[key: string]: {new(): ICellRenderer} | ICellRendererFunc} { return this.gridOptions.cellRenderers; }
480 // public getCellEditors(): {[key: string]: {new(): ICellEditor}} { return this.gridOptions.cellEditors; }
481
482 public isServerSideSortingAlwaysResets() { return isTrue(this.gridOptions.serverSideSortingAlwaysResets); }
483
484 public getPostSortFunc(): (rowNodes: RowNode[]) => void { return this.gridOptions.postSort; }
485
486 public getClipboardDeliminator() {
487 return _.exists(this.gridOptions.clipboardDeliminator) ? this.gridOptions.clipboardDeliminator : '\t';
488 }
489
490 public setProperty(key: string, value: any): void {
491 let gridOptionsNoType = <any> this.gridOptions;
492 let previousValue = gridOptionsNoType[key];
493
494 if (previousValue !== value) {
495 gridOptionsNoType[key] = value;
496 let event: PropertyChangedEvent = {
497 type: key,
498 currentValue: value,
499 previousValue: previousValue
500 };
501 this.propertyEventService.dispatchEvent(event);
502 }
503 }
504
505 // this logic is repeated in lots of places. any element that had different CSS
506 // dependent on the layout needs to have the layout class added ot it.
507 public addLayoutElement(element: HTMLElement): void {
508 this.layoutElements.push(element);
509 this.updateLayoutClasses();
510 }
511
512 private updateLayoutClasses(): void {
513 let autoHeight = this.isGridAutoHeight();
514 this.layoutElements.forEach( e => {
515 _.addOrRemoveCssClass(e, 'ag-layout-auto-height', autoHeight);
516 _.addOrRemoveCssClass(e, 'ag-layout-normal', !autoHeight);
517 });
518 }
519
520 public addEventListener(key: string, listener: Function): void {
521 GridOptionsWrapper.checkEventDeprecation(key);
522 this.propertyEventService.addEventListener(key, listener);
523 }
524
525 public static checkEventDeprecation(eventName: string): void {
526 if (eventName === 'floatingRowDataChanged') {
527 console.warn('ag-Grid: floatingRowDataChanged is now called pinnedRowDataChanged');
528 }
529 }
530
531 public removeEventListener(key: string, listener: Function): void {
532 this.propertyEventService.removeEventListener(key, listener);
533 }
534
535 public getAutoSizePadding(): number {
536 return this.gridOptions.autoSizePadding > 0 ? this.gridOptions.autoSizePadding : 20;
537 }
538
539 // properties
540 public getHeaderHeight(): number {
541 if (typeof this.gridOptions.headerHeight === 'number') {
542 return this.gridOptions.headerHeight;
543 } else {
544 return this.specialForNewMaterial(25, 'headerHeight');
545 }
546 }
547
548 public getFloatingFiltersHeight(): number {
549 if (typeof this.gridOptions.floatingFiltersHeight === 'number') {
550 return this.gridOptions.floatingFiltersHeight;
551 } else {
552 return this.specialForNewMaterial(25, 'headerHeight');
553 }
554 }
555
556 public getGroupHeaderHeight(): number {
557 if (typeof this.gridOptions.groupHeaderHeight === 'number') {
558 return this.gridOptions.groupHeaderHeight;
559 } else {
560 return this.getHeaderHeight();
561 }
562 }
563
564 public getPivotHeaderHeight(): number {
565 if (typeof this.gridOptions.pivotHeaderHeight === 'number') {
566 return this.gridOptions.pivotHeaderHeight;
567 } else {
568 return this.getHeaderHeight();
569 }
570 }
571
572 public getPivotGroupHeaderHeight(): number {
573 if (typeof this.gridOptions.pivotGroupHeaderHeight === 'number') {
574 return this.gridOptions.pivotGroupHeaderHeight;
575 } else {
576 return this.getGroupHeaderHeight();
577 }
578 }
579
580
581 public isExternalFilterPresent() {
582 if (typeof this.gridOptions.isExternalFilterPresent === 'function') {
583 return this.gridOptions.isExternalFilterPresent();
584 } else {
585 return false;
586 }
587 }
588
589 public doesExternalFilterPass(node: RowNode) {
590 if (typeof this.gridOptions.doesExternalFilterPass === 'function') {
591 return this.gridOptions.doesExternalFilterPass(node);
592 } else {
593 return false;
594 }
595 }
596
597 public getDocument(): Document {
598 // if user is providing document, we use the users one,
599 // otherwise we use the document on the global namespace.
600 let result: Document;
601 if (_.exists(this.gridOptions.getDocument)) {
602 result = this.gridOptions.getDocument();
603 }
604 if (_.exists(result)) {
605 return result;
606 } else {
607 return document;
608 }
609 }
610
611 public getMinColWidth() {
612 if (this.gridOptions.minColWidth > GridOptionsWrapper.MIN_COL_WIDTH) {
613 return this.gridOptions.minColWidth;
614 } else {
615 return GridOptionsWrapper.MIN_COL_WIDTH;
616 }
617 }
618
619 public getMaxColWidth() {
620 if (this.gridOptions.maxColWidth > GridOptionsWrapper.MIN_COL_WIDTH) {
621 return this.gridOptions.maxColWidth;
622 } else {
623 return null;
624 }
625 }
626
627 public getColWidth() {
628 if (typeof this.gridOptions.colWidth !== 'number' || this.gridOptions.colWidth < GridOptionsWrapper.MIN_COL_WIDTH) {
629 return 200;
630 } else {
631 return this.gridOptions.colWidth;
632 }
633 }
634
635 public getRowBuffer() {
636 if (typeof this.gridOptions.rowBuffer === 'number') {
637 if (this.gridOptions.rowBuffer < 0) {
638 console.warn('ag-Grid: rowBuffer should not be negative')
639 }
640 return this.gridOptions.rowBuffer;
641 } else {
642 return Constants.ROW_BUFFER_SIZE;
643 }
644 }
645
646 // the user might be using some non-standard scrollbar, eg a scrollbar that has zero
647 // width and overlays (like the Safari scrollbar, but presented in Chrome). so we
648 // allow the user to provide the scroll width before we work it out.
649 public getScrollbarWidth() {
650 let scrollbarWidth = this.gridOptions.scrollbarWidth;
651 if (typeof scrollbarWidth !== 'number' || scrollbarWidth < 0) {
652 scrollbarWidth = _.getScrollbarWidth();
653 }
654 return scrollbarWidth;
655 }
656
657 private checkForDeprecated() {
658 // casting to generic object, so typescript compiles even though
659 // we are looking for attributes that don't exist
660 let options: any = this.gridOptions;
661 if (options.suppressUnSort) {
662 console.warn('ag-grid: as of v1.12.4 suppressUnSort is not used. Please use sortingOrder instead.');
663 }
664 if (options.suppressDescSort) {
665 console.warn('ag-grid: as of v1.12.4 suppressDescSort is not used. Please use sortingOrder instead.');
666 }
667 if (options.groupAggFields) {
668 console.warn('ag-grid: as of v3 groupAggFields is not used. Please add appropriate agg fields to your columns.');
669 }
670 if (options.groupHidePivotColumns) {
671 console.warn('ag-grid: as of v3 groupHidePivotColumns is not used as pivot columns are now called rowGroup columns. Please refer to the documentation');
672 }
673 if (options.groupKeys) {
674 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');
675 }
676 if (typeof options.groupDefaultExpanded === 'boolean') {
677 console.warn('ag-grid: groupDefaultExpanded can no longer be boolean. for groupDefaultExpanded=true, use groupDefaultExpanded=9999 instead, to expand all the groups');
678 }
679 if (options.onRowDeselected || options.rowDeselected) {
680 console.warn('ag-grid: since version 3.4 event rowDeselected no longer exists, please check the docs');
681 }
682 if (options.rowsAlreadyGrouped) {
683 console.warn('ag-grid: since version 3.4 rowsAlreadyGrouped no longer exists, please use getNodeChildDetails() instead');
684 }
685 if (options.groupAggFunction) {
686 console.warn('ag-grid: since version 4.3.x groupAggFunction is now called groupRowAggNodes');
687 }
688 if (options.checkboxSelection) {
689 console.warn('ag-grid: since version 8.0.x checkboxSelection is not supported as a grid option. ' +
690 'If you want this on all columns, use defaultColDef instead and set it there');
691 }
692 if (options.paginationInitialRowCount) {
693 console.warn('ag-grid: since version 9.0.x paginationInitialRowCount is now called infiniteInitialRowCount');
694 }
695 if (options.infinitePageSize) {
696 console.warn('ag-grid: since version 9.0.x infinitePageSize is now called cacheBlockSize');
697 }
698 if (options.infiniteBlockSize) {
699 console.warn('ag-grid: since version 10.0.x infiniteBlockSize is now called cacheBlockSize');
700 }
701 if (options.maxPagesInCache) {
702 console.warn('ag-grid: since version 10.0.x maxPagesInCache is now called maxBlocksInCache');
703 }
704 if (options.paginationOverflowSize) {
705 console.warn('ag-grid: since version 10.0.x paginationOverflowSize is now called cacheOverflowSize');
706 }
707 if (options.forPrint) {
708 console.warn('ag-grid: since version 10.1.x, use property domLayout="forPrint" instead of forPrint=true');
709 }
710 if (options.suppressMenuFilterPanel) {
711 console.warn(`ag-grid: since version 11.0.x, use property colDef.menuTabs=['generalMenuTab','columnsMenuTab'] instead of suppressMenuFilterPanel=true`);
712 }
713 if (options.suppressMenuMainPanel) {
714 console.warn(`ag-grid: since version 11.0.x, use property colDef.menuTabs=['filterMenuTab','columnsMenuTab'] instead of suppressMenuMainPanel=true`);
715 }
716 if (options.suppressMenuColumnPanel) {
717 console.warn(`ag-grid: since version 11.0.x, use property colDef.menuTabs=['generalMenuTab','filterMenuTab'] instead of suppressMenuColumnPanel=true`);
718 }
719 if (options.suppressUseColIdForGroups) {
720 console.warn(`ag-grid: since version 11.0.x, this is not in use anymore. You should be able to remove it from your definition`);
721 }
722 if (options.groupColumnDef) {
723 console.warn(`ag-grid: since version 11.0.x, groupColumnDef has been renamed, this property is now called autoGroupColumnDef. Please change your configuration accordingly`);
724 }
725 if (options.slaveGrids) {
726 console.warn(`ag-grid: since version 12.x, slaveGrids has been renamed, this property is now called alignedGrids. Please change your configuration accordingly`);
727 }
728 if (options.floatingTopRowData) {
729 console.warn(`ag-grid: since version 12.x, floatingTopRowData is now called pinnedTopRowData`);
730 }
731 if (options.floatingBottomRowData) {
732 console.warn(`ag-grid: since version 12.x, floatingBottomRowData is now called pinnedBottomRowData`);
733 }
734 if (options.paginationStartPage) {
735 console.warn(`ag-grid: since version 12.x, paginationStartPage is gone, please call api.paginationGoToPage(${options.paginationStartPage}) instead.`);
736 }
737
738 if (options.getHeaderCellTemplate) {
739 console.warn(`ag-grid: since version 15.x, getHeaderCellTemplate is gone, please check the header documentation on how to set header templates.`);
740 }
741 if (options.headerCellTemplate) {
742 console.warn(`ag-grid: since version 15.x, headerCellTemplate is gone, please check the header documentation on how to set header templates.`);
743 }
744 if (options.headerCellRenderer) {
745 console.warn(`ag-grid: since version 15.x, headerCellRenderer is gone, please check the header documentation on how to set header templates.`);
746 }
747 if (options.angularCompileHeaders) {
748 console.warn(`ag-grid: since version 15.x, angularCompileHeaders is gone, please see the getting started for Angular 1 docs to see how to do headers in Angular 1.x.`);
749 }
750 if (options.domLayout==='forPrint') {
751 console.warn(`ag-grid: since version 18.x, forPrint is no longer supported, as same can be achieved using autoHeight (and set the grid width accordingly). please use autoHeight instead.`);
752 }
753 if (options.domLayout==='autoHeight') {
754 console.warn(`ag-grid: since version 18.x, domLayout is gone, instead if doing auto-height, set gridAutoHeight=true.`);
755 options.gridAutoHeight = true;
756 }
757 if (options.pivotTotals) {
758 console.warn(`ag-grid: since version 18.x, pivotTotals has been removed, instead if using pivotTotals, set pivotColumnGroupTotals='before'|'after'.`);
759 options.pivotColumnGroupTotals = 'before';
760 }
761 if (options.rowModelType==='inMemory') {
762 console.warn(`ag-grid: since version 18.x, The In Memory Row Model has been renamed to the Client Side Row Model, set rowModelType='clientSide' instead.`);
763 options.rowModelType = 'clientSide';
764 }
765 if (options.rowModelType==='enterprise') {
766 console.warn(`ag-grid: since version 18.x, The Enterprise Row Model has been renamed to the Server Side Row Model, set rowModelType='serverSide' instead.`);
767 options.rowModelType = 'serverSide';
768 }
769 if (options.layoutInterval) {
770 console.warn(`ag-grid: since version 18.x, layoutInterval is no longer a property. This is because the grid now uses CSS Flex for layout.`);
771 }
772 }
773
774 public getLocaleTextFunc() {
775 if (this.gridOptions.localeTextFunc) {
776 return this.gridOptions.localeTextFunc;
777 }
778 let that = this;
779 return function(key: any, defaultValue: any) {
780 let localeText = that.gridOptions.localeText;
781 if (localeText && localeText[key]) {
782 return localeText[key];
783 } else {
784 return defaultValue;
785 }
786 };
787 }
788
789 // responsible for calling the onXXX functions on gridOptions
790 public globalEventHandler(eventName: string, event?: any): void {
791 let callbackMethodName = ComponentUtil.getCallbackForEvent(eventName);
792 if (typeof (<any>this.gridOptions)[callbackMethodName] === 'function') {
793 (<any>this.gridOptions)[callbackMethodName](event);
794 }
795 }
796
797 // we don't allow dynamic row height for virtual paging
798 public getRowHeightAsNumber(): number {
799 let rowHeight = this.gridOptions.rowHeight;
800 if (_.missing(rowHeight)) {
801 return this.getDefaultRowHeight();
802 } else if (this.isNumeric(this.gridOptions.rowHeight)) {
803 return this.gridOptions.rowHeight;
804 } else {
805 console.warn('ag-Grid row height must be a number if not using standard row model');
806 return this.getDefaultRowHeight();
807 }
808 }
809
810 public getRowHeightForNode(rowNode: RowNode): number {
811 // check the function first, in case use set both function and
812 // number, when using virtual pagination then function can be
813 // used for pinned rows and the number for the body rows.
814
815 if (typeof this.gridOptions.getRowHeight === 'function') {
816 let params = {
817 node: rowNode,
818 data: rowNode.data,
819 api: this.gridOptions.api,
820 context: this.gridOptions.context
821 };
822 return this.gridOptions.getRowHeight(params);
823 } else if (rowNode.detail && this.isMasterDetail()) {
824 if (this.isNumeric(this.gridOptions.detailRowHeight)) {
825 return this.gridOptions.detailRowHeight;
826 } else {
827 return DEFAULT_DETAIL_ROW_HEIGHT;
828 }
829 } else {
830 let defaultHeight = this.isNumeric(this.gridOptions.rowHeight) ?
831 this.gridOptions.rowHeight : this.getDefaultRowHeight();
832 if (this.columnController.isAutoRowHeightActive()) {
833 let autoHeight = this.autoHeightCalculator.getPreferredHeightForRow(rowNode);
834 // never return less than the default row height - covers when auto height
835 // cells are blank.
836 if (autoHeight > defaultHeight) {
837 return autoHeight;
838 } else {
839 return defaultHeight;
840 }
841 } else {
842 return defaultHeight;
843 }
844 }
845 }
846
847 public isDynamicRowHeight(): boolean {
848 return typeof this.gridOptions.getRowHeight === 'function';
849 }
850
851 public getVirtualItemHeight() {
852 return this.specialForNewMaterial(20, 'virtualItemHeight');
853 }
854
855 private isNumeric(value:any) {
856 return !isNaN(value) && typeof value === 'number';
857 }
858
859 // Material data table has strict guidelines about whitespace, and these values are different than the ones
860 // ag-grid uses by default. We override the default ones for the sake of making it better out of the box
861 private specialForNewMaterial(defaultValue: number, sassVariableName: string): number {
862 var theme = this.environment.getTheme();
863 if (theme.indexOf('ag-theme') === 0) {
864 return this.environment.getSassVariable(theme, sassVariableName);
865 } else {
866 return defaultValue;
867 }
868 }
869
870 private getDefaultRowHeight() {
871 return this.specialForNewMaterial(DEFAULT_ROW_HEIGHT, 'rowHeight');
872 }
873}