Search code examples
javascriptjquerydatatables

Update a row using DataTable()


I would like to know the correct way to update/redraw a table row using the new API. Old questions suggest table.fnUpdate. Should I still be using the old API for this?

The new API tells me nothing about updating rows.

Thanks in advance!


Solution

  • I had a similar issue recently. I believe row().data() is what you are looking for https://datatables.net/reference/api/row%28%29.data%28%29

    For example:

    table.row( 0 ).data( newData ).draw();
    

    Alternatively, you can use row().invalidate() https://datatables.net/reference/api/row%28%29.invalidate%28%29

    var initialData = [new Data(), new Data()];
    var table = $('#foo').Datatable({
      data: initialData
    });
    initialData[0].bar = 5;
    table.row(0).invalidate().draw();
    

    This is more useful if you are deriving your data from an external data source.