Sum rows in table with edited cells

I have a table where a column of percentage cells are editable. I want to make sure the user cannot save changes unless all of the rows add up to 100% (including the edited cell). The problem I'm having is that table.displayedData does not use the edited cell value, but uses the original value before the user changed it.

Hey dan1989! Thanks for reaching out about this. Any changes made to a table's editable cells are stored in table.recordUpdates.

Unfortunately, it's not a direct mapping of table row index to recordUpdate row index. Do your rows have a unique identifier like an id?

1 Like

Hey @dan1989!

I made an example on how you can do logic like this using @joeBumbaca 's record updates and a temporary state. There are probably some better ways to do this too.

So basically what you could do is map and add all values from that row together for each object inside of the recordUpdates array inside of a temporary state array. Then create a boolean expression:
{{>parseFloat( + parseFloat(d.sales) == 60)}}

The temprorary state gains a false value unless the ID and sales add up to 60. Then set the disable save changes to false for when this temporary state includes false

{{_.includes(state2.value, false)}}

If I wanted to do this for a single column I could change up my syntax a bit:

Temporary State: {{_.sum(>parseFloat( == 50}} - This tests if all IDS add up to 50

Disable save: {{state2.value == false}} - we can just set this as a boolean expression since we no longer have an array

Hope that helps!

1 Like