[英]Issue with Responsive DataTables And Bootstrap Tabs
I want to use Datatables and Responsive extension inside Bootstrap Tabs. 我想在Bootstrap选项卡中使用Datatables和Responsive扩展。 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();
});
There are multiple issues with your code: 您的代码存在多个问题:
responsive.recalc()
is available in dataTables.responsive.js
since 1.0.1
, you're including version 1.0.0
. responsive.recalc()
是可用的dataTables.responsive.js
自从1.0.1
,你包括版本1.0.0
。 Include Bootstrap library after jQuery library 在jQuery库之后包含Bootstrap库
Include Responsive extension version 1.0.1 or later 包括响应式扩展程序版本1.0.1或更高版本
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(); }); });
See updated jsFiddle for code and demonstration. 有关代码和演示,请参阅更新的jsFiddle 。
See jQuery DataTables – Column width issues with Bootstrap tabs for solution to the most common problems with jQuery DataTables and Bootstrap Tabs. 请参阅jQuery DataTables - Bootstrap选项卡的列宽问题,以解决jQuery DataTables和Bootstrap选项卡最常见的问题。
I tried the answers above but none worked. 我尝试了上面的答案但没有奏效。 I was using JQuery Steps Wizard as tabs.
我使用JQuery Steps Wizard作为选项卡。 I had to use
$('#datatable').css("width", '100%')
as well for it to work. 我不得不使用
$('#datatable').css("width", '100%')
以及它的工作原理。
wizard.steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
enableFinishButton: false,
enablePagination: false,
enableAllSteps: true,
titleTemplate: "#title#",
cssClass: "tabcontrol",
onStepChanged: function (event, currentIndex, priorIndex) {
if (currentIndex == 2) {
$('#datatable').css("width", '100%')
$($.fn.dataTable.tables(true)).DataTable().columns.adjust().responsive.recalc();
}
}
})
My Datatable is on the 3rd tab hence the check on the currentIndex
. 我的数据表位于第3个选项卡上,因此检查
currentIndex
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.