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>

bootstrap table 自适应高度

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

bootstrap table 自适应高度

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);
    }
}

效果:

数据少:

bootstrap table 自适应高度

数据量大:

bootstrap table 自适应高度