"cannot reinitialise" when hiding columns

"cannot reinitialise" when hiding columns

lcdserviceslcdservices Posts: 2Questions: 2Answers: 0

I have a dataTable that is drawn, after which I am dynamically hiding a column. if the table is redrawn from another action, I get a "cannot reinitialise" error when my column-hiding code is hit.

I've tried conditioning on isDataTable() and then using retrieve to get the existing object, but it still errors. how can I restructure this so that I don't hit that error

$(document).ready(function(){
  if ($.fn.dataTable.isDataTable('.group-selector')) {
    //this works on initial page load
    var tblGroups = $('.group-selector').dataTable();
    tblGroups.fnSetColumnVis(5, false);
  }
  else {
    //oddly, this errors when table is redrawn
    var tblGroups = $('.group-selector').dataTable({
      "retrieve": true
    });
    tblGroups.fnSetColumnVis(5, false);
  }
});

Answers

  • allanallan Posts: 64,303Questions: 1Answers: 10,620 Site admin

    Its difficult to say without being able to see the page (per the forum rules ;-) ), but my guess is that the selector is picking up a second table.

    Perhaps try:

    $.fn.dataTable.tables({api:true}).column(5).visible(false);
    

    Do you have any other tables? Or does it use scrolling?

    Allan

This discussion has been closed.