简体   繁体   中英

Delete column at jquery DataTable with javascript

I use the table plug-in for jquery Datatable at my rails app, and i look for a way to delete the whole column if some actions occurs eg if a button was clicked.

The table:

<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>

How can I do that?

Ok, nth-child selector works(thx @TrueBlueAussie) for my the following way:

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

It removes the 5'th column from my table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM