bootstraptable 页面多表格合计行宽度设置与隐藏

bootstraptable 页面多表格合计行宽度设置与隐藏

页面效果展示
在这里插入图片描述
HTML部分

   <table id="payment_detail_table"></table>
   <table id="payment_table2" class="payment_table2"></table>

编写js为表格添加数据并且在onLoadSuccess方法或者onLoadSuccess方法中调用合计行样式处理方法merge_footer()

//第一张表数据
 var templateTableParams = {
        classes: "table table-bordered table-hover",
        url: "后台访问URL",
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        dataType: "json",
        cache: false,     //是否使用缓存,默认为true
        striped: true,    //是否显示行间隔色
        singleSelect: true,   //单选
        clickToSelect: true,  //是否启用点击选中行
        showFooter: true,//合计
        height:120,
        queryParams: function () {
            var params = {
                maindjh: '${puFksqdMain.djh}'
            };
            return params;
        },
        columns: [
//            {
//                checkbox: true
//            },
            {
                title: '序号', halign: "center", align: 'center', width: '50px',
                formatter: function (value, row, index) {
                    return index + 1;
                },
                footerFormatter: function (value) {
                    return '合计';
                }
            },

            {
                field: 'hth', title: '合同号', halign: "center", width: '100px', formatter :'paramsMatter'
            },

            {
                field: 'xshth', title: '销售合同号', width: '100px', halign: "center", formatter :'paramsMatter'

            },
            {
                field: 'rq', title: '合同日期', width: '70px', halign: "center", formatter :'paramsMatter'
            },
            {
                field: 'htje', title: '合同金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].htje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'fkje', title: '已付款金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].fkje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'htqkje', title: '合同欠款金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].htqkje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'shzje', title: '审核中金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].shzje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'ksqje', title: '可申请金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].ksqje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'sqfkje', title: '申请付款金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].sqfkje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'fkzl', title: '付款种类', width: '70px', halign: "center", formatter :'paramsMatter'
            }
        ],
        cardView: (function () {
            return /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent);
        })(),
        trimOnSearch: true,
        onlyInfoPagination: false,//显示总记录数  必须打开pagination=true
        pagination: false,      //显示分页
        pageNumber: 1,             //初始化加载第一页,默认第一页
        pageSize: 10,               //每页记录数
        pageList: [5, 10, 20],     //可供选择的每页的行数
        idField: 'id',
        uniqueId: 'id',
        smartDisplay: false,
        onPostBody: function (data) {
            merge_footer();
        },
        onLoadSuccess: function (data) {
            if (data.length == 0) {
                layer.msg("查询结果为空");
            }
        }
    };
   //第二张表数据
   var templateTableParams2 = {
        classes: "table table-bordered table-hover ",
        url: "访问后台URL",
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        dataType: "json",
        cache: false,     //是否使用缓存,默认为true
        striped: true,    //是否显示行间隔色
        singleSelect: true,   //单选
        clickToSelect: true,  //是否启用点击选中行
        showFooter: true,//合计
        queryParams: function () {
            var params = {
                gys: $('#gys').val()
            };
            return params;
        },
        columns: [
//            {
//                checkbox: true
//            },
            {
                title: '序号', halign: "center", align: 'center', width: '50px',
                formatter: function (value, row, index) {
                    return index + 1;
                },
                footerFormatter: function (value) {
                    return '合计';
                }
            },
            {
                field: 'hth', title: '合同号', width: '80px', halign: "center", formatter :'paramsMatter'
            },

            {
                field: 'xshth', title: '销售合同号', width: '80px', halign: "center", formatter :'paramsMatter'

            },
            {
                field: 'rq', title: '合同日期', width: '70px', align: 'center', halign: "center", formatter :'paramsMatter'
            },
            {
                field: 'htje', title: '合同金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].htje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'fkje', title: '已付款金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].fkje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'htqkje', title: '合同欠款金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].htqkje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'fpje', title: '已开发票金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].fpje;
                    }
                    return count.toFixed(2);
                }
            }

        ],
        cardView: (function () {
            return /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent);
        })(),
        trimOnSearch: true,
        onlyInfoPagination: false,//显示总记录数  必须打开pagination=true
        pagination: false,      //显示分页
        pageNumber: 1,             //初始化加载第一页,默认第一页
        pageSize: 10,               //每页记录数
        pageList: [5, 10, 20],     //可供选择的每页的行数
        idField: 'id',
        uniqueId: 'id',
        smartDisplay: false,
        onLoadSuccess: function (data) {
            if (data.length == 0) {
                layer.msg("查询结果为空");
            }
        },
        formatNoMatches : function() {
            return '';
        }
    };
    var trueHeight = document.documentElement.clientHeight-5;
    var startHeight = document.body.offsetHeight;
    templateTableParams2.height = trueHeight - startHeight-130;
    $('#payment_detail_table').bootstrapTable(templateTableParams);
  var templateTableParams2 = {
        classes: "table table-bordered table-hover ",
        url: "${ctx}/payment/contractPamentCondition.z",
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        dataType: "json",
        cache: false,     //是否使用缓存,默认为true
        striped: true,    //是否显示行间隔色
        singleSelect: true,   //单选
        clickToSelect: true,  //是否启用点击选中行
        showFooter: true,//合计
        queryParams: function () {
            var params = {
                gys: $('#gys').val()
            };
            return params;
        },
        columns: [
//            {
//                checkbox: true
//            },
            {
                title: '序号', halign: "center", align: 'center', width: '50px',
                formatter: function (value, row, index) {
                    return index + 1;
                },
                footerFormatter: function (value) {
                    return '合计';
                }
            },
            {
                field: 'hth', title: '合同号', width: '80px', halign: "center", formatter :'paramsMatter'
            },

            {
                field: 'xshth', title: '销售合同号', width: '80px', halign: "center", formatter :'paramsMatter'

            },
            {
                field: 'rq', title: '合同日期', width: '70px', align: 'center', halign: "center", formatter :'paramsMatter'
            },
            {
                field: 'htje', title: '合同金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].htje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'fkje', title: '已付款金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].fkje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'htqkje', title: '合同欠款金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].htqkje;
                    }
                    return count.toFixed(2);
                }
            },
            {
                field: 'fpje', title: '已开发票金额', width: '70px', halign: "center", align: 'right',
                footerFormatter: function (value) {
                    var count = 0;
                    for (var i in value) {
                        count += value[i].fpje;
                    }
                    return count.toFixed(2);
                }
            }

        ],
        cardView: (function () {
            return /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent);
        })(),
        trimOnSearch: true,
        onlyInfoPagination: false,//显示总记录数  必须打开pagination=true
        pagination: false,      //显示分页
        pageNumber: 1,             //初始化加载第一页,默认第一页
        pageSize: 10,               //每页记录数
        pageList: [5, 10, 20],     //可供选择的每页的行数
        idField: 'id',
        uniqueId: 'id',
        smartDisplay: false,
        onLoadSuccess: function (data) {
            if (data.length == 0) {
                layer.msg("查询结果为空");
            }
        },
        formatNoMatches : function() {
            return '';
        }
    };
 $('#payment_detail_table').bootstrapTable(templateTableParams);
   $('#payment_table2').bootstrapTable(templateTableParams2);    

merge_footer方法编写

  //设置合计列宽度
    function merge_footer() {
        //获取table表中footer 并获取到这一行的所有列
        var footer_tbody = $('.fixed-table-footer table tbody');
        var footer_tr = footer_tbody.find('>tr');
        //footer_tr中包含页面所有合计行的内容
        var footer_td = footer_tr.find('>td');
        for(var i=0;i<footer_td.length-1;i++) {
                footer_td.eq(i).hide();
             //第一张表格合计行宽度设置
            if(i==0){
                footer_td.eq(i).attr('width', "70px").show();
            }
            if(i==1){
                footer_td.eq(i).attr('width', "380px").show();
            }
            if(i>3&&i<10){
                footer_td.eq(i).attr('width', "99px").show();
            }
            if(i==10){
                footer_td.eq(i).attr('width', "99px").show();
            }
            //第二张表格合计行宽度设置
            if(i==11){
                footer_td.eq(i).attr('width', "100px").show();
            }
            if(i==14){
                footer_td.eq(i).attr('width', "465px").show();
            }
            if(i>=15&&i<=18){
                footer_td.eq(i).attr('width', "140px").show();
            }
        }
    }
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 要实现表格宽度拖动,可以使用 bootstrap-table 插件中的 resizableColumns 插件。具体使用方法如下: 1. 引入插件: ```html <script src="https://cdn.bootcss.com/bootstrap-table/1.15.4/extensions/resizable/bootstrap-table-resizable.min.js"></script> ``` 2. 初始化表格并添加插件: ```javascript $('#table').bootstrapTable({ resizableColumns: true, // 开启列宽拖动功能 columns: [{ field: 'id', title: 'ID' }, { field: 'name', title: 'Name' }, { field: 'price', title: 'Price' }] }); ``` 3. 如果需要固定表头,可以在 CSS 中添加以下样式: ```css .fixed-table-header { position: fixed; top: 0; left: 0; z-index: 999; } ``` 然后在表格的父容器中添加以下属性: ```html <div class="table-responsive"> <table id="table" data-height="460" data-show-columns="true"> ... </table> </div> ``` 其中,`table-responsive` 类用于使表格可以响应式缩放,`data-height` 属性指定表格高度,`data-show-columns` 属性用于显示列选择器。 ### 回答2: Bootstrap Table表格宽度拖动,固定表头的实现方法如下: 1. 使用bootstrap-table插件的table组件来创建表格,并设置table-layout为fixed来固定列宽。 2. 在表格的CSS样式中,设置表格容器的宽度为固定值,以便固定表格宽度。 3. 使用bootstrap-table插件的column的width属性来设置每列的宽度。通过拖拽可调整列宽的方式来改变每列的宽度。 4. 为表格的头部区域创建一个额外的div容器,并设置其CSS样式为固定定位和指定高度。 5. 使用jQuery的scroll事件来监听滚动事件,在滚动时将表格头部的div容器进滚动,使其保持固定在页面上方。 6. 在colgroup标签中定义每列的固定宽度,使表格的列宽度表格头部的div容器保持一致。 综上所述,通过使用bootstrap-table插件和一些CSS样式和JavaScript代码的设置,我们可以实现Bootstrap Table表格宽度拖动和固定表头的效果。这样,无论用户拖动表格宽度还是滚动页面,表头始终会保持在页面顶部,为用户提供更好的表格浏览体验。 ### 回答3: 要实现表格宽度拖动和固定表头,可以使用 Bootstrap Table 插件结合其他一些技术来实现。 首先,引入 Bootstrap Table 插件的样式和脚本文件。在表格的容器中创建一个 `<table>` 元素,并添加相应的 `class`,如 `table table-bordered table-striped`。 接下来,使用 jQuery UI 的 resizable 方法使表格宽度可以拖动调整大小。为表格添加一个父容器,并给父容器设置合适的宽度。然后,使用 jQuery 选择器选择表格,并调用 resizable 方法,设置拖动范围和回调函数。 为了固定表头,需要创建一个静态的表格头部。复制表格头部的内容并使用 div 包裹起来,添加对应的样式。 接下来,使用 CSS 来实现表格的固定表头。设置父容器的 `position` 为 `relative`,表格头部的 `position` 为 `absolute`。通过调整父容器的 `padding-top` 来使表格正文内容向下错开,然后用 `z-index` 来设置表格头部的层级。 最后,为了使表格正文能够滚动,添加 CSS 样式设置表格的 `overflow-x` 为 `auto`。 通过上述步骤,我们就能够实现 Bootstrap Table 表格宽度的拖动和固定表头的效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

桀骜浮沉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值