New row id and classes

New row id and classes

debdeb Posts: 3Questions: 0Answers: 0
edited April 2012 in DataTables 1.9
To insert a new row into a table I'm using:

fnAddData( ["str1","str2","str3", etc... ])

However, I would like to specify the id of the newly inserted TR, and also add some classes to it. Is that possible?

Thanks,

Deb

Replies

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Certainly is - use the DT_RowId property:

    [code]
    fnAddData( {
    "DT_RowId": "myId",
    "0": "str1",
    "1": "str2",
    "2": "str3",
    etc...
    } );
    [/code]

    Allan
  • koosvdkolkkoosvdkolk Posts: 169Questions: 0Answers: 0
    According to http://datatables.net/api, fnAddData should return the index(es) of the inserted row(s).

    Once you have these indexes, you can get the actual TR-element using fnGetNodes.
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    koosvdkolk's suggestion is the other way of doing it - good point!

    Allan
  • debdeb Posts: 3Questions: 0Answers: 0
    Thank you for your help, "DT_RowId": "myId" works perfectly!
This discussion has been closed.