gpt4 book ai didi

javascript - 数据表标题在页面加载时不是全宽

转载 作者:数据小太阳 更新时间:2023-10-29 06:10:02 26 4
gpt4 key购买 nike

当使用数据表加载我的 Web 应用程序页面时,数据表已加载但 <thead>行不是表格的全宽。

编辑数据或在数据表搜索中搜索后,标题跳到全 Angular 。看图片。

对此有任何解决方案或解决方法吗?

数据表截图:

Screenshot of datatable

我的普通数据表很好,但这个是在模态中加载的。代码模式:

<!-- Get selected shops modal -->
<div id="SelectedShopsModal" class="infomodal">
<div class="shops-content">
<h2><span class="closeModalSelectedShops">&times;</span> <?php echo lang('Shops'); ?></h2>
<div class="detailblock">
<table id="DataListTableSelectedShops" class="display" cellspacing="0" width="100%">
<thead>
<th class="OE"><?php echo lang('Shop_No'); ?></th>
<th class="OE"><?php echo lang('Shop_Name'); ?></th>
<th class="OE"><?php echo lang('Shop_District'); ?></th>
</thead>
<tbody>
<?php foreach($selected_shops as $shop){
echo "<tr><td>" . $shop['Shop'] . "</td><td>" . $shop['Name'] . "</td><td>" . $shop['District'] . "</td></tr>";
} ?>
</tbody>
</table>
<br /><button class="closeBtnSelectedShops btn red"><?php echo lang('Close'); ?></button>
<button class="btn red" onclick="delete_oneshots();"><i class="fa fa-trash" aria-hidden="true"></i> <?php echo lang('Delete_shops'); ?></button>
</div>
</div>
</div>

我在页面页脚中使用的 javascript:

//datatable to display all selected shops on detail page
selectedshoptable = $('#DataListTableSelectedShops').DataTable( {
"dom": "Bfrtip",
"scrollY": "300px",
"scrollCollapse": true,
"bPaginate": false,
"bInfo" : false,
"fields": [ {
label: "Shopnr",
name: "Shop"
}, {
label: "Shopname:",
name: "Name"
}, {
label: "District",
name: "District"
}],
"buttons":[{
extend: 'selectAll',
text: '<?php echo lang('Select_all'); ?>',
className: 'btn red'
}, {
text: '<?php echo lang('Select_none'); ?>',
className: 'btn red',
action: function () {
selectedshoptable.rows().deselect();
}
}],
"language": {
"zeroRecords": "<?php echo lang('Nothing_found'); ?>",
"infoEmpty": "<?php echo lang('No_records_available'); ?>",
"search":"<?php echo lang('Search'); ?>",
"buttons": {"selectNone": "Select none"}
}
});

最佳答案

原因

您的表格最初是隐藏的,这会阻止 jQuery DataTables 调整列宽。

解决方案

  • 如果表格位于可折叠元素中,您需要在可折叠元素可见时调整标题。

    例如,对于 Bootstrap Collapse 插件:

    $('#myCollapsible').on('shown.bs.collapse', function () {
    $($.fn.dataTable.tables(true)).DataTable()
    .columns.adjust();
    });
  • 如果表格在选项卡中,您需要在选项卡可见时调整标题。

    例如,对于 Bootstrap Tab 插件:

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

上面的代码调整页面上所有表格的列宽。参见 columns().adjust() API 方法以获取更多信息。

响应式、滚动式或固定列扩展

如果您使用的是 Responsive、Scroller 或 FixedColumns 扩展程序,则需要使用其他 API 方法来解决此问题。

链接

参见 jQuery DataTables – Column width issues with Bootstrap tabs用于解决最初隐藏表时 jQuery DataTables 中列的最常见问题。

关于javascript - 数据表标题在页面加载时不是全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42115118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com