3

I am using Datatable plugin in table. I am adding row dynamically by Jquery:

var t = $('#example').DataTable();
 t.row.add( [
    counter +'.1',
    counter +'.2',
    counter +'.3',
    counter +'.4',
    counter +'.5'
] ).draw();

Here is fiddle Demo. But i haven't found anything how can i add attributes on <tr>?

As per my need i want to add data-id,class,id and any other attributes.

1 Answer 1

1

This is how i solved my problem:

var data = [
    counter +'.1',
    counter +'.2',
    counter +'.3',
    counter +'.4',
    counter +'.5'
];
var rowIndex = t.fnAddData(data);
var row = t.fnGetNodes(rowIndex);
$(row).attr( 'id', 'MyUniqueID' );

Working DEMO and Details

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.