Possible to update a row only by specifying changed column values?

Possible to update a row only by specifying changed column values?

northmoornorthmoor Posts: 10Questions: 5Answers: 0

I have a use case where I have a table that is updated (inserts and updates) in real-time. The first column in the table is a checkbox that is used to control the display of some data elsewhere in the application. I would like for the state of that checkbox to remain at whatever a user sets it to (checked, unchecked) regardless of any updates to the table. I update my table using code similar to this:

trackDataTable.row("#" + track.id).data({
        "DT_RowId":track.id,
        "DT_RowClass": DT_RowClass,
        "SELECT": checkBox,
        "CALLSIGN":track.radio,
        "OPERATOR":track.operator,
        "RANGE": track.range}).draw(false);

The problem with this is that the state of the checkbox is re-initialised every time the row is updated. I was hoping I could simply omit the checkbox column (select) from the update, to have something like this instead:

trackDataTable.row("#" + track.id).data({
        "DT_RowId":track.id,
        "DT_RowClass": DT_RowClass,
        "CALLSIGN":track.radio,
        "OPERATOR":track.operator,
        "RANGE": track.range}).draw(false);

However, when I do this, I receive the following error:

DataTables warning: table id=trackTable - Requested unknown parameter 'SELECT' for row 2, column 0. For more information about this error, please see http://datatables.net/tn/4

I can figure a way to maintain the state of the checkbox in a map and pass it into the update so that the state is maintained each time the row is updated, but I wondered if there was an easier way to achieve what I need using Datatables? I had assumed that as I'm passing in my data as named values that it could simply match the fields that needed updating and ignore anything else?

Many thanks!

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    I was hoping I could simply omit the checkbox column (select) from the update, to have something like this instead:

    If you are using the select extension does the row stay selected? If so you can check to if if its selected, for example:

    trackDataTable.row(track.id, {selected: true}).count()
    

    If the row with the DT_RowId of track.id is select this should return 1. If not it will return 0. You can set the checkbox appropriately. If this doesn't help or your not using select then please post a link to your page or a test case so we can see what you are doing.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

This discussion has been closed.