首页 > 其他 > 详细

bootstraptable行合并

时间:2019-08-02 14:55:45      阅读:51      评论:0      收藏:0      [点我收藏+]
onLoadSuccess: function (data) {
            data = $(‘#categorySonTab‘).bootstrapTable(‘getData‘, true);
            //合并单元格
            mergeCells(data, "name", 1, $(‘#categorySonTab‘));
            mergeCells(data, "url", 1, $(‘#categorySonTab‘));
            mergeCells(data, "cateWord", 1, $(‘#categorySonTab‘));
            mergeCells(data, "id", 1, $(‘#categorySonTab‘));

        },

 

合并方法(直接可用)

/**
 * 合并单元格
 * @param data  原始数据(在服务端完成排序)
 * @param fieldName 合并属性名称
 * @param colspan   合并列
 * @param target    目标表格对象
 */
function mergeCells(data, fieldName, colspan, target) {
    //声明一个map计算相同属性值在data对象出现的次数和
    var sortMap = {};
    for (var i = 0; i < data.length; i++) {
        for (var prop in data[i]) {
            if (prop == fieldName) {
                var key = data[i][prop];
                if (sortMap.hasOwnProperty(key)) {
                    sortMap[key] = sortMap[key] * 1 + 1;
                } else {
                    sortMap[key] = 1;
                }
                break;
            }
        }
    }
    var index = 0;
    for (var prop in sortMap) {
        var count = sortMap[prop] * 1;
        $(target).bootstrapTable(‘mergeCells‘, {index: index, field: fieldName, colspan: colspan, rowspan: count});
        index += count;
    }
}

 

效果图:

技术分享图片

bootstraptable行合并

原文:https://www.cnblogs.com/abo666/p/11288303.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!