lose class at row after redraw of the table

lose class at row after redraw of the table

diemdiem Posts: 2Questions: 0Answers: 0
edited January 2012 in General
Hi,

how should I add a class to a -tag if I have to make a redraw the table??
After the fnDraw the additional class is lost :(

$('tr.xxxxx').live('click', function () {
$(this).addClass('row_selected');
... insert rows (_fnAddData) ... do something ...
oTable.fnDraw();
});

How can I do this without to lose the new class??

Thank you!

Dieter

Replies

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Hi Dieter,

    The extra class will be kept on the row, as long as it is using client-side processing (which I think you are).

    Here is an example showing that: http://live.datatables.net/ehuloj/edit . It adds a class to the last row to make it background: grey, and then does a draw.

    Allan
  • diemdiem Posts: 2Questions: 0Answers: 0
    Hi allan,

    this is exactly what I am doing:

    $('#palreport tbody tr.hassub').live('click', function () {

    ..... ajax-call to get data .....

    // mark the parent row as selected
    $(this).addClass('row_selected');
    // insert the new rows after the parent row
    addnewRows(nTr,data);
    });

    function addnewRows(aTr,data) {
    for (var i = $(data.aaData).length-1; i >= 0; --i) {
    oTable.fnAddAfter(aTr,$(data.aaData)[i], false);
    }
    oTable.fnDraw();
    }

    Before the "oTable.fnDraw();" the class is set correctly ... after that the class is the same as before :(


    Dieter
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    For anyone else who comes across this thread, I've talked to Dieter about this offline. Basically the problem was the use of className to set the call for elements in fnRowCallback (not shown in the above code, but that is what was happening).

    It is generally much better to use jQuery's addClass and removeClass, particularly if you don't want to overwrite some old classes.

    Allan
This discussion has been closed.