使用 javascript 删除 jquery DataTable 上的列

Delete column at jquery DataTable with javascript

本文关键字:DataTable jquery javascript 删除 使用      更新时间:2023-09-26

我在我的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>

我该怎么做?

好的,第 n 个孩子选择器通过以下方式为我工作(谢谢@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 列。