2017-09-25 65 views
0

添加列進行排序的功能,我有一個的TreeGrid是建立這樣的:上的TreeGrid HTML

<table> 
    <thead> 
     <tr> 
      <th>Name</th> 
      <th>Type</th> 
      <th>Number</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr class="treegrid-0"> 
      <th>name2</th> 
      <th>type2</th> 
      <th>Number2</th> 
     </tr> 
     <tr class="treegrid-1"> 
      <th>name1</th> 
      <th>type1</th> 
      <th>Number1</th> 
     </tr> 
     <tr class="treegrid-2 treegrid-parent-1" style="display:none;"> 
      <th>name1-A</th> 
      <th>type1-A</th> 
      <th>Number1-A</th> 
     </tr> 
     <tr class="treegrid-3 treegrid-parent-1" style="display:none;"> 
      <th>name1-B</th> 
      <th>type1-B</th> 
      <th>Number1-B</th> 
     </tr> 
     <tr class="treegrid-4"> 
      <th>name0</th> 
      <th>type0</th> 
      <th>Number0</th> 
     </tr> 
    </tbody> 
</table> 

我想補充的排序選項時,我在一列點擊。 排序選項只能在頂級父級上完成。 這是一個treegrid,所以預期的行爲是如果父節點必須移動,那麼子節點也必須與父節點一起移動。

我該如何做到這一點與JS?

回答

0

而不是做所有的辛勤工作你自己,你可以使用真棒JS/jQuery庫:數據表:https://datatables.net/

只需定義你的表後,給它一個ID

<table id = "myTable">..</table> 

,然後添加下面的代碼片段將把你的桌子變成一個真棒桌子。

$(document).ready(function(){ 
    $('#myTable').DataTable(); 
}); 

乾杯!

+0

感謝您的建議,我已經知道Datatable,但對於我的項目,必須使用可以通過分層視圖顯示數據的可檢索視圖。 – wawanopoulos