简体   繁体   English

jQuery DataTables清除表,但第一行除外

[英]jQuery DataTables clear table except the first row

I am using jquery datatables. 我正在使用jquery数据表。 I want to clear table except the first row. 我想清除第一行以外的表格。

 var table = $('tableId').DataTable({});

Sample: 样品:
tr1 TR1
tr2 TR2
tr3 TR3

table.clear().draw(); //This clear all rows, How do I exclude first row

clear table: 清除表格:
tr1 TR1

How about this - I've used .rows().remove() instead of .clear() , so I could select which rows should be removed. 怎么样-我使用.rows().remove()而不是.clear() ,所以我可以选择应删除的行。

$('#deleteAll').click(function(){
    //get first element
    var firstElement = $('tbody > tr').first();

    /*remove all <tr> which are coming after the first element and
    redraw the table */
    table.rows(firstElement.nextAll('tr')).remove().draw();
});

Fiddle 小提琴

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

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