I have a datatable which displays records retrieved from api. one of the columns is editable (and is blank on load). One of the issues I have is that i cannot use the refreshApex
because the data don't exist in the database yet. So, when the column is edited and saved, i would like to update the current table data.
columns:
const COLUMNS = [
{ label: 'Ref', fieldName: 'ref', type: 'text' },
{ label: 'Dril Date', fieldName: 'drilDate', type: 'text' },
{ label: 'Dril Amount', fieldName: 'drilAmount', type: 'text' },
{ label: 'Description', fieldName: 'description', type: 'text', editable: true }];
To do this, I have tried:
handleSave(event) {
for(var i = 0; i < this.data.length; i++) {
let draftValues = this.template.querySelector('lightning-datatable').draftValues;
for(var d = 0; d < draftValues.length; d++){
let rowId = draftValues[d].id.slice(draftValues[d].id.lastIndexOf('-') + 1);
if(i == rowId){
let dataRow = {...this.data[rowId], ...{description: draftValues[d].description}};
console.log(dataRow);
this.data[rowId] = {...this.data[rowId], dataRow};
}
}
}
this.draftValues = [];
}
however, this throws NoErrorObjectAvailable
error