响应数据表和引导选项卡的问题 [英] Issue with Responsive DataTables And Bootstrap Tabs
本文介绍了响应数据表和引导选项卡的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$(document).ready(function(){
$('#example ').DataTable({
respond:true
});
$('#exampleInTab')。DataTable({
respond:true
});
});
$('a [data-toggle =tab]')on('shown.bs.tab',function(e){
$($。fn.dataTable .tables(true))。DataTable()
.columns.adjust()
.responsive.recalc();
});
您可以看到问题这里
解决方案
原因
您的代码的问题:
- 引导库包含在jQuery库之前
- API方法
respond.recalc()
在dataTables.responsive.js
中可用,因为1.0.1
,你包括版本1.0.0
。 - 一旦DOM可用,就应该附加事件处理程序。 >
解决方案
-
包含Bootstrap库jQuery库
-
包含响应扩展版本1.0.1或更高版本
-
使用以下代码:
$(document).ready(function(){
$('#example')。DataTable({
respond:true
});
$('#exampleInTab')。DataTable({
respond:true
});
$('a [data-toggle =tab]')on('shown.bs.tab',function(e){
$($。fn.dataTable .tables(true))。DataTable()
.columns.adjust()
.responsive.recalc();
});
});
演示
有关代码和演示,请参阅更新的jsFiddle 。
LINKS
请参阅 jQuery DataTables - 使用引导选项卡的列宽度问题解决了jQuery DataTables和Bootstrap选项卡中最常见的问题。
I want to use Datatables and Responsive extension inside Bootstrap Tabs. I have this 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 the issue here
解决方案
CAUSE
There are multiple issues with your code:
- Bootstrap library is included before jQuery library
- API method
responsive.recalc()
is available indataTables.responsive.js
since1.0.1
, you're including version1.0.0
. - Event handler should be attached once DOM is available.
SOLUTION
Include Bootstrap library after jQuery library
Include Responsive extension version 1.0.1 or later
Use the 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 for code and demonstration.
LINKS
See jQuery DataTables – Column width issues with Bootstrap tabs for solution to the most common problems with jQuery DataTables and Bootstrap Tabs.
这篇关于响应数据表和引导选项卡的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文