Add Class to new row using scroller plug-in

Add Class to new row using scroller plug-in

dsnapdsnap Posts: 23Questions: 3Answers: 0
edited November 2012 in General
I tried using what Allan suggested on this post, http://www.datatables.net/forums/discussion/181/fnadddata-and-add-class/p1
[code]
var newRowAdding = groupTable.fnAddData([
userData[0],
userData[1],
userData[2],
userData[3]
]);
var newRow = groupTable.fnSettings().aoData[ newRowAdding[0] ].nTr;
if ($(this).hasClass('changed')) {
newRow.setAttribute('class', '');
} else {
newRow.setAttribute('class', 'changed');
}
[/code]

This works, but only so long as the row being added is currently in the scroller view (which make sense since it is merely looking for the latest row added to the DOM). Is there something else I can do to add a class to a row?

Replies

  • dsnapdsnap Posts: 23Questions: 3Answers: 0
    I found this, http://www.datatables.net/docs/Scroller/1.1.0/Scroller.html#fnScrollToRow

    Is there a way to snag the index of the row that was just created?
    Something like...
    [code]
    var newRowAdding = groupTable.fnAddData([
    userData[0],
    userData[1],
    userData[2],
    userData[3]
    ]);
    var oSettings = groupTable.fnSettings();
    oSettings.oScroller.fnScrollToRow(newRowAdding[0]);
    var newRow = groupTable.fnSettings().aoData[ newRowAdding[0] ].nTr;
    if ($(this).hasClass('changed')) {
    newRow.setAttribute('class', '');
    } else {
    newRow.setAttribute('class', 'changed');
    }
    [/code]
    note, this doesn't work. it just scrolls me to the bottom of the table from the top of the table, even if I was originally in the middle of the table.
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    I'd suggest you use fnCreatedRow - which is the DataTables method for manipulating newly created rows.

    Allan
  • dsnapdsnap Posts: 23Questions: 3Answers: 0
    How do I call that function after init so it doesn't apply the class to every row in the table?
This discussion has been closed.