ag-grid-row-unselectable-angular
Version:
A fork version of ag-grid-angular with row selection disable function added
388 lines (365 loc) • 19.3 kB
text/typescript
import {
Component,
EventEmitter,
Input,
Output,
ViewEncapsulation,
ViewContainerRef,
ElementRef,
ContentChildren,
QueryList,
AfterViewInit,
ComponentFactoryResolver
} from "@angular/core";
import {Grid, GridOptions, GridApi, ColumnApi, GridParams, ComponentUtil} from "ag-grid-row-unselectable/main";
import {Ng2FrameworkFactory} from "./ng2FrameworkFactory";
import {AgGridColumn} from "./agGridColumn";
import {Ng2FrameworkComponentWrapper} from "./ng2FrameworkComponentWrapper";
export class AgGridNg2 implements AfterViewInit {
// not intended for user to interact with. so putting _ in so if user gets reference
// to this object, they kind'a know it's not part of the agreed interface
private _nativeElement: any;
private _initialised = false;
private _destroyed = false;
private gridParams: GridParams;
// making these public, so they are accessible to people using the ng2 component references
public api: GridApi;
public columnApi: ColumnApi;
public columns: QueryList<AgGridColumn>;
constructor(elementDef: ElementRef,
private viewContainerRef: ViewContainerRef,
private ng2FrameworkFactory: Ng2FrameworkFactory,
private frameworkComponentWrapper: Ng2FrameworkComponentWrapper,
private _componentFactoryResolver: ComponentFactoryResolver) {
this._nativeElement = elementDef.nativeElement;
// create all the events generically. this is done generically so that
// if the list of grid events change, we don't need to change this code.
this.createComponentEvents();
this.ng2FrameworkFactory.setViewContainerRef(this.viewContainerRef);
this.frameworkComponentWrapper.setViewContainerRef(this.viewContainerRef);
this.frameworkComponentWrapper.setComponentFactoryResolver(this._componentFactoryResolver);
}
private createComponentEvents() {
ComponentUtil.EVENTS.forEach((eventName) => {
(<any>this)[eventName] = new EventEmitter();
});
}
ngAfterViewInit(): void {
this.gridOptions = ComponentUtil.copyAttributesToGridOptions(this.gridOptions, this);
this.gridParams = {
globalEventListener: this.globalEventListener.bind(this),
frameworkFactory: this.ng2FrameworkFactory,
seedBeanInstances: {
frameworkComponentWrapper: this.frameworkComponentWrapper
}
};
if (this.columns && this.columns.length > 0) {
this.gridOptions.columnDefs = this.columns
.map((column: AgGridColumn) => {
return column.toColDef();
});
}
new Grid(this._nativeElement, this.gridOptions, this.gridParams);
if (this.gridOptions.api) {
this.api = this.gridOptions.api;
}
if (this.gridOptions.columnApi) {
this.columnApi = this.gridOptions.columnApi;
}
this._initialised = true;
}
public ngOnChanges(changes: any): void {
if (this._initialised) {
ComponentUtil.processOnChange(changes, this.gridOptions, this.api, this.columnApi);
}
}
public ngOnDestroy(): void {
if (this._initialised) {
// need to do this before the destroy, so we know not to emit any events
// while tearing down the grid.
this._destroyed = true;
this.api.destroy();
}
}
private globalEventListener(eventType: string, event: any): void {
// if we are tearing down, don't emit angular events, as this causes
// problems with the angular router
if (this._destroyed) {
return;
}
// generically look up the eventType
let emitter = <EventEmitter<any>> (<any>this)[eventType];
if (emitter) {
emitter.emit(event);
} else {
console.log('ag-Grid-ng2: could not find EventEmitter: ' + eventType);
}
}
/**
* inputs
*/
public gridOptions: GridOptions;
public slaveGrids: any = undefined;
public rowData: any = undefined;
public floatingTopRowData: any = undefined;
public floatingBottomRowData: any = undefined;
public columnDefs: any = undefined;
public defaultColDef: any = undefined;
public rowStyle: any = undefined;
public context: any = undefined;
public groupColumnDef: any = undefined;
public localeText: any = undefined;
public icons: any = undefined;
public datasource: any = undefined;
public enterpriseDatasource: any = undefined;
public viewportDatasource: any = undefined;
public groupRowRendererParams: any = undefined;
public aggFuncs: any = undefined;
public fullWidthCellRendererParams: any = undefined;
public sortingOrder: any = undefined;
public rowClass: any = undefined;
public rowSelection: any = undefined;
public overlayLoadingTemplate: any = undefined;
public overlayNoRowsTemplate: any = undefined;
public headerCellTemplate: any = undefined;
public quickFilterText: any = undefined;
public rowModelType: any = undefined;
public rowHeight: any = undefined;
public rowBuffer: any = undefined;
public colWidth: any = undefined;
public headerHeight: any = undefined;
public groupDefaultExpanded: any = undefined;
public minColWidth: any = undefined;
public maxColWidth: any = undefined;
public viewportRowModelPageSize: any = undefined;
public viewportRowModelBufferSize: any = undefined;
public layoutInterval: any = undefined;
public autoSizePadding: any = undefined;
public maxPagesInCache: any = undefined;
public maxConcurrentDatasourceRequests: any = undefined;
public paginationOverflowSize: any = undefined;
public paginationPageSize: any = undefined;
public paginationInitialRowCount: any = undefined;
public headerCellRenderer: any = undefined;
public localeTextFunc: any = undefined;
public groupRowInnerRenderer: any = undefined;
public groupRowRenderer: any = undefined;
public isScrollLag: any = undefined;
public isExternalFilterPresent: any = undefined;
public getRowHeight: any = undefined;
public doesExternalFilterPass: any = undefined;
public getRowClass: any = undefined;
public getRowStyle: any = undefined;
public getHeaderCellTemplate: any = undefined;
public traverseNode: any = undefined;
public getContextMenuItems: any = undefined;
public getMainMenuItems: any = undefined;
public processRowPostCreate: any = undefined;
public processCellForClipboard: any = undefined;
public getNodeChildDetails: any = undefined;
public groupRowAggNodes: any = undefined;
public getRowNodeId: any = undefined;
public isFullWidthCell: any = undefined;
public fullWidthCellRenderer: any = undefined;
public doesDataFlower: any = undefined;
public toolPanelSuppressRowGroups: any = undefined;
public toolPanelSuppressValues: any = undefined;
public toolPanelSuppressPivots: any = undefined;
public toolPanelSuppressPivotMode: any = undefined;
public suppressRowClickSelection: any = undefined;
public suppressCellSelection: any = undefined;
public suppressHorizontalScroll: any = undefined;
public suppressScrollOnNewData: any = undefined;
public debug: any = undefined;
public enableColResize: any = undefined;
public enableCellExpressions: any = undefined;
public enableSorting: any = undefined;
public enableServerSideSorting: any = undefined;
public enableFilter: any = undefined;
public enableServerSideFilter: any = undefined;
public angularCompileRows: any = undefined;
public angularCompileFilters: any = undefined;
public angularCompileHeaders: any = undefined;
public groupSuppressAutoColumn: any = undefined;
public groupSelectsChildren: any = undefined;
public groupIncludeFooter: any = undefined;
public groupUseEntireRow: any = undefined;
public groupSuppressRow: any = undefined;
public groupSuppressBlankHeader: any = undefined;
public forPrint: any = undefined;
public suppressMenuHide: any = undefined;
public rowDeselection: any = undefined;
public unSortIcon: any = undefined;
public suppressMultiSort: any = undefined;
public suppressScrollLag: any = undefined;
public singleClickEdit: any = undefined;
public suppressLoadingOverlay: any = undefined;
public suppressNoRowsOverlay: any = undefined;
public suppressAutoSize: any = undefined;
public suppressParentsInRowNodes: any = undefined;
public showToolPanel: any = undefined;
public suppressColumnMoveAnimation: any = undefined;
public suppressMovableColumns: any = undefined;
public suppressFieldDotNotation: any = undefined;
public enableRangeSelection: any = undefined;
public suppressEnterprise: any = undefined;
public rowGroupPanelShow: any = undefined;
public pivotPanelShow: any = undefined;
public suppressContextMenu: any = undefined;
public suppressMenuFilterPanel: any = undefined;
public suppressMenuMainPanel: any = undefined;
public suppressMenuColumnPanel: any = undefined;
public enableStatusBar: any = undefined;
public rememberGroupStateWhenNewData: any = undefined;
public enableCellChangeFlash: any = undefined;
public suppressDragLeaveHidesColumns: any = undefined;
public suppressMiddleClickScrolls: any = undefined;
public suppressPreventDefaultOnMouseWheel: any = undefined;
public suppressUseColIdForGroups: any = undefined;
public suppressCopyRowsToClipboard: any = undefined;
public pivotMode: any = undefined;
public suppressAggFuncInHeader: any = undefined;
public suppressColumnVirtualisation: any = undefined;
public suppressFocusAfterRefresh: any = undefined;
public functionsPassive: any = undefined;
public functionsReadOnly: any = undefined;
public defaultColGroupDef: any = undefined;
public editType: any = undefined;
public scrollbarWidth: any = undefined;
public groupRowInnerRendererFramework: any = undefined;
public groupRowRendererFramework: any = undefined;
public fullWidthCellRendererFramework: any = undefined;
public processSecondaryColDef: any = undefined;
public processSecondaryColGroupDef: any = undefined;
public suppressRowHoverClass: any = undefined;
public suppressTouch: any = undefined;
public animateRows: any = undefined;
public groupSelectsFiltered: any = undefined;
public groupRemoveSingleChildren: any = undefined;
public getBusinessKeyForNode: any = undefined;
public checkboxSelection: any = undefined;
public enableRtl: any = undefined;
public suppressClickEdit: any = undefined;
public enableRtlSupport: any = undefined;
public excelStyles: any = undefined;
public dateComponent: any = undefined;
public dateComponentFramework: any = undefined;
public dateComponentParams: any = undefined;
public sendToClipboard: any = undefined;
public navigateToNextCell: any = undefined;
public tabToNextCell: any = undefined;
public processCellFromClipboard: any = undefined;
public getDocument: any = undefined;
public enableGroupEdit: any = undefined;
public embedFullWidthRows: any = undefined;
public suppressTabbing: any = undefined;
public suppressPaginationPanel: any = undefined;
public paginationStartPage: any = undefined;
public floatingFilter: any = undefined;
public groupHideOpenParents: any = undefined;
public defaultExportParams: any = undefined;
public infiniteBlockSize: any = undefined;
public infiniteInitialRowCount: any = undefined;
public allowContextMenuWithControlKey: any = undefined;
public groupMultiAutoColumn: any = undefined;
public pagination: any = undefined;
public stopEditingWhenGridLosesFocus: any = undefined;
public paginationAutoPageSize: any = undefined;
public groupHeaderHeight: any = undefined;
public floatingFiltersHeight: any = undefined;
public pivotHeaderHeight: any = undefined;
public pivotGroupHeaderHeight: any = undefined;
public maxBlocksInCache: any = undefined;
public cacheOverflowSize: any = undefined;
public suppressAggAtRootLevel: any = undefined;
public purgeClosedRowNodes: any = undefined;
public postProcessPopup: any = undefined;
public suppressAsyncEvents: any = undefined;
public cacheQuickFilter: any = undefined;
/**
* Outputs
*/
public gridReady: EventEmitter<any>;
public columnEverythingChanged: EventEmitter<any>;
public newColumnsLoaded: EventEmitter<any>;
public columnPivotModeChanged: EventEmitter<any>;
public columnRowGroupChanged: EventEmitter<any>;
public columnPivotChanged: EventEmitter<any>;
public gridColumnsChanged: EventEmitter<any>;
public columnValueChanged: EventEmitter<any>;
public columnMoved: EventEmitter<any>;
public columnVisible: EventEmitter<any>;
public columnPinned: EventEmitter<any>;
public columnGroupOpened: EventEmitter<any>;
public columnResized: EventEmitter<any>;
public displayedColumnsChanged: EventEmitter<any>;
public virtualColumnsChanged: EventEmitter<any>;
public rowGroupOpened: EventEmitter<any>;
public rowDataChanged: EventEmitter<any>;
public floatingRowDataChanged: EventEmitter<any>;
public rangeSelectionChanged: EventEmitter<any>;
public columnRowGroupAddRequest: EventEmitter<any>;
public columnRowGroupRemoveRequest: EventEmitter<any>;
public columnPivotAddRequest: EventEmitter<any>;
public columnPivotRemoveRequest: EventEmitter<any>;
public columnValueAddRequest: EventEmitter<any>;
public columnValueRemoveRequest: EventEmitter<any>;
public columnAggFuncChangeRequest: EventEmitter<any>;
public clipboardPaste: EventEmitter<any>;
public modelUpdated: EventEmitter<any>;
public cellClicked: EventEmitter<any>;
public cellDoubleClicked: EventEmitter<any>;
public cellContextMenu: EventEmitter<any>;
public cellValueChanged: EventEmitter<any>;
public cellFocused: EventEmitter<any>;
public rowSelected: EventEmitter<any>;
public selectionChanged: EventEmitter<any>;
public filterChanged: EventEmitter<any>;
public filterModified: EventEmitter<any>;
public sortChanged: EventEmitter<any>;
public virtualRowRemoved: EventEmitter<any>;
public rowClicked: EventEmitter<any>;
public rowDoubleClicked: EventEmitter<any>;
public gridSizeChanged: EventEmitter<any>;
public viewportChanged: EventEmitter<any>;
public dragStarted: EventEmitter<any>;
public dragStopped: EventEmitter<any>;
public itemsAdded: EventEmitter<any>;
public itemsRemoved: EventEmitter<any>;
public columnRowGroupChangeRequest: EventEmitter<any>;
public columnPivotChangeRequest: EventEmitter<any>;
public columnValueChangeRequest: EventEmitter<any>;
public rowValueChanged: EventEmitter<any>;
public bodyScroll: EventEmitter<any>;
public rowEditingStarted: EventEmitter<any>;
public rowEditingStopped: EventEmitter<any>;
public cellEditingStarted: EventEmitter<any>;
public cellEditingStopped: EventEmitter<any>;
public displayedColumnsWidthChanged: EventEmitter<any>;
public scrollVisibilityChanged: EventEmitter<any>;
public flashCells: EventEmitter<any>;
public cellMouseOver: EventEmitter<any>;
public cellMouseOut: EventEmitter<any>;
public columnHoverChanged: EventEmitter<any>;
public paginationReset: EventEmitter<any>;
public paginationPageLoaded: EventEmitter<any>;
public paginationPageRequested: EventEmitter<any>;
public paginationChanged: EventEmitter<any>;
public bodyHeightChanged: EventEmitter<any>;
public componentStateChanged: EventEmitter<any>;
// deprecated
public beforeFilterChanged: EventEmitter<any>;
public afterFilterChanged: EventEmitter<any>;
public beforeSortChanged: EventEmitter<any>;
public afterSortChanged: EventEmitter<any>;
}