【问题标题】:Delete column at jquery DataTable with javascript使用javascript删除jquery DataTable中的列
【发布时间】:2014-11-28 11:44:24
【问题描述】:

我在我的 rails 应用程序中使用 jquery Datatable 的表格插件,如果发生某些操作,我会寻找一种方法来删除整个列,例如如果单击了按钮。

桌子:

<table id="words" class="display" data-source="<%= url_for controller:"words", action: "index", :format=>:json %>" >
<thead>
    <tr>
      <th><%= l(:name) %></th>
       .
       .
       .
    </tr>
</thead>
<tbody>    
</tbody>
</table>

我该怎么做?

【问题讨论】:

标签: javascript jquery ruby-on-rails html-table jquery-datatables


【解决方案1】:

好的,nth-child selector 适用于我的以下方式(thx @TrueBlueAussie):

$('#words thead').find("tr th:nth-child(5)").each(function(){$(this).remove()});
$('#words tbody').find("tr td:nth-child(5)").each(function(){$(this).remove()});

它从我的表格中删除了第 5 列。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 2021-01-10
    • 2012-05-23
    • 1970-01-01
    相关资源
    最近更新 更多