I am working on an application built using angular2 with typescript. I am using ag-grid to display data in grid but not able to find the grid api.
///
You want to initialize gridOptions
as a property of the class, not just a variable. So it should be this.gridOptions
:
constructor(private _heroService: HeroService) {
console.log("in Grid constructor...");
this.columnDefs = [
{ headerName: "ID", field: "id", sortingOrder: ["asc", "desc"], editable: false, width: 100 },
{ headerName: "Name", field: "name", sortingOrder: ["asc", "desc"], editable: false, hide: false }
];
this._heroService.getHeroes().then(heroes => this.rowData = heroes);
this.gridOptions = {
enableSorting: true,
rowData: this.rowData,
columnDefs: this.columnDefs,
onReady: () => {
this.gridOptions.api.sizeColumnsToFit();
alert(this.gridOptions.api);
}
}
}