I'm currently attempting to dynamically populate the rows of ag-grid. The grid should only be displayed when a file is sent for validation and errors are detected. Below is my code:
columnDefs = [
{headerName: 'S.No.', field : 'SNo'},
{headerName: 'Error Description', field: 'Error_Description'},
{headerName: 'Suggestion', field: 'Suggestion'}
];
rowData = [
// {SNo :1, Error_Description:"Error 1", Suggestion: 'Suggestion 1'},
// {SNo :2, Error_Description:"Error 2", Suggestion: 'Suggestion 2'},
// {SNo :3, Error_Description:"Error 3", Suggestion: 'Suggestion 3'},
// {SNo :4, Error_Description:"Error 4", Suggestion: 'Suggestion 4'}
];
index.html
<ag-grid-angular [hidden]="isValid" class="ag-theme-balham" style="width: fit-content" [rowData]="rowData" [columnDefs]="columnDefs">
<!-- Show table -->
</ag-grid-angular>
Dynamic Population of Grid Rows
for(var i=0; i<this.errorMsgs.length; i++){
let errorObj={};
errorObj["SNo"]=i+1;
errorObj["Error_Description"]=this.errorMsgs[i];
errorObj["Suggestion"]="Put Some Suggestion";
this.rowData.push(errorObj);
}
When I use the hardcoded values (commented values), I see the expected output. However, when I attempt to populate the grid dynamically, the data is not being displayed. The data is pushed into the rowData array but it doesn't show up in the table. What could I be doing wrong? Thanks in advance and apologies if this is a basic question, as this is my first experience working with ag-grid.