jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 数据表在引导选项卡中的大小不正确大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个页面,每个选项卡中有三个引导选项卡和一个数据表.第一个选项卡中的数据表工作正常.但是,第二个选项卡中的数据表是半宽的,我不知道为什么.也没有适用于它的CSs.

这是第一个标签的截图(工作正常)

jquery – 数据表在引导选项卡中的大小不正确

第二个标签(半宽数据)

jquery – 数据表在引导选项卡中的大小不正确

我的代码

$('#companies').DataTable({ //table in tab 1 (works finE)
        responsive: true
});


$('#companies2').DataTable({ //table in tab 2
        responsive: true
});

我的HTML:

<!-- tab start -->
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h1>Tabs</h1>
            <ul class="nav nav-tabs">
                <li class="active"><a href="#tab1" data-toggle="tab">Section 1</a></li>
                <li><a href="#tab2" data-toggle="tab">Section 2</a></li>
                <li><a href="#tab3" data-toggle="tab">Section 3</a></li>
            </ul>

            <!-- tab sections -->
            <div class="tab-content">
                <div class="tab-pane active" id="tab1">
                    <table id="companies" class="table table-Striped table-bordered dt-responsive Nowrap" cellspacing="0">
                        <thead>
                            <tr>
                                <th>Company ID</th>
                                <th>Company Name</th>
                                <th>Status</th>
                                <th></th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            {{#each context}}
                            {{#if setup}}
                            <tr>
                                <td>{{Company_iD}}</td>
                                <td>{{Company_namE}}</td>
                                {{#if is_approveD}}
                                <td>Approved</td>
                                {{elsE}}
                                <td>Not Approved</td>
                                {{/if}}
                                <td><a href="/admin/viewclientorders/{{Company_iD}}">View orders</a></td>
                                <td><a href="/admin/company/{{Company_iD}}">View Details</a></td>
                            </tr>
                            {{/if}}
                            {{/each}}
                        </tbody>
                    </table> 
                </div>
                <div class="tab-pane" id="tab2">
                    <table id="companies2" class="table table-Striped table-bordered dt-responsive Nowrap" cellspacing="0">
                        <thead>
                            <tr>
                                <th>Company ID</th>
                                <th>Company Name</th>
                                <th>Create Date</th>
                                <th></th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            {{#each context}}
                            {{#unless setup}}
                            <tr>
                                <td>{{Company_iD}}</td>
                                <td>{{Company_namE}}</td>
                                <td>{{Created_at}}</td>
                                <td><button class="btn btn-priMary setup"><a href="/admin/companies/setup_company/{{Company_iD}}">Setup</a></button></td>
                                <td><button class="btn btn-danger delete">Ignore</button></td>
                            </tr>
                            {{/unless}}
                            {{/each}}
                        </tbody>
                    </table>
                </div>
                <div class="tab-pane" id="tab3">
                    3rd
                </div>

            </div>

有人可以帮忙吗?

解决方法

保留dataTable实例,即

var companies2 = $('#companies2').DataTable({
  responsive: true
})

然后使用columns.adjust()重新计算保持表格的选项卡变为可见时的宽度:

$('a[data-toggle="tab"]').on('shown.bs.tab',function(E) {
  if (e.target.hash == '#tab2') {
    companies2.columns.adjust().draw()
  }
})

完全没有经过您的特定场景测试,但这肯定是要走的路.

大佬总结

以上是大佬教程为你收集整理的jquery – 数据表在引导选项卡中的大小不正确全部内容,希望文章能够帮你解决jquery – 数据表在引导选项卡中的大小不正确所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。