Adminlte: Datatables not responsive when in a tab.

Created on 28 Dec 2016  路  9Comments  路  Source: ColorlibHQ/AdminLTE

Hi,

I am having a problem when it comes to getting the Datatables to be responsive when in a Tab. As soon as like i put my phone landscape and the portrait it is fine but when the page first loads it doesn't resize the datatable to the size of the screen. See images below.

screenshot at dec 28 19-24-43
screenshot at dec 28 19-25-10
screenshot at dec 28 19-25-28

Anyone have any ideas on how to fix this? have been going around in circles with it for ages.

It is fine if i place a Datatable in a normal 'div' box.

screenshot at dec 28 19-27-20

Thanks

Most helpful comment

If you are using a dataTable in a hidden tab (meaning it is not shown on page load) you'll have to take care yourself on resizing the columns on first page load.

$(document).ready(function() {
    $('a[data-toggle="tab"]').on( 'shown.bs.tab', function (e) {
        $.fn.dataTable.tables( {visible: true, api: true} ).columns.adjust();
    } );
    ...

This is also mentioned in dataTables documentation: https://datatables.net/examples/api/tabs_and_scrolling.html

All 9 comments

hey. can I see the code?

Yeah sure.

Added onto pasteBin.

https://pastebin.com/UVxXp67Z

I myself use

<div class="table-responsive">
  <table id="applicationList" class="table table-bordered table-striped">
  ...

from bootstrap

That would work on @xDowwdeen tables too, in the pastbin code you doesn't execute DataTable JS function,
if you want to use DataTables instead of Boostraps Tables use DataTable's Responsive extension for this problem.

@REJack I do use the Datatables extension and the JS functions are at the bottom of the page. The Responsive extension is working but when i load the page it doesn't but as soon as i rotate the device to landscape and then back to portrait its fine.

If you are using a dataTable in a hidden tab (meaning it is not shown on page load) you'll have to take care yourself on resizing the columns on first page load.

$(document).ready(function() {
    $('a[data-toggle="tab"]').on( 'shown.bs.tab', function (e) {
        $.fn.dataTable.tables( {visible: true, api: true} ).columns.adjust();
    } );
    ...

This is also mentioned in dataTables documentation: https://datatables.net/examples/api/tabs_and_scrolling.html

Perfect that had fixed it. Thanks all for your help :)

hi @xDowwdeen 锛學hat design software do you use?

i use coda on Mac OS

Was this page helpful?
0 / 5 - 0 ratings