How to add a row at the end of the table?
How to add a row at the end of the table?
FRS4002
Posts: 85Questions: 11Answers: 0
I need to add a row without columns at the end of the table (after initialization), since adding only a row directly in HTML is not possible in datatables, it gives error. Here is the test case of the table: http://live.datatables.net/moxepano/1/edit
How can I achieve this, and also if there is a solution on how to freely add any custom rows and columns directly in HTML (remove datatables detection of adding only a row without column)?
Answers
The RowGroup extension is an example of rows added to the DOM to display the group information. These rows aren't apart of the Datatable row data meaning they are counted as a row in the info message nor are they used for sorting or searching. The extension refreshes the rows after each table draw.
You could do something similar. You would use standard jQuery or Javascript methods to insert the
tr
at the desired position. You will probably want to use thedraw
event to keep up with the rows you are inserting to make sure they are displayed where you want when for example, sorting changes. There is nothing built into Datatables for this and Datatables knows nothing about the rows you insert.Kevin
@kthorngren Thanks Kevin, but could you please help me apply this to my test case above? Also, You said "You would use standard jQuery or Javascript methods to insert the tr at the desired position", you mean without RowGroup extension? Or RowGroup extension is a must! If you can help me to apply the row at the end of the table without RowGroup extension would be great!
Here is one of many possible ways:
http://live.datatables.net/holejodi/1/edit
You wouldn't use rowGroup for this.
Kevin
@kthorngren Yeah, but you added colspan with tds... I don't want to add any columns in the last row... I just need to write immediately in the row... I tried deleting colspan, and it didn't work...
I just used colspan as an example. You just need to provide proper HTMl. This is all outside fo Datatables. Stack Overflow is a good resource for general jQuery, Javascript and HTML questions.
However if you want to update the test case showing what you did we'll take a look.
Kevin
@kthorngren Thanks Kevin! I fixed it by adding this:
Thanks!