UNPKG

47.1 kBPlain TextView Raw
1import {CsvCreator} from "./csvCreator";
2import {RowRenderer} from "./rendering/rowRenderer";
3import {FilterManager} from "./filter/filterManager";
4import {ColumnController} from "./columnController/columnController";
5import {ColumnApi} from "./columnController/columnApi";
6import {SelectionController} from "./selectionController";
7import {GridOptionsWrapper} from "./gridOptionsWrapper";
8import {GridPanel} from "./gridPanel/gridPanel";
9import {ValueService} from "./valueService/valueService";
10import {EventService} from "./eventService";
11import {ColDef, ColGroupDef, IAggFunc} from "./entities/colDef";
12import {RowNode} from "./entities/rowNode";
13import {Constants} from "./constants";
14import {Column} from "./entities/column";
15import {Autowired, Bean, Context, Optional, PostConstruct} from "./context/context";
16import {GridCore} from "./gridCore";
17import {IRowModel} from "./interfaces/iRowModel";
18import {SortController} from "./sortController";
19import {FocusedCellController} from "./focusedCellController";
20import {AddRangeSelectionParams, IRangeController, RangeSelection} from "./interfaces/iRangeController";
21import {GridCell, GridCellDef} from "./entities/gridCell";
22import {IClipboardService} from "./interfaces/iClipboardService";
23import {Utils as _} from "./utils";
24import {IViewportDatasource} from "./interfaces/iViewportDatasource";
25import {IMenuFactory} from "./interfaces/iMenuFactory";
26import {InfiniteRowModel} from "./rowModels/infinite/infiniteRowModel";
27import {CellRendererFactory} from "./rendering/cellRendererFactory";
28import {CellEditorFactory} from "./rendering/cellEditorFactory";
29import {IAggFuncService} from "./interfaces/iAggFuncService";
30import {IFilterComp} from "./interfaces/iFilter";
31import {CsvExportParams} from "./exportParams";
32import {ExcelExportParams, IExcelCreator} from "./interfaces/iExcelCreator";
33import {IDatasource} from "./rowModels/iDatasource";
34import {IServerSideDatasource} from "./interfaces/iServerSideDatasource";
35import {PaginationProxy} from "./rowModels/paginationProxy";
36import {
37 ClientSideRowModel,
38 RefreshModelParams,
39 RowDataTransaction,
40 RowNodeTransaction
41} from "./rowModels/clientSide/clientSideRowModel";
42import {ImmutableService} from "./rowModels/clientSide/immutableService";
43import {ValueCache} from "./valueService/valueCache";
44import {AlignedGridsService} from "./alignedGridsService";
45import {PinnedRowModel} from "./rowModels/pinnedRowModel";
46import {AgEvent, ColumnEventType} from "./events";
47import {IToolPanel} from "./interfaces/iToolPanel";
48import {IContextMenuFactory} from "./interfaces/iContextMenuFactory";
49import {ICellRendererComp} from "./rendering/cellRenderers/iCellRenderer";
50import {ICellEditorComp} from "./rendering/cellEditors/iCellEditor";
51import {HeaderRootComp} from "./headerRendering/headerRootComp";
52import {AnimationFrameService} from "./misc/animationFrameService";
53import {IServerSideRowModel} from "./interfaces/iServerSideRowModel";
54
55export interface StartEditingCellParams {
56 rowIndex: number;
57 colKey: string|Column;
58 rowPinned?: string;
59 keyPress?: number;
60 charPress?: string;
61}
62
63export interface GetCellsParams {
64 rowNodes?: RowNode[];
65 columns?: (string|Column)[];
66}
67
68export interface RefreshCellsParams extends GetCellsParams {
69 force?: boolean;
70}
71
72export interface FlashCellsParams extends GetCellsParams {}
73
74export interface GetCellRendererInstancesParams extends GetCellsParams {}
75
76export interface GetCellEditorInstancesParams extends GetCellsParams {}
77
78export interface RedrawRowsParams {
79 rowNodes?: RowNode[];
80}
81
82export interface DetailGridInfo {
83 id: string;
84 api: GridApi;
85 columnApi: ColumnApi;
86}
87
88@Bean('gridApi')
89export class GridApi {
90
91 @Autowired('immutableService') private immutableService: ImmutableService;
92 @Autowired('csvCreator') private csvCreator: CsvCreator;
93 @Optional('excelCreator') private excelCreator: IExcelCreator;
94 @Autowired('gridCore') private gridCore: GridCore;
95 @Autowired('rowRenderer') private rowRenderer: RowRenderer;
96 @Autowired('filterManager') private filterManager: FilterManager;
97 @Autowired('columnController') private columnController: ColumnController;
98 @Autowired('selectionController') private selectionController: SelectionController;
99 @Autowired('gridOptionsWrapper') private gridOptionsWrapper: GridOptionsWrapper;
100 @Autowired('valueService') private valueService: ValueService;
101 @Autowired('alignedGridsService') private alignedGridsService: AlignedGridsService;
102 @Autowired('eventService') private eventService: EventService;
103 @Autowired('pinnedRowModel') private pinnedRowModel: PinnedRowModel;
104 @Autowired('context') private context: Context;
105 @Autowired('rowModel') private rowModel: IRowModel;
106 @Autowired('sortController') private sortController: SortController;
107 @Autowired('paginationProxy') private paginationProxy: PaginationProxy;
108 @Autowired('focusedCellController') private focusedCellController: FocusedCellController;
109 @Optional('rangeController') private rangeController: IRangeController;
110 @Optional('clipboardService') private clipboardService: IClipboardService;
111 @Optional('aggFuncService') private aggFuncService: IAggFuncService;
112 @Autowired('menuFactory') private menuFactory: IMenuFactory;
113 @Optional('contextMenuFactory') private contextMenuFactory: IContextMenuFactory;
114 @Autowired('cellRendererFactory') private cellRendererFactory: CellRendererFactory;
115 @Autowired('cellEditorFactory') private cellEditorFactory: CellEditorFactory;
116 @Autowired('valueCache') private valueCache: ValueCache;
117 @Optional('toolPanelComp') private toolPanelComp: IToolPanel;
118 @Autowired('animationFrameService') private animationFrameService: AnimationFrameService;
119
120 private gridPanel: GridPanel;
121 private headerRootComp: HeaderRootComp;
122
123 private clientSideRowModel: ClientSideRowModel;
124 private infinitePageRowModel: InfiniteRowModel;
125 private serverSideRowModel: IServerSideRowModel;
126
127 private detailGridInfoMap: {[id: string]: DetailGridInfo} = {};
128
129 public registerGridComp(gridPanel: GridPanel): void {
130 this.gridPanel = gridPanel;
131 }
132
133 public registerHeaderRootComp(headerRootComp: HeaderRootComp): void {
134 this.headerRootComp = headerRootComp;
135 }
136
137 @PostConstruct
138 private init(): void {
139 switch (this.rowModel.getType()) {
140 case Constants.ROW_MODEL_TYPE_CLIENT_SIDE:
141 this.clientSideRowModel = <ClientSideRowModel> this.rowModel;
142 break;
143 case Constants.ROW_MODEL_TYPE_INFINITE:
144 this.infinitePageRowModel = <InfiniteRowModel> this.rowModel;
145 break;
146 case Constants.ROW_MODEL_TYPE_SERVER_SIDE:
147 this.serverSideRowModel = <IServerSideRowModel> this.rowModel;
148 break;
149 }
150 }
151
152 /** Used internally by grid. Not intended to be used by the client. Interface may change between releases. */
153 public __getAlignedGridService(): AlignedGridsService {
154 return this.alignedGridsService;
155 }
156
157 public addDetailGridInfo(id: string, gridInfo: DetailGridInfo): void {
158 this.detailGridInfoMap[id] = gridInfo;
159 }
160
161 public removeDetailGridInfo(id: string): void {
162 this.detailGridInfoMap[id] = undefined;
163 }
164
165 public getDetailGridInfo(id: string): DetailGridInfo {
166 return this.detailGridInfoMap[id];
167 }
168
169 public forEachDetailGridInfo(callback: (gridInfo: DetailGridInfo, index: number)=>void) {
170 let index = 0;
171 _.iterateObject(this.detailGridInfoMap, (id: string, gridInfo: DetailGridInfo)=> {
172 // check for undefined, as old references will still be lying around
173 if (_.exists(gridInfo)) {
174 callback(gridInfo, index);
175 index++;
176 }
177 });
178 }
179
180 public getDataAsCsv(params?: CsvExportParams): string {
181 return this.csvCreator.getDataAsCsv(params);
182 }
183
184 public exportDataAsCsv(params?: CsvExportParams): void {
185 this.csvCreator.exportDataAsCsv(params)
186 }
187
188 public getDataAsExcel(params?: ExcelExportParams): string {
189 if (!this.excelCreator) { console.warn('ag-Grid: Excel export is only available in ag-Grid Enterprise'); }
190 return this.excelCreator.getDataAsExcelXml(params);
191 }
192
193 public exportDataAsExcel(params?: ExcelExportParams): void {
194 if (!this.excelCreator) { console.warn('ag-Grid: Excel export is only available in ag-Grid Enterprise'); }
195 this.excelCreator.exportDataAsExcel(params)
196 }
197
198 // DEPRECATED
199 public setEnterpriseDatasource(datasource: IServerSideDatasource) {
200 console.warn(`ag-grid: since version 18.x, api.setEnterpriseDatasource() should be replaced with api.setServerSideDatasource()`);
201 this.setServerSideDatasource(datasource);
202 }
203
204 public setServerSideDatasource(datasource: IServerSideDatasource) {
205 if (this.gridOptionsWrapper.isRowModelServerSide()) {
206 // should really have an IEnterpriseRowModel interface, so we are not casting to any
207 (<any>this.rowModel).setDatasource(datasource);
208 } else {
209 console.warn(`ag-Grid: you can only use an enterprise datasource when gridOptions.rowModelType is '${Constants.ROW_MODEL_TYPE_SERVER_SIDE}'`)
210 }
211 }
212
213 public setDatasource(datasource: IDatasource) {
214 if (this.gridOptionsWrapper.isRowModelInfinite()) {
215 (<InfiniteRowModel>this.rowModel).setDatasource(datasource);
216 } else {
217 console.warn(`ag-Grid: you can only use a datasource when gridOptions.rowModelType is '${Constants.ROW_MODEL_TYPE_INFINITE}'`)
218 }
219 }
220
221 public setViewportDatasource(viewportDatasource: IViewportDatasource) {
222 if (this.gridOptionsWrapper.isRowModelViewport()) {
223 // this is bad coding, because it's using an interface that's exposed in the enterprise.
224 // really we should create an interface in the core for viewportDatasource and let
225 // the enterprise implement it, rather than casting to 'any' here
226 (<any>this.rowModel).setViewportDatasource(viewportDatasource);
227 } else {
228 console.warn(`ag-Grid: you can only use a viewport datasource when gridOptions.rowModelType is '${Constants.ROW_MODEL_TYPE_VIEWPORT}'`)
229 }
230 }
231
232 public setRowData(rowData: any[]) {
233 if (this.gridOptionsWrapper.isRowModelDefault()) {
234 if (this.gridOptionsWrapper.isDeltaRowDataMode()) {
235 let [transaction, orderIdMap] = this.immutableService.createTransactionForRowData(rowData);
236 this.clientSideRowModel.updateRowData(transaction, orderIdMap);
237 } else {
238 this.selectionController.reset();
239 this.clientSideRowModel.setRowData(rowData);
240 }
241 } else {
242 console.log('cannot call setRowData unless using normal row model');
243 }
244 }
245
246 // DEPRECATED
247 public setFloatingTopRowData(rows: any[]): void {
248 console.warn('ag-Grid: since v12, api.setFloatingTopRowData() is now api.setPinnedTopRowData()');
249 this.setPinnedTopRowData(rows);
250 }
251
252 // DEPRECATED
253 public setFloatingBottomRowData(rows: any[]): void {
254 console.warn('ag-Grid: since v12, api.setFloatingBottomRowData() is now api.setPinnedBottomRowData()');
255 this.setPinnedBottomRowData(rows);
256 }
257
258 // DEPRECATED
259 public getFloatingTopRowCount(): number {
260 console.warn('ag-Grid: since v12, api.getFloatingTopRowCount() is now api.getPinnedTopRowCount()');
261 return this.getPinnedTopRowCount();
262 }
263
264 // DEPRECATED
265 public getFloatingBottomRowCount(): number {
266 console.warn('ag-Grid: since v12, api.getFloatingBottomRowCount() is now api.getPinnedBottomRowCount()');
267 return this.getPinnedBottomRowCount();
268 }
269
270 // DEPRECATED
271 public getFloatingTopRow(index: number): RowNode {
272 console.warn('ag-Grid: since v12, api.getFloatingTopRow() is now api.getPinnedTopRow()');
273 return this.getPinnedTopRow(index);
274 }
275
276 // DEPRECATED
277 public getFloatingBottomRow(index: number): RowNode {
278 console.warn('ag-Grid: since v12, api.getFloatingBottomRow() is now api.getPinnedBottomRow()');
279 return this.getPinnedBottomRow(index);
280 }
281
282 public setPinnedTopRowData(rows: any[]): void {
283 this.pinnedRowModel.setPinnedTopRowData(rows);
284 }
285
286 public setPinnedBottomRowData(rows: any[]): void {
287 this.pinnedRowModel.setPinnedBottomRowData(rows);
288 }
289
290 public getPinnedTopRowCount(): number {
291 return this.pinnedRowModel.getPinnedTopRowCount();
292 }
293
294 public getPinnedBottomRowCount(): number {
295 return this.pinnedRowModel.getPinnedBottomRowCount();
296 }
297
298 public getPinnedTopRow(index: number): RowNode {
299 return this.pinnedRowModel.getPinnedTopRow(index);
300 }
301
302 public getPinnedBottomRow(index: number): RowNode {
303 return this.pinnedRowModel.getPinnedBottomRow(index);
304 }
305
306 public setColumnDefs(colDefs: (ColDef|ColGroupDef)[], source: ColumnEventType = "api") {
307 this.columnController.setColumnDefs(colDefs, source);
308 }
309
310 public expireValueCache(): void {
311 this.valueCache.expire();
312 }
313
314 public getVerticalPixelRange(): any {
315 return this.gridPanel.getVScrollPosition();
316 }
317
318 public refreshToolPanel(): void {
319 if (this.toolPanelComp) {
320 this.toolPanelComp.refresh();
321 }
322 }
323
324 public refreshCells(params: RefreshCellsParams = {}): void {
325 if (Array.isArray(params)) {
326 // the old version of refreshCells() took an array of rowNodes for the first argument
327 console.warn('since ag-Grid v11.1, refreshCells() now takes parameters, please see the documentation.');
328 return;
329 }
330 this.rowRenderer.refreshCells(params);
331 }
332
333 public flashCells(params: FlashCellsParams = {}): void {
334 this.rowRenderer.flashCells(params);
335 }
336
337 public redrawRows(params: RedrawRowsParams = {}): void {
338 if (params && params.rowNodes) {
339 this.rowRenderer.redrawRows(params.rowNodes);
340 } else {
341 this.rowRenderer.redrawAfterModelUpdate();
342 }
343 }
344
345 public timeFullRedraw(count = 1) {
346
347 let iterationCount = 0;
348 let totalProcessing = 0;
349 let totalReflow = 0;
350
351 let that = this;
352
353 doOneIteration();
354
355 function doOneIteration(): void {
356 let start = (new Date()).getTime();
357 that.rowRenderer.redrawAfterModelUpdate();
358 let endProcessing = (new Date()).getTime();
359 setTimeout( ()=> {
360 let endReflow = (new Date()).getTime();
361 let durationProcessing = endProcessing - start;
362 let durationReflow = endReflow - endProcessing;
363 console.log('duration: processing = ' + durationProcessing + 'ms, reflow = ' + durationReflow + 'ms');
364
365 iterationCount++;
366 totalProcessing += durationProcessing;
367 totalReflow += durationReflow;
368
369 if (iterationCount < count) {
370 // wait for 1s between tests
371 setTimeout(doOneIteration, 1000);
372 } else {
373 finish();
374 }
375
376 }, 0);
377 }
378
379 function finish(): void {
380 console.log('tests complete. iteration count = ' + iterationCount);
381 console.log('average processing = ' + (totalProcessing/iterationCount) + 'ms');
382 console.log('average reflow = ' + (totalReflow/iterationCount) + 'ms');
383 }
384 }
385
386 // *** deprecated
387 public refreshView() {
388 console.warn('ag-Grid: since v11.1, refreshView() is deprecated, please call refreshCells() or redrawRows() instead');
389 this.redrawRows();
390 }
391
392 // *** deprecated
393 public refreshRows(rowNodes: RowNode[]): void {
394 console.warn('since ag-Grid v11.1, refreshRows() is deprecated, please use refreshCells({rowNodes: rows}) or redrawRows({rowNodes: rows}) instead');
395 this.refreshCells({rowNodes: rowNodes});
396 }
397
398 // *** deprecated
399 public rowDataChanged(rows:any) {
400 console.log('ag-Grid: rowDataChanged is deprecated, either call refreshView() to refresh everything, or call rowNode.setRowData(newData) to set value on a particular node')
401 this.redrawRows();
402 }
403
404 // *** deprecated
405 public softRefreshView() {
406 console.error('ag-Grid: since v16, softRefreshView() is no longer supported. Please check the documentation on how to refresh.');
407 }
408
409 // *** deprecated
410 public refreshGroupRows() {
411 console.warn('ag-Grid: since v11.1, refreshGroupRows() is no longer supported, call refreshCells() instead. ' +
412 'Because refreshCells() now does dirty checking, it will only refresh cells that have changed, so it should ' +
413 'not be necessary to only refresh the group rows.');
414 this.refreshCells();
415 }
416
417 public setFunctionsReadOnly(readOnly: boolean) {
418 this.gridOptionsWrapper.setProperty('functionsReadOnly', readOnly);
419 }
420
421 public refreshHeader() {
422 this.headerRootComp.refreshHeader();
423 this.gridPanel.setBodyAndHeaderHeights();
424 }
425
426 public isAnyFilterPresent(): boolean {
427 return this.filterManager.isAnyFilterPresent();
428 }
429
430 public isAdvancedFilterPresent(): boolean {
431 return this.filterManager.isAdvancedFilterPresent();
432 }
433
434 public isQuickFilterPresent(): boolean {
435 return this.filterManager.isQuickFilterPresent();
436 }
437
438 public getModel(): IRowModel {
439 return this.rowModel;
440 }
441
442 public onGroupExpandedOrCollapsed(deprecated_refreshFromIndex?: any) {
443 if (_.missing(this.clientSideRowModel)) { console.log('ag-Grid: cannot call onGroupExpandedOrCollapsed unless using normal row model') }
444 if (_.exists(deprecated_refreshFromIndex)) { console.log('ag-Grid: api.onGroupExpandedOrCollapsed - refreshFromIndex parameter is no longer used, the grid will refresh all rows'); }
445 // we don't really want the user calling this if one one rowNode was expanded, instead they should be
446 // calling rowNode.setExpanded(boolean) - this way we do a 'keepRenderedRows=false' so that the whole
447 // grid gets refreshed again - otherwise the row with the rowNodes that were changed won't get updated,
448 // and thus the expand icon in the group cell won't get 'opened' or 'closed'.
449 this.clientSideRowModel.refreshModel({step: Constants.STEP_MAP});
450 }
451
452 public refreshInMemoryRowModel(step?: string): any {
453 console.warn(`ag-grid: since version 18.x, api.refreshInMemoryRowModel() should be replaced with api.refreshClientSideRowModel()`);
454 this.refreshClientSideRowModel(step);
455 }
456
457 public refreshClientSideRowModel(step?: string): any {
458 if (_.missing(this.clientSideRowModel)) { console.log('cannot call refreshClientSideRowModel unless using normal row model') }
459
460 let paramsStep = Constants.STEP_EVERYTHING;
461 let stepsMapped: any = {
462 group: Constants.STEP_EVERYTHING,
463 filter: Constants.STEP_FILTER,
464 map: Constants.STEP_MAP,
465 aggregate: Constants.STEP_AGGREGATE,
466 sort: Constants.STEP_SORT,
467 pivot: Constants.STEP_PIVOT
468 };
469
470 if (_.exists(step)) {
471 paramsStep = stepsMapped[step];
472 }
473 if (_.missing(paramsStep)) {
474 console.error(`ag-Grid: invalid step ${step}, available steps are ${Object.keys(stepsMapped).join(', ')}`);
475 return;
476 }
477
478 let modelParams: RefreshModelParams = {
479 step: paramsStep,
480 keepRenderedRows: true,
481 animate: true,
482 keepEditingRows: true
483 };
484
485 this.clientSideRowModel.refreshModel(modelParams);
486 }
487
488 public isAnimationFrameQueueEmpty(): boolean {
489 return this.animationFrameService.isQueueEmpty();
490 }
491
492 public getRowNode(id: string): RowNode {
493 return this.rowModel.getRowNode(id);
494 }
495
496 public expandAll() {
497 if (_.missing(this.clientSideRowModel)) {
498 console.warn('ag-Grid: cannot call expandAll unless using normal row model');
499 return;
500 }
501 this.clientSideRowModel.expandOrCollapseAll(true);
502 }
503
504 public collapseAll() {
505 if (_.missing(this.clientSideRowModel)) {
506 console.warn('ag-Grid: cannot call collapseAll unless using normal row model');
507 return;
508 }
509 this.clientSideRowModel.expandOrCollapseAll(false);
510 }
511
512 public addVirtualRowListener(eventName: string, rowIndex: number, callback: Function) {
513 if (typeof eventName !== 'string') {
514 console.log('ag-Grid: addVirtualRowListener is deprecated, please use addRenderedRowListener.');
515 }
516 this.addRenderedRowListener(eventName, rowIndex, callback);
517 }
518
519 public addRenderedRowListener(eventName: string, rowIndex: number, callback: Function) {
520 if (eventName==='virtualRowSelected') {
521 console.log('ag-Grid: event virtualRowSelected is deprecated, to register for individual row ' +
522 'selection events, add a listener directly to the row node.');
523 }
524 this.rowRenderer.addRenderedRowListener(eventName, rowIndex, callback);
525 }
526
527 public setQuickFilter(newFilter:any): void {
528 this.filterManager.setQuickFilter(newFilter)
529 }
530
531 public selectIndex(index:any, tryMulti:any, suppressEvents:any) {
532 console.log('ag-Grid: do not use api for selection, call node.setSelected(value) instead');
533 if (suppressEvents) {
534 console.log('ag-Grid: suppressEvents is no longer supported, stop listening for the event if you no longer want it');
535 }
536 this.selectionController.selectIndex(index, tryMulti);
537 }
538
539 public deselectIndex(index: number, suppressEvents: boolean = false) {
540 console.log('ag-Grid: do not use api for selection, call node.setSelected(value) instead');
541 if (suppressEvents) {
542 console.log('ag-Grid: suppressEvents is no longer supported, stop listening for the event if you no longer want it');
543 }
544 this.selectionController.deselectIndex(index);
545 }
546
547 public selectNode(node: RowNode, tryMulti: boolean = false, suppressEvents: boolean = false) {
548 console.log('ag-Grid: API for selection is deprecated, call node.setSelected(value) instead');
549 if (suppressEvents) {
550 console.log('ag-Grid: suppressEvents is no longer supported, stop listening for the event if you no longer want it');
551 }
552 node.setSelectedParams({newValue: true, clearSelection: !tryMulti});
553 }
554
555 public deselectNode(node: RowNode, suppressEvents: boolean = false) {
556 console.log('ag-Grid: API for selection is deprecated, call node.setSelected(value) instead');
557 if (suppressEvents) {
558 console.log('ag-Grid: suppressEvents is no longer supported, stop listening for the event if you no longer want it');
559 }
560 node.setSelectedParams({newValue: false});
561 }
562
563 public selectAll() {
564 this.selectionController.selectAllRowNodes();
565 }
566
567 public deselectAll() {
568 this.selectionController.deselectAllRowNodes();
569 }
570
571 public selectAllFiltered() {
572 this.selectionController.selectAllRowNodes(true);
573 }
574
575 public deselectAllFiltered() {
576 this.selectionController.deselectAllRowNodes(true);
577 }
578
579 public recomputeAggregates(): void {
580 if (_.missing(this.clientSideRowModel)) { console.warn('cannot call recomputeAggregates unless using normal row model') }
581 console.warn(`recomputeAggregates is deprecated, please call api.refreshClientSideRowModel('aggregate') instead`);
582 this.clientSideRowModel.refreshModel({step: Constants.STEP_AGGREGATE});
583 }
584
585 public sizeColumnsToFit() {
586 this.gridPanel.sizeColumnsToFit();
587 }
588
589 public showLoadingOverlay(): void {
590 this.gridPanel.showLoadingOverlay();
591 }
592
593 public showNoRowsOverlay(): void {
594 this.gridPanel.showNoRowsOverlay();
595 }
596
597 public hideOverlay(): void {
598 this.gridPanel.hideOverlay();
599 }
600
601 public isNodeSelected(node:any) {
602 console.log('ag-Grid: no need to call api.isNodeSelected(), just call node.isSelected() instead');
603 return node.isSelected();
604 }
605
606 public getSelectedNodesById(): {[nodeId: number]: RowNode;} {
607 console.error('ag-Grid: since version 3.4, getSelectedNodesById no longer exists, use getSelectedNodes() instead');
608 return null;
609 }
610
611 public getSelectedNodes(): RowNode[] {
612 return this.selectionController.getSelectedNodes();
613 }
614
615 public getSelectedRows(): any[] {
616 return this.selectionController.getSelectedRows();
617 }
618
619 public getBestCostNodeSelection() {
620 return this.selectionController.getBestCostNodeSelection();
621 }
622
623 public getRenderedNodes() {
624 return this.rowRenderer.getRenderedNodes();
625 }
626
627 public ensureColIndexVisible(index:any) {
628 console.warn('ag-Grid: ensureColIndexVisible(index) no longer supported, use ensureColumnVisible(colKey) instead.');
629 }
630
631 public ensureColumnVisible(key: string|Column) {
632 this.gridPanel.ensureColumnVisible(key);
633 }
634
635 // Valid values for position are bottom, middle and top
636 public ensureIndexVisible(index:any, position?:string) {
637 this.gridPanel.ensureIndexVisible(index, position);
638 }
639
640 // Valid values for position are bottom, middle and top
641 public ensureNodeVisible(comparator:any, position?:string) {
642 this.gridCore.ensureNodeVisible(comparator, position);
643 }
644
645 public forEachLeafNode(callback: (rowNode: RowNode)=>void ) {
646 if (_.missing(this.clientSideRowModel)) { console.log('cannot call forEachNode unless using normal row model') }
647 this.clientSideRowModel.forEachLeafNode(callback);
648 }
649
650 public forEachNode(callback: (rowNode: RowNode)=>void ) {
651 this.rowModel.forEachNode(callback);
652 }
653
654 public forEachNodeAfterFilter(callback: (rowNode: RowNode)=>void) {
655 if (_.missing(this.clientSideRowModel)) { console.log('cannot call forEachNodeAfterFilter unless using normal row model') }
656 this.clientSideRowModel.forEachNodeAfterFilter(callback);
657 }
658
659 public forEachNodeAfterFilterAndSort(callback: (rowNode: RowNode)=>void) {
660 if (_.missing(this.clientSideRowModel)) { console.log('cannot call forEachNodeAfterFilterAndSort unless using normal row model') }
661 this.clientSideRowModel.forEachNodeAfterFilterAndSort(callback);
662 }
663
664 public getFilterApiForColDef(colDef: any): any {
665 console.warn('ag-grid API method getFilterApiForColDef deprecated, use getFilterApi instead');
666 return this.getFilterInstance(colDef);
667 }
668
669 public getFilterInstance(key: string|Column): IFilterComp {
670 let column = this.columnController.getPrimaryColumn(key);
671 if (column) {
672 return this.filterManager.getFilterComponent(column).resolveNow<IFilterComp>(null, filterComp=>filterComp);
673 }
674 }
675
676 public getFilterApi(key: string|Column) {
677 console.warn('ag-Grid: getFilterApi is deprecated, use getFilterInstance instead');
678 return this.getFilterInstance(key);
679 }
680
681 public destroyFilter(key: string|Column) {
682 let column = this.columnController.getPrimaryColumn(key);
683 if (column) {
684 return this.filterManager.destroyFilter(column, "filterDestroyed");
685 }
686 }
687
688 public getColumnDef(key: string|Column) {
689 let column = this.columnController.getPrimaryColumn(key);
690 if (column) {
691 return column.getColDef();
692 } else {
693 return null;
694 }
695 }
696
697 public onFilterChanged() {
698 this.filterManager.onFilterChanged();
699 }
700
701 public onSortChanged() {
702 this.sortController.onSortChanged();
703 }
704
705 public setSortModel(sortModel:any, source: ColumnEventType = "api") {
706 this.sortController.setSortModel(sortModel, source);
707 }
708
709 public getSortModel() {
710 return this.sortController.getSortModel();
711 }
712
713 public setFilterModel(model:any) {
714 this.filterManager.setFilterModel(model);
715 }
716
717 public getFilterModel() {
718 return this.filterManager.getFilterModel();
719 }
720
721 public getFocusedCell(): GridCell {
722 return this.focusedCellController.getFocusedCell();
723 }
724
725 public clearFocusedCell(): void {
726 return this.focusedCellController.clearFocusedCell();
727 }
728
729 public setFocusedCell(rowIndex: number, colKey: string|Column, floating?: string) {
730 this.focusedCellController.setFocusedCell(rowIndex, colKey, floating, true);
731 }
732
733 public setSuppressRowDrag(value: boolean): void {
734 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_SUPPRESS_ROW_DRAG, value);
735 }
736
737 public setHeaderHeight(headerHeight: number) {
738 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_HEADER_HEIGHT, headerHeight);
739 this.doLayout();
740 }
741
742 public setGridAutoHeight(gridAutoHeight: boolean) {
743 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_GRID_AUTO_HEIGHT, gridAutoHeight);
744 }
745
746 public getPreferredWidth(): number {
747 return this.gridCore.getPreferredWidth();
748 }
749
750 public setGroupHeaderHeight(headerHeight: number) {
751 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_GROUP_HEADER_HEIGHT, headerHeight);
752 this.doLayout();
753 }
754
755 public setFloatingFiltersHeight(headerHeight: number) {
756 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_FLOATING_FILTERS_HEIGHT, headerHeight);
757 this.doLayout();
758 }
759
760 public setPivotGroupHeaderHeight(headerHeight: number) {
761 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_PIVOT_GROUP_HEADER_HEIGHT, headerHeight);
762 this.doLayout();
763 }
764
765 public setPivotHeaderHeight(headerHeight: number) {
766 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_PIVOT_HEADER_HEIGHT, headerHeight);
767 this.doLayout();
768 }
769
770 public showToolPanel(show:any) {
771 this.gridCore.showToolPanel(show);
772 }
773
774 public setSuppressClipboardPaste(value: boolean): void {
775 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_SUPPRESS_CLIPBOARD_PASTE, value);
776 }
777
778 public isToolPanelShowing() {
779 return this.gridCore.isToolPanelShowing();
780 }
781
782 public doLayout() {
783 this.gridPanel.checkViewportAndScrolls();
784 }
785
786 public resetRowHeights() {
787 if (_.exists(this.clientSideRowModel)) {
788 this.clientSideRowModel.resetRowHeights();
789 }
790 }
791
792 public setGroupRemoveSingleChildren(value: boolean) {
793 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_GROUP_REMOVE_SINGLE_CHILDREN, value);
794 }
795
796 public setGroupRemoveLowestSingleChildren(value: boolean) {
797 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_GROUP_REMOVE_LOWEST_SINGLE_CHILDREN, value);
798 }
799
800 public onRowHeightChanged() {
801 if (_.exists(this.clientSideRowModel)) {
802 this.clientSideRowModel.onRowHeightChanged();
803 }
804 }
805
806 public getValue(colKey: string|Column, rowNode: RowNode): any {
807 let column = this.columnController.getPrimaryColumn(colKey);
808 if (_.missing(column)) {
809 column = this.columnController.getGridColumn(colKey);
810 }
811 if (_.missing(column)) {
812 return null;
813 } else {
814 return this.valueService.getValue(column, rowNode);
815 }
816 }
817
818 public addEventListener(eventType: string, listener: Function): void {
819 let async = this.gridOptionsWrapper.useAsyncEvents();
820 this.eventService.addEventListener(eventType, listener, async);
821 }
822
823 public addGlobalListener(listener: Function): void {
824 let async = this.gridOptionsWrapper.useAsyncEvents();
825 this.eventService.addGlobalListener(listener, async);
826 }
827
828 public removeEventListener(eventType: string, listener: Function): void {
829 let async = this.gridOptionsWrapper.useAsyncEvents();
830 this.eventService.removeEventListener(eventType, listener, async);
831 }
832
833 public removeGlobalListener(listener: Function): void {
834 let async = this.gridOptionsWrapper.useAsyncEvents();
835 this.eventService.removeGlobalListener(listener, async);
836 }
837
838 public dispatchEvent(event: AgEvent): void {
839 this.eventService.dispatchEvent(event);
840 }
841
842 public destroy(): void {
843 this.context.destroy();
844 }
845
846 public resetQuickFilter(): void {
847 this.rowModel.forEachNode( node => node.quickFilterAggregateText = null);
848 }
849
850 public getRangeSelections(): RangeSelection[] {
851 if (this.rangeController) {
852 return this.rangeController.getCellRanges();
853 } else {
854 console.warn('ag-Grid: cell range selection is only available in ag-Grid Enterprise');
855 return null;
856 }
857 }
858
859 public camelCaseToHumanReadable (camelCase:string):string{
860 return _.camelCaseToHumanText(camelCase);
861 }
862
863 public addRangeSelection(rangeSelection: AddRangeSelectionParams): void {
864 if (!this.rangeController) { console.warn('ag-Grid: cell range selection is only available in ag-Grid Enterprise'); }
865 this.rangeController.addRange(rangeSelection);
866 }
867
868 public clearRangeSelection(): void {
869 if (!this.rangeController) { console.warn('ag-Grid: cell range selection is only available in ag-Grid Enterprise'); }
870 this.rangeController.clearSelection();
871 }
872
873 public copySelectedRowsToClipboard(includeHeader: boolean, columnKeys?: (string|Column)[]): void {
874 if (!this.clipboardService) { console.warn('ag-Grid: clipboard is only available in ag-Grid Enterprise'); }
875 this.clipboardService.copySelectedRowsToClipboard(includeHeader, columnKeys);
876 }
877
878 public copySelectedRangeToClipboard(includeHeader: boolean): void {
879 if (!this.clipboardService) { console.warn('ag-Grid: clipboard is only available in ag-Grid Enterprise'); }
880 this.clipboardService.copySelectedRangeToClipboard(includeHeader);
881 }
882
883 public copySelectedRangeDown(): void {
884 if (!this.clipboardService) { console.warn('ag-Grid: clipboard is only available in ag-Grid Enterprise'); }
885 this.clipboardService.copyRangeDown();
886 }
887
888 public showColumnMenuAfterButtonClick(colKey: string|Column, buttonElement: HTMLElement): void {
889 let column = this.columnController.getPrimaryColumn(colKey);
890 this.menuFactory.showMenuAfterButtonClick(column, buttonElement);
891 }
892
893 public showColumnMenuAfterMouseClick(colKey: string|Column, mouseEvent: MouseEvent|Touch): void {
894 let column = this.columnController.getPrimaryColumn(colKey);
895 this.menuFactory.showMenuAfterMouseEvent(column, mouseEvent);
896 }
897
898 public hidePopupMenu(): void {
899 // hide the context menu if in enterprise
900 if (this.contextMenuFactory) {
901 this.contextMenuFactory.hideActiveMenu();
902 }
903 // and hide the column menu always
904 this.menuFactory.hideActiveMenu();
905 }
906
907 public setPopupParent(ePopupParent: HTMLElement): void {
908 this.gridOptionsWrapper.setProperty(GridOptionsWrapper.PROP_POPUP_PARENT, ePopupParent);
909 }
910
911 public tabToNextCell(): boolean {
912 return this.rowRenderer.tabToNextCell(false);
913 }
914
915 public tabToPreviousCell(): boolean {
916 return this.rowRenderer.tabToNextCell(true);
917 }
918
919 public getCellRendererInstances(params: GetCellRendererInstancesParams = {}): ICellRendererComp[] {
920 return this.rowRenderer.getCellRendererInstances(params);
921 }
922
923 public getCellEditorInstances(params: GetCellEditorInstancesParams = {}): ICellEditorComp[] {
924 return this.rowRenderer.getCellEditorInstances(params);
925 }
926
927 public getEditingCells(): GridCellDef[] {
928 return this.rowRenderer.getEditingCells();
929 }
930
931 public stopEditing(cancel: boolean = false): void {
932 this.rowRenderer.stopEditing(cancel);
933 }
934
935 public startEditingCell(params: StartEditingCellParams): void {
936 let column = this.columnController.getGridColumn(params.colKey);
937 if (!column) {
938 console.warn(`ag-Grid: no column found for ${params.colKey}`);
939 return;
940 }
941 let gridCellDef = <GridCellDef> {
942 rowIndex: params.rowIndex,
943 floating: params.rowPinned,
944 column: column
945 };
946 let gridCell = new GridCell(gridCellDef);
947 let notPinned = _.missing(params.rowPinned);
948 if (notPinned) {
949 this.gridPanel.ensureIndexVisible(params.rowIndex);
950 }
951 this.rowRenderer.startEditingCell(gridCell, params.keyPress, params.charPress);
952 }
953
954 public addAggFunc(key: string, aggFunc: IAggFunc): void {
955 if (this.aggFuncService) {
956 this.aggFuncService.addAggFunc(key, aggFunc);
957 }
958 }
959
960 public addAggFuncs(aggFuncs: {[key: string]: IAggFunc}): void {
961 if (this.aggFuncService) {
962 this.aggFuncService.addAggFuncs(aggFuncs);
963 }
964 }
965
966 public clearAggFuncs(): void {
967 if (this.aggFuncService) {
968 this.aggFuncService.clear();
969 }
970 }
971
972 public updateRowData(rowDataTransaction: RowDataTransaction): RowNodeTransaction {
973 let res: RowNodeTransaction = null;
974 if (this.clientSideRowModel) {
975 res = this.clientSideRowModel.updateRowData(rowDataTransaction);
976 } else if (this.infinitePageRowModel) {
977 this.infinitePageRowModel.updateRowData(rowDataTransaction);
978 } else {
979 console.error('ag-Grid: updateRowData() only works with ClientSideRowModel and InfiniteRowModel.');
980 }
981
982 // do change detection for all present cells
983 if (!this.gridOptionsWrapper.isSuppressChangeDetection()) {
984 this.rowRenderer.refreshCells();
985 }
986
987 return res;
988 }
989
990 public batchUpdateRowData(rowDataTransaction: RowDataTransaction, callback?: (res: RowNodeTransaction)=>void): void {
991 if (!this.clientSideRowModel) {
992 console.error('ag-Grid: api.batchUpdateRowData() only works with ClientSideRowModel.');
993 return;
994 }
995 this.clientSideRowModel.batchUpdateRowData(rowDataTransaction, callback);
996 }
997
998 public insertItemsAtIndex(index: number, items: any[], skipRefresh = false): void {
999 console.warn('ag-Grid: insertItemsAtIndex() is deprecated, use updateRowData(transaction) instead.');
1000 this.updateRowData({add: items, addIndex: index, update: null, remove: null});
1001 }
1002
1003 public removeItems(rowNodes: RowNode[], skipRefresh = false): void {
1004 console.warn('ag-Grid: removeItems() is deprecated, use updateRowData(transaction) instead.');
1005 let dataToRemove: any[] = rowNodes.map(rowNode => rowNode.data);
1006 this.updateRowData({add: null, addIndex: null, update: null, remove: dataToRemove});
1007 }
1008
1009 public addItems(items: any[], skipRefresh = false): void {
1010 console.warn('ag-Grid: addItems() is deprecated, use updateRowData(transaction) instead.');
1011 this.updateRowData({add: items, addIndex: null, update: null, remove: null});
1012 }
1013
1014 public refreshVirtualPageCache(): void {
1015 console.warn('ag-Grid: refreshVirtualPageCache() is now called refreshInfiniteCache(), please call refreshInfiniteCache() instead');
1016 this.refreshInfiniteCache();
1017 }
1018
1019 public refreshInfinitePageCache(): void {
1020 console.warn('ag-Grid: refreshInfinitePageCache() is now called refreshInfiniteCache(), please call refreshInfiniteCache() instead');
1021 this.refreshInfiniteCache();
1022 }
1023
1024 public refreshInfiniteCache(): void {
1025 if (this.infinitePageRowModel) {
1026 this.infinitePageRowModel.refreshCache();
1027 } else {
1028 console.warn(`ag-Grid: api.refreshInfiniteCache is only available when rowModelType='infinite'.`);
1029 }
1030 }
1031
1032 public purgeVirtualPageCache(): void {
1033 console.warn('ag-Grid: purgeVirtualPageCache() is now called purgeInfiniteCache(), please call purgeInfiniteCache() instead');
1034 this.purgeInfinitePageCache();
1035 }
1036
1037 public purgeInfinitePageCache(): void {
1038 console.warn('ag-Grid: purgeInfinitePageCache() is now called purgeInfiniteCache(), please call purgeInfiniteCache() instead');
1039 this.purgeInfiniteCache();
1040 }
1041
1042 public purgeInfiniteCache(): void {
1043 if (this.infinitePageRowModel) {
1044 this.infinitePageRowModel.purgeCache();
1045 } else {
1046 console.warn(`ag-Grid: api.purgeInfiniteCache is only available when rowModelType='infinite'.`);
1047 }
1048 }
1049
1050 // DEPRECATED
1051 public purgeEnterpriseCache(route?: string[]): void {
1052 console.warn(`ag-grid: since version 18.x, api.purgeEnterpriseCache() should be replaced with api.purgeServerSideCache()`);
1053 this.purgeServerSideCache(route);
1054 }
1055
1056 public purgeServerSideCache(route?: string[]): void {
1057 if (this.serverSideRowModel) {
1058 this.serverSideRowModel.purgeCache(route);
1059 } else {
1060 console.warn(`ag-Grid: api.purgeServerSideCache is only available when rowModelType='enterprise'.`);
1061 }
1062 }
1063
1064 // public removeFromEnterpriseCache(route: string[], items: any[]): void {
1065 // if (this.serverSideRowModel) {
1066 // this.serverSideRowModel.removeFromCache(route, items);
1067 // } else {
1068 // console.warn(`ag-Grid: api.removeFromEnterpriseCache is only available when rowModelType='enterprise'.`);
1069 // }
1070 // }
1071 //
1072 // public addToEnterpriseCache(route: string[], items: any[], index: number): void {
1073 // if (this.serverSideRowModel) {
1074 // this.serverSideRowModel.addToCache(route, items, index);
1075 // } else {
1076 // console.warn(`ag-Grid: api.addToEnterpriseCache is only available when rowModelType='enterprise'.`);
1077 // }
1078 // }
1079
1080 public getVirtualRowCount(): number {
1081 console.warn('ag-Grid: getVirtualRowCount() is now called getInfiniteRowCount(), please call getInfiniteRowCount() instead');
1082 return this.getInfiniteRowCount();
1083 }
1084
1085 public getInfiniteRowCount(): number {
1086 if (this.infinitePageRowModel) {
1087 return this.infinitePageRowModel.getVirtualRowCount();
1088 } else {
1089 console.warn(`ag-Grid: api.getVirtualRowCount is only available when rowModelType='virtual'.`);
1090 }
1091 }
1092
1093 public isMaxRowFound(): boolean {
1094 if (this.infinitePageRowModel) {
1095 return this.infinitePageRowModel.isMaxRowFound();
1096 } else {
1097 console.warn(`ag-Grid: api.isMaxRowFound is only available when rowModelType='virtual'.`);
1098 }
1099 }
1100
1101 public setVirtualRowCount(rowCount: number, maxRowFound?: boolean): void {
1102 console.warn('ag-Grid: setVirtualRowCount() is now called setInfiniteRowCount(), please call setInfiniteRowCount() instead');
1103 this.setInfiniteRowCount(rowCount, maxRowFound);
1104 }
1105
1106 public setInfiniteRowCount(rowCount: number, maxRowFound?: boolean): void {
1107 if (this.infinitePageRowModel) {
1108 this.infinitePageRowModel.setVirtualRowCount(rowCount, maxRowFound);
1109 } else {
1110 console.warn(`ag-Grid: api.setVirtualRowCount is only available when rowModelType='virtual'.`);
1111 }
1112 }
1113
1114 public getVirtualPageState(): any {
1115 console.warn('ag-Grid: getVirtualPageState() is now called getCacheBlockState(), please call getCacheBlockState() instead');
1116 return this.getCacheBlockState();
1117 }
1118
1119 public getInfinitePageState(): any {
1120 console.warn('ag-Grid: getInfinitePageState() is now called getCacheBlockState(), please call getCacheBlockState() instead');
1121 return this.getCacheBlockState();
1122 }
1123
1124 public getCacheBlockState(): any {
1125 if (this.infinitePageRowModel) {
1126 return this.infinitePageRowModel.getBlockState();
1127 } else if (this.serverSideRowModel) {
1128 return this.serverSideRowModel.getBlockState();
1129 } else {
1130 console.warn(`ag-Grid: api.getCacheBlockState() is only available when rowModelType='infinite' or rowModelType='serverSide'.`);
1131 }
1132 }
1133
1134 public checkGridSize(): void {
1135 this.gridPanel.setBodyAndHeaderHeights();
1136 }
1137
1138 public getFirstRenderedRow(): number {
1139 console.log('in ag-Grid v12, getFirstRenderedRow() was renamed to getFirstDisplayedRow()');
1140 return this.getFirstDisplayedRow();
1141 }
1142
1143 public getFirstDisplayedRow(): number {
1144 return this.rowRenderer.getFirstVirtualRenderedRow();
1145 }
1146
1147 public getLastRenderedRow(): number {
1148 console.log('in ag-Grid v12, getLastRenderedRow() was renamed to getLastDisplayedRow()');
1149 return this.getLastDisplayedRow();
1150 }
1151
1152 public getLastDisplayedRow(): number {
1153 return this.rowRenderer.getLastVirtualRenderedRow();
1154 }
1155
1156 public getDisplayedRowAtIndex(index: number): RowNode {
1157 return this.rowModel.getRow(index);
1158 }
1159
1160 public getDisplayedRowCount(): number {
1161 return this.rowModel.getRowCount();
1162 }
1163
1164 public paginationIsLastPageFound(): boolean {
1165 return this.paginationProxy.isLastPageFound();
1166 }
1167
1168 public paginationGetPageSize(): number {
1169 return this.paginationProxy.getPageSize();
1170 }
1171
1172 public paginationSetPageSize(size: number): void {
1173 this.gridOptionsWrapper.setProperty('paginationPageSize', size);
1174 }
1175
1176 public paginationGetCurrentPage(): number {
1177 return this.paginationProxy.getCurrentPage();
1178 }
1179
1180 public paginationGetTotalPages(): number {
1181 return this.paginationProxy.getTotalPages();
1182 }
1183
1184 public paginationGetRowCount(): number {
1185 return this.paginationProxy.getTotalRowCount();
1186 }
1187
1188 public paginationGoToNextPage(): void {
1189 this.paginationProxy.goToNextPage();
1190 }
1191
1192 public paginationGoToPreviousPage(): void {
1193 this.paginationProxy.goToPreviousPage();
1194 }
1195
1196 public paginationGoToFirstPage(): void {
1197 this.paginationProxy.goToFirstPage();
1198 }
1199
1200 public paginationGoToLastPage(): void {
1201 this.paginationProxy.goToLastPage();
1202 }
1203
1204 public paginationGoToPage(page: number): void {
1205 this.paginationProxy.goToPage(page);
1206 }
1207
1208 /*
1209 Taking these out, as we want to reconsider how we register components
1210
1211 public addCellRenderer(key: string, cellRenderer: {new(): ICellRenderer} | ICellRendererFunc): void {
1212 this.cellRendererFactory.addCellRenderer(key, cellRenderer);
1213 }
1214
1215 public addCellEditor(key: string, cellEditor: {new(): ICellEditor}): void {
1216 this.cellEditorFactory.addCellEditor(key, cellEditor);
1217 }*/
1218
1219}