关于datatables自适应以及自定义列宽度的总结

本文总结了使用Datatables时如何实现表格的自适应布局以及自定义列宽度的方法。通过设置`table-layout: fixed;`属性可以控制列宽,同时在表格头部(thead)中设置各列的宽度。在遇到tab切换导致表头宽度问题时,可以使用setTimeout函数配合hide方法解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

table-layout:fixed;可以自定义列的宽度

<div id="bizhi" style="width:100%;height: 85%;overflow-x: auto;">
                        <table id="data_table" class=""  style="width:100%;height: 100%;table-layout:fixed;font-size: 0.2rem !important;">
                                <thead>
                                    <tr>
                                        <!--<th rowspan="2" style="width: 5px !important;">序号</th>-->
                                        <!--<th rowspan="2" style="width: 120px !important;">供热站</th>
                                        <th colspan="5" style="width: 270px !important;">消耗指标</th>-->
                                        <th rowspan="2" style="width: 36% !important;">供热站</th>
                                        <th colspan="5" style="width: 64% !important;">消耗指标</th>
                                    </tr>
                                    <tr>
                                        <th>氧化钙</th>
                                        <th>NaOH溶液</th>
                                        <th>NaOH片碱</th>
                                        <th>尿素</th>
                                        <th>工业盐</th>
                                    </tr>
                                </thead>
                        </table>
                    </div>

//tab切换时会使表头元素宽度无法识别,先设置一个定时器,刚开始让所有的table的div都显示,在页面打开若干秒或者毫秒之后,让不该显示的div隐藏就好了hide(),
        setTimeout(function(){$("#changzhi").hide()},1000)

转载于:https://www.cnblogs.com/lxl0419/p/8984963.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值