How can I pass a html table row into DataTable.net fnAddData
Posted
by chobo2
on Stack Overflow
See other posts from Stack Overflow
or by chobo2
Published on 2010-05-16T19:04:41Z
Indexed on
2010/05/16
19:10 UTC
Read the original article
Hit count: 469
jQuery
|jquery-plugins
Hi
I am using the DataTable.net plugin and I am wondering how can I add dynamically a row to a existing table?
http://datatables.net/examples/api/add_row.html
I am looking at this example and they have it like this
/* Global variable for the DataTables object */
var oTable;
/* Global var for counter */
var giCount = 2;
$(document).ready(function() {
oTable = $('#example').dataTable();
} );
function fnClickAddRow() {
oTable.fnAddData( [
giCount+".1",
giCount+".2",
giCount+".3",
giCount+".4" ] );
giCount++;
}
but I am wondering what happens if I want I have a table row already rendered?
Say this is my table.
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
Now I have this
var newRow = '<tr><td>row 3, cell 1</td><td>row 3, cell 2</td></tr>';
How can I add it through addRow?
I tried oTable.fnAddData(newRow);
but that seems not to work.
So I am not sure how to do this.
© Stack Overflow or respective owner