Responsive redraw on multiple tables

Responsive redraw on multiple tables

bek816bek816 Posts: 5Questions: 2Answers: 1

I'm looping through a collection of items that I'm appending to tables. When I'm done, I'm creating all of the DataTables via:
$('table.table').DataTable( { ... });

There are at least ten tables. How can I force a recalc on every one? I know on one, I can do:
DataTable.columns.adjust() .responsive.recalc();

Should I $.each of the results of the first query?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,982Questions: 87Answers: 421
    Answer ✓

    This is what I do after all tables have loaded. I had the $.each in there as well and then replaced it with $.fn.dataTable. Columns.adjust is enough if you do this initially because there will not have been a user change of the screen size by then.

    $(document).ajaxStop(function () {
        $('#content').fadeIn('fast');
        //"api: true" - means it is a data table
        $.fn.dataTable
            .tables( { visible: true, api: true } )
            .columns.adjust();
    //        $('table.table').each(function() {
    //            if ( ! $(this).hasClass("hidden") ) {
    //                $(this).DataTable().columns.adjust()
    //                                   .responsive.recalc();
    //            }
    //        })
    });   
    
  • bek816bek816 Posts: 5Questions: 2Answers: 1

    Thanks!

This discussion has been closed.