2012-05-24 38 views
0

可能重复:
using jquery datatable plugin, does fnAddAdd() add rows to the top or bottom of a html tabld为什么datatable将行添加到我的表的顶部?

我试图使用数据表与我的应用程序,看到的动态添加行的例子。它的工作原理很奇怪。它在我现有的行上添加行。我怎样才能解决这个问题?

逸岸请看看这个演示页:

http://datatables.net/examples/api/add_row.html

,然后点击“点击添加新行”。你会看到在行allan,allan,allan,allan之上添加了1.1,1.2,1.3,1.4。

如何告诉datatables在allan下方添加该行,而不是在上面。

+0

@Alexis:它不重复。该解决方案并不适合我,所以我再次发布。如果我将false作为第二个参数传递,则不会添加行本身。 –

回答

1

添加新行函数有一个可选的布尔值,表示是否重绘表。因此,您在演示中看到的内容按第1列进行排序,并且在添加新项目时,结果会被采用。如果您传递错误,重绘将不会发生,并按您的预期行事,但不会被排序。您可以通过降序排列第1列,然后添加行来看到发生了什么。

$(this).fnAddData(data, false); 

API

Input parameters: 
{array|object}: The data to be added to the table. This can be: 
       1D array of data - add a single row with the data provided 
       2D array of arrays - add multiple rows in a single call 
       object - data object when using mDataProp 
       array of objects - multiple data objects when using mDataProp 
{bool} [default=true]: redraw the table or not 
+0

如果我传递false,则不会添加行本身。这是我做的:$('#purForm')。dataTable()。fnAddData(['','','','','',''],false); –

+0

我错过了什么吗? –

相关问题