简体   繁体   English

将datatable行添加到表的顶部或底部?

[英]add datatable row to top or bottom of the table?

My datatable by default sorting for 1 column. 我的数据表默认为1列排序。 Dynamically I am adding row to the table, row is adding sometimes in middle of table, sometime add to 2 page .. etc because first column is name. 动态地我在表中添加行,有时在表的中间添加行,有时添加到2页..等等,因为第一列是名称。

But I want add top of the table or last of the table. 但我想添加表格的顶部或表格的最后。 Can we do that? 我们可以做到吗? How? 怎么样?

var t = $('#tblRoster').DataTable();
t.row.add( [memberCustomerName, memberPosition,memberMasterCustomer,
    memberCustomerEmail, endDate,'<a href="#" class="linkbutton 
    padding-left-20" id="addCancelButton">Remove</a>']).draw( false );

Position of newly added data in entirely based on the ordering condition applied to the DataTable. 新添加数据的位置完全基于应用于DataTable的排序条件。

Suppose you want to add Row at last of the DataTable. 假设您要在DataTable的最后添加Row。 So you need to take following steps: 因此,您需要采取以下步骤:

  1. Add New Row in DataTable. 在数据表中添加新行。

  2. Draw DataTable with specified order. 以指定顺序绘制DataTable。

  3. Move the page focus to last page of the DataTable (optional). 将页面焦点移到DataTable的最后一页(可选)。

So you can achieve it this way. 因此,您可以通过这种方式实现它。

$('#AddRow').on('click', function() {
     var row = ['testing', 'testing', 'testing', 'testing', 'testing', 'testing'];
     table.row.add(row).draw(false);
     table.order([1, 'asc']).draw();
     table.page('last').draw(false);
});

Here is its Demo 这是它的演示

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

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