Do table columns have a keys?

Do table columns have a keys?

sjw01sjw01 Posts: 67Questions: 36Answers: 1

I am updating a column when data is modified in a child

http://live.datatables.net/lidequra/21/edit

When child row expands and new data is entered - I update the relative column with the new value as follows:

    var tr = $(ro_form).closest('tr').prev();
    var row = table.row( tr ).data();

    // Update column in array with Yes and redraw row
    row[17] = expected_close_date;
    table
        .row( tr )
        .data( row )
        .draw();

Problem: When I add a new column, the row is moved and the updated column changes which I need to update. Sometimes I forget and for 1-2 days, the update doesn't work until I am alerted to it.

Do columns have keys? e.g Can I access the column via:

    // Update column in array with Yes and redraw row
    row["Expected Close Date"] = expected_close_date;

or similar?

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    If you are going to directly modify the data for a row, rather than attempting to use row().data() as a setter, use row().invalidate(). So your code above would become:

    var tr = $(ro_form).closest('tr').prev();
    var row = table.row( tr ).data();
     
    // Update column in array with Yes and redraw row
    row[17] = expected_close_date;
    table
        .row( tr )
        .invalidate()
        .draw();
    

    However, that is beside the point :).

    Do columns have keys? e.g Can I access the column via:

    You are using an array data source, so yes, you would need to update it using array notation. If you used objects, then you can update it with parameter names. See this section of the manual for details.

    Allan

This discussion has been closed.