bootstrap表格行合并问题

bootstrap表格行合并问题
js相关代码:

function mergeCells(data, fieldName, colspan, target) {
        if (!data) {
            return;
        }
        var numArr = [];
        var value = data[0][fieldName];
        var num = 0;
        for (var i = 0; i < data.length; i++) {
            if (value != data[i][fieldName]) {
                numArr.push(num);
                value = data[i][fieldName];
                num = 1;
                continue;
            }
            num++;
        }
        if (typeof (value) != "undefined" && value != "") {
            numArr.push(num);
        }
        var merIndex = 0;
        for (var i = 0; i < numArr.length; i++) {
            $(target).bootstrapTable('mergeCells', {
                index: merIndex,
                field: fieldName,
                colspan: colspan,
                rowspan: numArr[i]
            });
            merIndex += numArr[i];
        }
    }

 Faxingfenlei.initTable=function () {
        $('#id').bootstrapTable({
            classes:"table table-hover " + "test",
            dataType:"json",
            url:url,
            pagination:true,
            pageList: [50, 100, 200],
            striped: true,
            queryParams:function () {
                var param = {
                    riqiStart: $("#riqiStart").val(),
                    riqiEnd:$("#riqiEnd").val(),
                    pageNumber: Faxingfenlei.pageNumber,
                    pageSize: Faxingfenlei.pageSize
                };
                return param;
            },
            queryParamsType:'',
            resizable:true,//列表可拖拽
            columns: defaultColunms,
            height:$("body").height() - $(".layui-form").outerHeight(true) - 26,
            sidePagination:"server",
            onPageChange:function(number, size){
                Faxingfenlei.pageNumber = number ;
                Faxingfenlei.pageSize = size
            },
            onLoadSuccess: function (data) {  //加载成功时执行
                if (data.total != 0) {
                    mergeCells(data.rows, "xiangmu1", 1, $('#id'));//行合并
                    mergeCells(data.rows, "xiangmu2", 1, $('#id'));//行合并
                }
            }
        });
    };

表格:

Faxingfenlei.initColumn = function () {
    return [
        [
        {title : '项目',colspan: 3,align:'center'},
        {title: '今年同期', field: 'jinniantongqi', align: 'center', halign: 'center',
            formatter: function (value) {return toDecimal2(value)}}
        ], [
            {title: '', field: 'xiangmu1', align: 'center', halign: 'center',
                formatter:function (value, row, index) {return getFormatter(value, row, index)}},
            {title: '', field: 'xiangmu2', align: 'center', halign: 'center',
                formatter:function (value, row, index) {return getFormatter(value, row, index)}},
            {title: '', field: 'xiangmu3', align: 'center', halign: 'center',
                formatter:function (value, row, index) {return getFormatter(value, row, index)}},
        ]];
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值