Update and Redraw Single Row Only

Update and Redraw Single Row Only

mrtomdmrtomd Posts: 4Questions: 2Answers: 0
edited February 2017 in Free community support

I want to update the data for a single row. I don't want the entire table to redraw because it takes the person away from where they were, making it hard to work on subsequent rows back to back to back.

I grab the data for the row, manipulate one cell, and then redraw.

var temp = table.row(5).data();
temp[0] = 'Tom';
table.row(5).data(temp).draw();

This redraws the entire table. Is there a way to just redraw the row?

Answers

  • mrtomdmrtomd Posts: 4Questions: 2Answers: 0

    The solution was to use fnUpdate() with the redraw parameter set to false.

    var temp = table.row(5).data();
    temp[0] = 'Tom';
    $('#table1').dataTable().fnUpdate(temp,5,undefined,false);
    
  • adcomentadcoment Posts: 1Questions: 0Answers: 0

    Another way- which is api only vs. object method:

    var temp = table.row(5).data();
    temp[0] = 'Tom';
    table.row(5).data(temp).invalidate();

  • sovicheachethsovicheacheth Posts: 1Questions: 0Answers: 0

    Thank you for the solution.

    Below are what it has been worked around for my case. Just in case anyone wants to update the row base on the row class or id.

    var table = $('#table1').dataTable();
    temp[0] = 'Tom';
    table.fnUpdate(temp, $('tr#rowId'), undefined, false);

  • jithubabujithubabu Posts: 2Questions: 1Answers: 0

    Hi,
    I am in a need of updating a single row in a table rather than loading the whole table which piles up my memory. So in order to update a row I wanted to identify the row to be updated by some identifier may be a row id and perform the update of the coumns in that specific row. How can I achieve this. I tried fnupdate but seems to have depricated.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @jithubabu ,

    You can update row data with row().data().

    If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.