javascript - Issue with Responsive DataTables And Bootstrap Tabs -
i want use datatables , responsive extension inside bootstrap tabs. have working separately.
$(document).ready(function() { $('#example').datatable( { responsive: true } ); $('#exampleintab').datatable( { responsive: true } ); } ); $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { $($.fn.datatable.tables(true)).datatable() .columns.adjust() .responsive.recalc(); });
you can see issue here
cause
there multiple issues code:
- bootstrap library included before jquery library
- api method
responsive.recalc()
available indatatables.responsive.js
since1.0.1
, you're including version1.0.0
. - event handler should attached once dom available.
solution
include bootstrap library after jquery library
include responsive extension version 1.0.1 or later
use code below:
$(document).ready(function () { $('#example').datatable({ responsive: true }); $('#exampleintab').datatable({ responsive: true }); $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { $($.fn.datatable.tables(true)).datatable() .columns.adjust() .responsive.recalc(); }); });
demo
see updated jsfiddle code , demonstration.
links
see jquery datatables – column width issues bootstrap tabs solution common problems jquery datatables , bootstrap tabs.
Comments
Post a Comment