Alex McManns
Alex McManns

Reputation: 267

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?

Upvotes: 0

Views: 715

Answers (1)

Gyrocode.com
Gyrocode.com

Reputation: 58870

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.

Upvotes: 1

Related Questions