2014-06-23 86 views
4

我已使用此table。我需要我的第一個tbody(它顯示平均列數)不應該排序,我的意思是這個行應該總是在(below thead)這樣的: 。我怎樣才能做到這一點?我在谷歌搜索解決方案,主要是我發現把那一行放在thead或類似的東西。但是,如果我試圖把那一行放在那個地方,對我來說似乎很複雜。那麼,有什麼方法可以在行上放置一個類,並禁用排序在該分類行上?像:<tr class="average no-sort"></tr>如何禁用從DataTable中的某些特定行中排序

Fiddle

回答

0

我在表中創建第二tbody和正義之舉,我需要在堅持另一個tbody像這樣的所有行:

initComplete: function() { 
    var self = this; 

    var api = this.api(); 
    api.rows().eq(0).each(function(index) { 
     var row = api.row(index); 
     if (row.data()...) { // condition here 
      var $row_to_persist = $(row.node()); 
      var $clone = $row_to_persist.clone(); 

      $(self).find('tbody:last').append($clone); 

      $total_row.remove(); 
      row.remove(); 
      api.draw(); 
     } 
    }); 
} 
0

也在尋找一個解決方案。在表啓動後修改dom很容易,但是會打破所有響應功能。

需要一種方法在排序和過濾完成之後將行保留在表格頂部。

1

我有同樣的問題,在我的情況我解決這樣說:

var $tr = $('#yourTable tr.no-sort'); //get the reference of row with the class no-sort 
var mySpecialRow = $tr.prop('outerHTML'); //get html code of tr 
$tr.remove(); //remove row of table 

$('#yourTable').dataTable({ 
    "fnDrawCallback": function(){ 
     //add the row with 'prepend' method: in the first children of TBODY 
     $('#yourTable tbody').prepend(mySpecialRow); 

    }     
}); 
相關問題