简体   繁体   English

如何获取第一行并将其附加到jQuery DataTables?

[英]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. 通常,除非确实必要,否则应避免直接操作该表,并使用适当的API方法。

SOLUTION

Use fnAddData (DataTables 1.9) or row.add() (DataTables 1.10) to add data to the table: 使用fnAddData (DataTables 1.9)或row.add() (DataTables 1.10)将数据添加到表中:

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

DEMO 演示

See this jsFiddle for code and demonstration. 有关代码和演示,请参见此jsFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery数据表:选择扩展:如何在init上选择第一行以及如何至少选择一行 - jquery datatables: Select Extension: How to select first row on init and how to get at least one row selected jQuery数据表首次显示行自定义属性 - jQuery Datatables get first displayed row custom attribute 如何在jQuery中将数据追加到数据表? - How to append data to datatables in jquery? 如何在jQuery DataTables分页期间滚动到第一行 - How to scroll to first row during pagination in jQuery DataTables jQuery DataTables:如何通过tr的行id获取行索引(或nNode)? - jQuery DataTables: How to get row index (or nNode) by row id of tr? jQuery Datatables-如何在单击该行中的按钮时获取该行的索引 - jQuery Datatables - How to get the index of a row when a button in that row is clicked jQuery DataTables清除表,但第一行除外 - jQuery DataTables clear table except the first row 如何在DataTables jquery中获取带有隐藏行的单列中单元格的DOM? - How to get the DOM of cells in a single column with a hidden row in DataTables jquery? jQuery - DataTables - 如何获取点击行数据 -.Net 6 MVC - jQuery - DataTables - How to get clicked row data - .Net 6 MVC jQuery Datatables查找最后一行,并从作为隐藏列的第一列获取数据 - jQuery Datatables find last row, and get data from first column which is a hidden column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM