function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jon Simmonds 11Jon Simmonds 11 

Best way to compare existing values and draft values in lightning-datatable?

Hello there,

I have a LWC that uses a lightning-datatable and I am loading the data via a wired Apex call to a controller.

The tables contains a number of records that represent questions. I want the user to answer the questions by ticking checkboxs that are on each row (question).

When first loaded none of the questions will have been answered but I need to ensure the user puts an answer for each question. So I have allowed inline editing so the user can update multiple rows in the table.

So my validation in the hnadleSave method has to check the values in draftvalues, but also has to check the exisitng values in the lightning-table as it needs to ensure ALL rows have a checkbox ticked.

Whats the easiest way to handle this?

I thought about looping through all the draftvalues but that only tells you the column values that have changed value, not all column values. And I need to check all the column values to do the validation.

I could also pull through the exisitng values using something like getElementId for the lightning- table but is this the easiest way of doing it?

Is there an easy way to be able to compare existing lighting-table values AND the new values in draft-values?