简体   繁体   中英

How to get first row and append it to jQuery DataTables?

I'm getting my first row:

var lFirstRow = self.table.fnGetData($('#' + self.idResultGrid() + ' tbody tr:eq(0)')[0]);

And trying to append to my table:

$('#' + self.idResultGrid() + ' tbody').append(lFirstRow);

Doesn't work, any idea why?

Generally, you should avoid manipulating the table directly unless really necessary and use appropriate API methods.

SOLUTION

Use fnAddData (DataTables 1.9) or row.add() (DataTables 1.10) to add data to the table:

var lFirstRow = self.table.fnGetData($('#' + self.idResultGrid() + ' tbody tr:eq(0)'));
self.table.fnAddData(lFirstRow);

DEMO

See this jsFiddle for code and demonstration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM