BarryWearBurberry 2022-03-23 14:49 采纳率: 81.8%
浏览 246
已结题

footerformatter和表格内容对不齐问题

问题遇到的现象和发生背景

bootstrap table底部使用footerFormatter来显示每一列的统计信息,为了让中间表格内容滑动的时候能够知道所属列以及所属列的信息,给表格属性设置了height,从而使表头和表尾做了固定,但是现在页脚和表格内容对不齐

<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link href="/css/bootstrap.min.css"/>
<link href="/css/bootstrap-editable.css" rel="stylesheet"/>
<link href="/css/plugins/bootstrap-table/bootstrap-table.min.css"/>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-body">
                    <div class="fixed-table-toolbar">
                        <div class="columns pull-left">
                            <input id="maintableId" name="maintableId" th:value="${maintableId}"  type="hidden">
                            <input id="product" name="product" th:value="${product}"  type="hidden">
                            <input id="process" name="process" th:value="${process}"  type="hidden">                                                                            
                            <button  shiro:hasPermission="oar:powertable:add" type="button" class="btn  btn-primary" onclick="add(1)">
                                <i class="fa fa-plus" aria-hidden="true"></i>以常规格式上传
                            </button>
                            <button  shiro:hasPermission="oar:powertable:add" type="button" class="btn  btn-primary" onclick="add(2)">
                                <i class="fa fa-plus" aria-hidden="true"></i>以MicroVU格式上传
                            </button>
                            <button shiro:hasPermission="oar:powertable:batchRemove" type="button" class="btn  btn-danger"
                                onclick="batchRemove()">
                                <i class="fa fa-trash" aria-hidden="true"></i>删除
                            </button>
                        </div>
                        <div class="columns pull-right">
                            <button class="btn btn-success" onclick="reLoad()">刷新</button>
                        </div>
                        <div class="columns pull-right col-md-2 nopadding">
                             <input id="tableName" name="tableName" th:value="${tableName}" class="form-control" type="text" readonly>    
                        </div>
                    </div>    
                    
                    <table id="exampleTable" data-mobile-responsive="true" >
                    </table>    
                             
                  </div>
            </div>
        </div>
    </div>
    <!--shiro控制bootstraptable行内按钮看见性 来自bootdo的创新方案 -->
    
     <style>
     .fixed-table-container thead th .sortable {
          background-image: url('/css/plugins/images/sort_asc.png');
      }
  
     .fixed-table-container thead th .asc {
         background-image: url('/css/plugins/images/sort_asc.png');
     }

     .fixed-table-container thead th .desc {
         background-image: url('/css/plugins/images/sort_desc.png');
     }
     </style>
    
    <style type="text/css">
         .table.table>tbody>tr>td {
                padding: 2px!important;
            }
    </style>
    
        <div>
            <script type="text/javascript">
                var s_edit_h = 'hidden';
                var s_remove_h = 'hidden';
                var s_resetPwd_h = 'hidden';
            </script>
        </div>
        <div shiro:hasPermission="oar:powertable:edit">
            <script type="text/javascript">
                s_edit_h = '';
            </script>
        </div>
        <div shiro:hasPermission="oar:powertable:remove">
            <script type="text/javascript">
                var s_remove_h = '';
            </script>
        </div>
        <div shiro:hasPermission="oar:powertable:resetPwd">
            <script type="text/javascript">
                var s_resetPwd_h = '';
            </script>
        </div>
    </div>
    <div th:include="include :: footer"></div>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap-editable.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap-table-editable.js"></script>
    <script type="text/javascript" src="/js/appjs/oar/powertable/powertableForMixNew.js"></script>
</body>
</html>
$('#exampleTable')
            .bootstrapTable(
                    {
                        method : 'get', // 服务器数据的请求方式 get or post    
                        url : prefix + "/listForMix"+ "?maintableId=" + maintableId+"&tableName="+tableName,
                         // 服务器数据的加载地址
                        //showRefresh : true,
                        //showToggle : true,
                        //showColumns : true,
                        // rowStyle: rowStyle,
                        iconSize : 'outline',
                        height:600,
                        toolbar : '#exampleToolbar',
                        striped : true, // 设置为true会有隔行变色效果
                        dataType : "json", // 服务器返回的数据类型
                        pagination : false, // 设置为true会在底部显示分页条
                        // queryParamsType : "limit",
                        // //设置为limit则会发送符合RESTFull格式的参数
                        singleSelect : false, // 设置为true将禁止多选
                        // contentType : "application/x-www-form-urlencoded",
                        // //发送到服务器的数据编码类型
                        pageSize : 10, // 如果设置了分页,每页数据条数
                        pageNumber : 1, // 如果设置了分布,首页页码
                        //search : true, // 是否显示搜索框
                        sortable: true,                     //是否启用排序
                        sortOrder: "asc",
                        showFooter: true,
                        showColumns : true, // 是否显示内容下拉框(选择显示的列)
                        sidePagination : "server", // 设置在哪里进行分页,可选值为"client" 或者 "server"
                        onEditableSave: function (field, row, oldValue, $el) {
                                $.ajax({
                                     type:  'post',
                                        url: prefix + "/updateInlineAddTableName",                                       
                                     data: row,
                                     dataType: 'JSON',
                                        success: function (data, status) {
                                                    if (status == "success") {                                                            
                                                            //alert("编辑成功");
                                                            reLoad();                                                            
                                                        }
                                        },
                                        error: function () {
                                                alert("Error");
                                    },
                                    complete: function () {
                                    }
                                });
                            },
                            queryParams : function(params) {
                            return {
                                //说明:传入后台的参数包括offset开始索引,limit步长,sort排序列,order:desc或者,以及所有列的键值对
                                limit: params.limit,
                                offset:params.offset,
                                sort:params.sort,
                                order:params.order,    
                                  //page : (params.offset / params.limit) + 1, //当前页码
                                   // name:$('#searchName').val(),
                                    // username:$('#searchName').val()
                            };
                        },
                        // //请求服务器数据时,你可以通过重写参数的方式添加一些额外的参数,例如 toolbar 中的参数 如果
                        // queryParamsType = 'limit' ,返回参数必须包含
                        // limit, offset, search, sort, order 否则, 需要包含:
                        // pageSize, pageNumber, searchText, sortName,
                        // sortOrder.
                        // 返回false将会终止请求
                        columns : myColumns
                    });

img

我的解答思路和尝试过的方法

参考了这篇博客
https://www.itxst.com/detail/yaqzzfqy.html
但是没有起效果
也使用了

$(document).ready(function(){
            $('.fixed-table-body').scroll(function(){
            $('.fixed-table-footer').scrollLeft($(this).scrollLeft());
            });
    });

也没起到效果

还有有时候页面正常显示,但浏览器按F12会有这些小错误是怎么一回事,虽然不影响显示

img

我想要达到的结果

想让表格内容与页脚对齐

  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2022-03-23 15:26
    关注

    文章里面的代码有问题,样式是错的
    可以试试在onPostBody中触发下window resize事件让bootstrap重新设置表格单元格宽度,经测试bootstrap-table@1.19.1有效

    img

           $('#table').bootstrapTable(
                {
                    height: 400,
                    onPostBody: function () {
                        setTimeout(() => { //为了演示页脚不对齐,特意延时2s后触发resize事件,实际使用时不需要延时,或者将2000(2s)改为100(100ms)
                            $(window).trigger('resize')
                        }, 2000)
                    },
    //....其他配置
    });
    
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月31日
  • 已采纳回答 3月23日
  • 创建了问题 3月23日

悬赏问题

  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果