1

I have a dataTable and having trash icon at the "th". I need to remove entire column when click on the trash icon(need to remove all data from all pages). I tried the following code but which is not working under pagination.Please help me...

$(document).on("click", ".a_datatbl_trash", function (e)
{
   var indexToRemove = $(this).parent().index();
   $("#datatable-buttons tbody tr").each(function() {
      $(this).find("td:eq("+indexToRemove+")").remove();
   });
   $(this).closest("th").remove();
)};

This is the html structure

<thead>
<tr role="row">
  <th class="sorting_asc" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Article title: activate to sort column descending">Article title
  <a href="" class="dragtable-drag-handle" style="background: none; width: 15px;"><i class="fa fa-fw fa-arrows"></i></a>
  <a href="" class="a_datatbl_trash" style="float: right;"><i class="fa fa-fw fa-trash datatbl_trash" style="float: right;"></i></a>
  </th>
</tr>
</thead>

1 Answer 1

7

Why don't you use the visible API? Does it not fit your need? that could be something like:

yourDatatable.column(columnIndex).visible(false);

Or you go to destroy the data first and update.

Sign up to request clarification or add additional context in comments.

1 Comment

I am glad it helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.