how to add rows to a table
how to add rows to a table
Type function rows.add( data ) Description: Add new rows to the table using the data given Parameters: Name Type Optional 1 data array No Array of data elements, with each one describing a new row to be added to the table (i.e. data.length is the number of new rows that will be added to the table). Each data element may be an array, object, Javascript object instance or a tr element. The data structure given must be in the same format as the other data in the table (i.e. if your table uses objects, pass in an object here!). Returns: DataTables.Api DataTables API instance with the newly added rows in its result set. row.add is described like this in the documentation. What is a tr element described above? _I have a whole row from to it is considered a tr element. i use jquery append and append multiple .... to the tbody of the tables assigned id tag. Is that correct usage? If the rows are on the not shown table i use $.fn.dataTable .columns.adjust() to redraw
Answers
Hi @alex9134 ,
A
tr
element is just a HTMLtr
element, i.e. "<tr><td>dfgdfg</td></tr>"If you're doing that, before you initialise the DataTable, that's fine. If you're doing it after the DataTables initialisation, then DataTables wouldn't be aware of those additional rows. You can do it that way still, but you would then need to call
rows().invalidate()
for the table to be reloaded. The best way is to userows.add()
as in the examples at the end of that page.Use
draw()
to redraw the table to show the rows.Hope that all helps,
Cheers,
Colin