I'm currently facing a minor issue with the Kendo Grid for Angular.
My attempt to bind data after fetching is resulting in the following error:
ERROR TypeError: Cannot read properties of undefined (reading 'api')
This indicates that
this.agGrid.api.setRowData(result.value)
is causing trouble. Below is my code snippet:
public columnDefs = [
{
headerName: 'productTitle',
field: 'productTitle',
sortable: true,
filter: true,
},
{
headerName: 'productDescription',
field: 'productDescription',
sortable: true,
filter: true,
},
];
public rowData$: Observable<Product[]>;
// To access the API of the Grid
@ViewChild('productGrid') agGrid: AgGridAngular;
// component initialization
ngOnInit() {
this.getProducts();
}
// retrieve all product types
getProducts(odataQueryString: string = undefined): any {
this.productService
.getAll_Product(odataQueryString)
.subscribe((result: ODataResponse<Product[]>) => {
if (result) {
this.agGrid.api.setRowData(result.value);
}
});
}
HTML
<div class="body flex-grow-1 px-3">
<div class="container-lg">
<div class="row">
<div class="col-lg-12">
<ag-grid-angular
id="productGrid"
style="width: 100%; height: 100%"
class="ag-theme-alpine"
[columnDefs]="columnDefs"
[rowData]="rowData$ | async"
enablecolresize
enablesorting
enablefilter
rowheight="22"
rowselection="multiple"
>
<ag-grid-column
headerName="productTitle"
field="productTitle"
[width]="125"
></ag-grid-column>
<ag-grid-column
headerName="productDescription"
field="productDescription"
[width]="120"
></ag-grid-column>
</ag-grid-angular>
</div>
</div>
</div>
</div>