Monday, April 9, 2018

ag-grid gridOptions.api undefined in angular 2

I am trying ag-grid in angular2 with typescript, for some reasons I am not able to use the ag-grid APIs, getting undefined error.,



here is the code..,




import { AgRendererComponent } from 'ag-grid-ng2/main';
import { GridOptions, RowNode } from 'ag-grid/main';
import { GridOptionsWrapper } from 'ag-grid/main';
import { GridApi } from 'ag-grid/main';

public gridOptions: GridOptions;

constructor()
{

this.gridOptions = {};

alert(this.gridOptions);
alert(this.gridOptions.api); // *** getting undefined ***


this.gridOptions = {
columnDefs: this.columnDefs(),
rowData: this.rowData,
onSelectionChanged: this.onSelectionChanged,

groupSelectsChildren: true,
suppressRowClickSelection: true,

rowSelection: 'multiple',
enableColResize: true,
enableSorting: true,
rowHeight: 45}

}//constructor



Please advise, Thanks



Updated with code in comment below



onGridReady() {
console.log(this.gridOptions.api); // here it work
this.selectedRows = this.gridOptions.api.getSelectedRows();
console.log(this.selectedRows);
}


private testClick(event): void {
try {
console.log(this.gridOptions.api); // here gives error
this.selectedRows = this.gridOptions.api.getSelectedRows();
console.log(this.selectedRows); //getting error saying undefined
}
}

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...