data-visible="false" hides header but not data

data-visible="false" hides header but not data

geigerzaehlergeigerzaehler Posts: 1Questions: 1Answers: 0

I’m using <th data-visible="false"> to hide a column but it only hides the header element (<th>) and not the data elements (<td>). This is on v2.0.2 and it used to work with 1.13.

Heres a link to a reproduction: https://jsfiddle.net/19g8pdzs/1/ and here is the code.

<table id="example" class="display" style="width:100%">
  <thead>
    <tr>
      <th>Name</th>
      <th>Hidden by column-defs</th>
      <th data-visible="false">Hidden by attribute</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Tiger Nixon</td>
      <td>Hidden value</td>
      <td>Hidden value data-visible</td>
    </tr>
  </tbody>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables.net/2.0.2/dataTables.min.js"></script>
<script>
  $("#example").DataTable({
    columnDefs: [{targets: [1], visible: false}]
  })
</script>

I would expect the cell “Hidden value data-visible“ not to be visible.

As a workaround I’m using the following code:

$("#example").DataTable().columns().every(function () {
  if (!this.visible()) {
    this.visible(true);
    this.visible(false);
  }
});

Answers

  • allanallan Posts: 63,441Questions: 1Answers: 10,459 Site admin

    An old thread sorry, I've only just happened across it. This was a bug in the earlier 2.0 releases. It has been resolved now.

    Allan

Sign In or Register to comment.