I am trying to update a field in ag-grid and it keeps coming back with ERROR TypeError: Cannot assign to read only property 'quantity' of object '[object Object]'.
It allows me to edit the cell but when i try to update it comes up with this error.
I am using an observable from an ngrx store to populate the rowData as below:
this.order$.subscribe(order => {
this.order = { ...order, products: [...order.products] };
});
I have checked the above and I can update this object by saying this.orders.products = [] which says to me it is no longer immutable.
<mi-ag-grid [data]="order.products" [columnDefs]="columnDefs" [suppressClickEdit]="false"></mi-ag-grid>
columnDefs = [
{
headerName: 'Code',
field: 'code',
width: 150
},
{
headerName: 'Name',
field: 'name',
width: 200,
editable: true
},
{
headerName: 'Quantity',
field: 'quantity',
width: 150,
editable: true
}
];
I next tried suggestion from @GreyBeardedGeek and tried to set value with a valueSetter as per below, but still getting same error.
,
{
headerName: 'Quantity',
width: 150,
editable: true,
field: 'quantity',
valueSetter: quantityValueSetter
},
function quantityValueSetter(params): any {
console.log(params);
params.data.quantity = params.newValue;
}