I’m a big fan of the jquery datatables grid plugin, I think it’s one of the best grids around (www.datatables.net). However, I struggled to overcome quite a basic task – so I hope the example below might help somebody.
var oTable = $(‘#datatablesTable’).dataTable();
var oSettings = oTable.fnSettings();
var aiNew = oTable.fnAddData( [
data.description,
data.description,
data.description,
'0.00',
'0.00',
'0.00',
'<input type="text" id="qty'+ widgetId +'" readonly="readonly" value="0" style="width: 30px;" />',
'' ]);
var nNewTr = oSettings.aoData[ aiNew[0] ].nTr;
$(nNewTr).attr(‘id’, ’1);
The example above call the internal fnAddData function to inject a single row. It
then grabs the table row element in then NewTr variable and finally we use the .attr jquery function to create a new row id with the value 1 to the nNewTr element.