Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Detecting for changes on table cells and sending to the backend

Hello,

I am fetching data from the backend and displaying it in the frontend (HTML + CSS, not anything fancy).

I output the table data inside input elements (each td), so if a user wants to change the cell's value he will edit the value inside the cell, then press the save button at the bottom.

But I need a good way to be able to detect what cells were changes before I send it to the backend to update the DB.

This is what I was thinking about, tell me if it's OK and if you think there's a better way:

Initially I will output the id of the row from the DB in a data-attribute, so I will have the id to update, and I will add a listener on every input element of the table, maybe using jQuery, something like:

$('#myTable input').on('change'......

Then, I will build an object with JavaScript that will use the row id as the key, and an array of the changed cells, so I will end up with sort of this object:

["1"] => [column1_new_value, column6_new_value]
["20"] => [column8_new_value, column9_new_value, column3_new_value]
["44"] => [column4_new_value, column5_new_value, column6_new_value]

then will send this object as JSON to the backend and update the the DB.

Is it a good idea? Anything I'm missing or a better solution?

Ty!

0 likes
7 replies
Sinnbeck's avatar

Any reason to only send the changed fields and not just all fields? If they haven't changed, I see no problem saving the value again

1 like
Sinnbeck's avatar

@Ligonsker ah sorry missed that it was a table. So they change cells in a row and can save that row, instead of clicking edit and edit either in a modal or different page?

1 like
Ligonsker's avatar

@Sinnbeck The current UI was already done as I described, however implemented very badly both on front and back (It's the same table from my post with the 75MB of data).

So now they got used to this way and their request was to keep the front as is with table cells as inputs, and a save button at the bottom, so that they can change any cell they want instead of opening a modal for each row they wanna edit. I guess it's more convenient to be able to edit it this way

Sinnbeck's avatar

@Ligonsker ok so just a single save button to save everything instead of one for each row?

1 like
Sinnbeck's avatar

In that case a simple solution would be to have an array of each row that was changed and then just send those rows values to the backend on save :)

1 like
Ligonsker's avatar

@Sinnbeck yes single save button. Ok so I thought about making an update for specific cell because I thought it's just sending unnecessary data but you're right since I don't think someone will ever change that many rows at once, thank you

Please or to participate in this conversation.