bootstrap table 自适应高度+列错位

这里主要解决bootstrap table 数据过多时固定高度,数据少时以数据量决定高度。

这里是带底部的表格,其他情况可能稍有出入:

直接上代码:

1、表格div

<div class="box-body" style="overflow: auto;" id="out_table_gzlmx_ks">
    <table class="table-container" id="table_gzlmx_ks">
    </table>
</div>

2、初始化表格,加载数据,注意核心标记

3、自适应方法

function getTableHeight() {
    return  $(window).height()-450;
}
function resizeTableHeightKs(dataLen) {
    debugger;
    if(dataLen==0){
        dataLen=1;
    }
    var a = $("#table_gzlmx_ks").first().find('tr').last().height() * (dataLen);
    if (a > getTableHeight()) {
        $('div#out_table_gzlmx_ks .fixed-table-container').height(getTableHeight());
    } else {
        $('div#out_table_gzlmx_ks .fixed-table-container').height(a);
    }
}

效果:

数据少:

数据量大:

4、这时列会错位,主要是指定height导致

4.1 后遗症:因为是全局,影响了时间控件fa fa-calendar

<style>
   table {
            table-layout: fixed;
        }
</style>

4.2解决4.1后遗症:让table-layout: fixed在具体的table范围生效

<style>
    td{
        white-space:nowrap;
        overflow:hidden;
        word-break:keep-all;
    }
    /**
    直接 table  影响时间控件
     **/
    @-moz-document url-prefix(){    /*Firefox*/
        .jxtj table {
            table-layout: fixed;
        }
    }
    @media screen and (-webkit-min-device-pixel-ratio:0){ /*写在选择器外层时(只可写在此处):Chrome only*/
        .jxtj table {
            table-layout: fixed;
        }
    }
</style>
<div class="row jxtj jxtjYj">
    <div class="col-md-12 both-pd7">
        <div class="tab-pane fade in active">
            <div class="box win-box">
                <div class="box-header">
                    <i class="fa box-search"></i>
                    <div class="box-title">(一级表)科室总绩效统计</div>
                </div>
                <div class="box-body" style="overflow: auto;" id="out_table_jxtjYj">
                    <table class="table-container" id="table_jxtjYj">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值