2017-09-25 63 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