own td attribute(s)

own td attribute(s)

ozneroloznerol Posts: 2Questions: 0Answers: 0
edited September 2011 in General
Hi, i'm googling since this morning and I can't find an answer to my problem.

I've seen somewhere in this forum that i can add class or id attribute to a newly generated TR/TD.

I've seen that i could add an other kind of attribute in my TR/TD using fnAddData like this

var ai = oTable.fnAddData( a );
var n = oTable.fnSettings().aoData[ ai[0] ].nTr;
nTr.attr('foo', 'bar');

But, when data come from server (bServerSide = true), how can i fire this ?

It's really unfortunate that we can't add custom property easily as we can add id or class to newly generated TR/TD :)

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    fnRowCallback is called for every row rendered
    fnDrawCallback is called after a draw (after all rows rendered)

    use one of the callbacks. I recommend fnRowCallback, which passes you the DOM node (TR) as nRow.

    [code]
    $(document).ready(function() {
    $('#example').dataTable( {
    "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
    $(nRow).attr('foo', 'bar');

    return nRow;
    }
    } );
    } );
    [/code]
  • allanallan Posts: 63,530Questions: 1Answers: 10,474 Site admin
    Its actually a lot easier when doing it with server-side processing that it is with client-side! All you need to do is specify the DT_RowId and/or DT_RowClass properties of the objects for each row. This can be seen in action here:
    http://datatables.net/release-datatables/examples/server_side/ids.html

    and documented here:
    http://datatables.net/usage/server-side

    Allan
This discussion has been closed.