Columns adjust issue when using Datatable inside an accordion

Columns adjust issue when using Datatable inside an accordion

omar_datatableomar_datatable Posts: 1Questions: 1Answers: 0

Hello,

Here is the test case: https://codepen.io/em-Omr/pen/OJbeBBe

The issue I'm having is that the adjustment of the column is visible to the user.
I would like the tables to appear with the adjusted column width

Answers

  • allanallan Posts: 63,226Questions: 1Answers: 10,416 Site admin

    If you use the shown.bs.collapse event, as the Bootstrap documentation says, it will trigger once the animation for the accordion is complete. So yes, you'd get that flicker. You need to use the show.bs.collapse event, but also with a little delay since it is triggered before the table is visible in the DOM:

    $('#accordionExample').on('show.bs.collapse', function(e){
       setTimeout(function () {
          $($.fn.dataTable.tables(true)).DataTable().columns.adjust();
       }, 10);
    });
    

    Allan

This discussion has been closed.