After destroying and re-initializing a responsive table with type = "none", icons remain

After destroying and re-initializing a responsive table with type = "none", icons remain

flauschiflauschi Posts: 3Questions: 1Answers: 0

Regarding the responsive extension:

I have a table where some columns should be put into child rows (using class="none" in the table header).
I can create two versions of a datatable, each version works as expected:
1. With "default" responsive setting, each row has an expand/collapse icon that shows/hides the child row.
2. With responsive.details settings display: $.fn.dataTable.Responsive.display.childRowImmediate
and type: 'none', the child rows are expanded and no expand/collapse icons are shown.

However, if I first create the table in version 1, then .destroy() it and reinitialize it as version 2, then stale collapse icons are displayed:

function defaultResponsive() {
  // this works fine and gives icons
  $('#example').DataTable( {
        responsive: true
    } );
}

function displayChildResponsive(){
  // this works fine and does not give any icons
  $('#example').DataTable( {
        responsive: {
            details: {
                display: $.fn.dataTable.Responsive.display.childRowImmediate,
                type: 'none',
                target: '',
            },
        },
    } ); 
}


$(document).ready(function() {
    defaultResponsive();
    $('#example').DataTable().destroy();
    displayChildResponsive();    
} );

See online example

PS: Why do I want that?
I would like to implement an "expand all" button for columns in child rows.
I do not want to just simulate clicks on all expand icons, as I want this setting to persist upon page changes.
I cannot just change the option after initialization (according to https://datatables.net/manual/tech-notes/3).
So the proper thing to do seems to be a destroy and reinitilaize?

This question has an accepted answers - jump to answer

Answers

  • flauschiflauschi Posts: 3Questions: 1Answers: 0

    Sorry, I should have mentioned the question:

    Question: How to get rid of the stale "collapse" icons?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @flauschi ,

    It seems that destroy() is incorrectly leaving in some classes. I've raised that as a bug (DD-887 for my reference) - I'll report back here when it's progressed. In the meantime you can just remove them by hand, as in here.

    Cheers,

    Colin

  • flauschiflauschi Posts: 3Questions: 1Answers: 0

    Great, thanks a lot!

This discussion has been closed.