Does value change in column require redraw?

Does value change in column require redraw?

chobo2chobo2 Posts: 23Questions: 2Answers: 0

Hi

I have a checkbox in my datatables(1.10) that when checked another column(checkInDate) in that row gets updated with a date. To update this checkInDate Column I use jquery

$('#datatables').on('change', '.my-checkbox', function(e) {
var $checkInDateColumn = $that.parent().siblings('td').children('.check-in-date');
// ajax call
$checkInDateColumn.text(result);
});

Now I noticed that when I tried to order that column this new date does not get ordered properly. I don't know if this because my manipulation of the column or because this column can have blank dates and I don't know if moment is handling it properly

I do have this set: $.fn.dataTable.moment( 'MM/DD/YYYY' );

but I don't know if this can handle blank dates.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,219Questions: 1Answers: 10,416 Site admin
    Answer ✓

    You can't just change the HTML (or text in this case) and expect DataTables to know about it I'm afraid.

    You need to use either cell().data() to change the cell's data via the API, or use your current method and then cell().invalidate() or rows().invalidate() to tell DataTables that the data has changed and it should be re-read.

    Allan

  • chobo2chobo2 Posts: 23Questions: 2Answers: 0

    Yea

    I thought that would be the case that's what I was hoping just draw would do it all but looks like I need an extra step. I don't really understand how to use cell.data()(not sure what I am passing into it).

    Is any one of these method more efficient vs the other?

  • allanallan Posts: 63,219Questions: 1Answers: 10,416 Site admin

    The easiest code wise is to do:

    table.rows().invalidate().draw( false );
    

    That will reread the data from all rows, so it is also the slowest option - although with a small / medium sized table, you'll never notice the difference. How large is your table (in rows and columns).

    Allan

This discussion has been closed.