Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTable How to add row with attributes Jquery?

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.

like image 993
Manwal Avatar asked Dec 09 '25 05:12

Manwal


1 Answers

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

like image 165
Manwal Avatar answered Dec 11 '25 22:12

Manwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!