I've been working with Ag-grid and facing an issue.
Initially, I load the original data into the grid using this.rowData
.
I have a function called addRow
that successfully adds a row to the top of the existing rows.
However, when the reset
function is called, I need to update the grid with the original data stored in this.rowData
.
The problem arises when I click on addRow
- it seems to update the this.rowData
as well.
Below is a snippet of my code:
Original Data:
this._Service.httpPost(Request, Url).subscribe(data => {
responseJson = JSON.parse(JSON.stringify(data));
this.rowData = responseJson;
this.gridOptions.api.setRowData(this.rowData); // displays 6 rows
});
addRow:
addRow() {
let rowData = this.rowData; // creating a local variable
rowData.unshift(newData);// rowData now has 7 rows
this.gridOptions.api.setRowData(rowData);// rowData still has 7 rows
console.log(this.rowData) // returns 7, unsure why `this.rowData` is getting modified
}