【发布时间】:2012-09-05 20:32:18
【问题描述】:
JS:
$(document).ready(function() {
// $( "#dashboard_container" ).tabs();
$('#listings').dataTable({
"bRetrieve": true,
"aoColumns":
[
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
{ "bVisible": false },
]
}).rowGrouping({
iGroupingColumnIndex: 1,
sGroupingColumnSortDirection: "asc",
iGroupingOrderByColumnIndex: 0,
bExpandableGrouping: true,
bExpandSingleGroup: true,
iExpandGroupOffset: -1
});
});
HTML:
<table class="datatable" id="listings">
<thead>
<tr>
<th>Group Index</th><th>Group Display Name</th>
<th>Organization</th>
<th>Volumes</th>
<th>Read (MB/s)</th>
<th>Write (MB/s)</th>
<th>Volume Size (GB)</th>
<th>My Cost (USD)</th>
<th>Comments</th>
</tr>
</thead>
<tfoot></tfoot>
<tbody>
<tr>
<td>0</td><td><a href="/dashboard/" class="orglist_group_link">Artful Scientific</a></td>
<td>Something Co.</td>
<td><a href="/details/view?volume=12345678" class="orglist_link">information</a></td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>$0</td>
<td><a class="btn small icon i_preview comment_edit_button" rel="1" title="edit or view comment">View</a></td>
</tr>
</tbody>
</table>
</div>
问题:
我能够成功地进行行分组并且工作正常,但是我需要将 2 列隐藏到某些角色。以及隐藏一个附加列,该列将是分组使用的“组织”列的等效项。但是,从上面的 JS 中,您可以看到我已经尝试隐藏所有列,只是为了看看是否有任何列会真正隐藏在我来到这里之前的最后一次努力中。无论是全部还是一个都不会隐藏。有人知道解决这个问题吗?因为我需要保留列但隐藏到实际视图中
【问题讨论】:
-
你用的是什么版本的dataTables?
-
1.9,但是我确实找到了答案,也许我应该在这里回答我自己的问题以防止混淆。基线是,我买了一个现成的模板,其中包含数据表。然而,由于我无法像以前那样使用数据表或应该能够使用数据表而遇到的问题,我开始深入研究模板文件,结果我发现一个对
$.dataTable();的单独调用在我的脚本之前调用所有表的上下文。 -
在可扩展性方面的设计非常糟糕,但是一旦我发现我将它从基础中移除,事情就从那里开始工作得非常顺利。
-
该死的,直到我完成了上面的 jsFiddle 之后才看到你的 cmets,显示它工作正常。 :/ - jsfiddle.net/trapper/fYaYW
-
是的,请回答您自己的问题并接受,谢谢。你甚至可能会得到一些支持:-)
标签: javascript jquery html css datatable