I have a datatable in a LWC where I allow users to update fields from the record. I am trying to add validation during save(or does the datatable have its own validation) to make sure 1 field value is not greater than another field. I have not been able to find any documentation or example. here is my .js save
export default class CreateInv extends LightningElement {
@track lineitems = [];
@track data = [];
@track columns = columns;
error;
columns = columns;
@wire(getLineItemList)
lineitems;
handleSave(event) {
const recordInputs = event.detail.draftValues.slice().map(draft => {
const fields = Object.assign({}, draft);
return { fields };
});
const promises = recordInputs.map(recordInput => updateRecord(recordInput));
Promise.all(promises).then(lineitems => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'line Item Updated',
variant: 'success'
})
);
this.draftValues = [];
return refreshApex(this.lineitems);
}).catch(error => {
});
}
async connectedCallback() {
const data = await fetchDataHelper({ amountOfRecords: 10 });
this.data = data;
}
handleclick(){
var el = this.template.querySelector('lightning-datatable');
console.log(el);
var selected = el.getSelectedRows();
console.log(selected);
}
}