加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Bootstrap mergeCells合并单元格(多列)

发布时间:2020-12-17 20:50:37 所属栏目:安全 来源:网络整理
导读:/** 合并单元格 @param target 目标表格对象 @param data 原始数据(在服务端完成排序) @param fieldName 合并参照的属性名称 @param fieldList 要合并的字段集合[不含fieldName]![] @param colspan 合并开始列 */ function mergeCells(target,data,fieldNa
/**

  • 合并单元格
  • @param target 目标表格对象
  • @param data 原始数据(在服务端完成排序)
  • @param fieldName 合并参照的属性名称
  • @param fieldList 要合并的字段集合[不含fieldName]![]
  • @param colspan 合并开始列
    */
    function mergeCells(target,data,fieldName,fieldList,colspan) {
    // 声明一个map计算相同属性值在data对象出现的次数和
    var sortMap = {};
    var index = 0;
    var begini=0;
    var endi = 0;
    // 统计fieldName长度
    getCount(target,data.length,index,sortMap);
    for(var prop in sortMap){
    endi = index+sortMap[prop];
    if(sortMap[prop]>1){
    // console.log(fieldName + ":" + prop,sortMap[prop]);
    for(var i=0;i<fieldList.length;i++){
    getCount(target,begini,endi,fieldList[i],null);
    }
    }
    index = begini = endi;
    }

}

/**

  • 计算合并
    /
    function getCount(target,sortMap) {
    // console.log(‘fieldName:‘ + fieldName);
    // console.log(begini,endi);
    if(sortMap == null){
    sortMap = {};
    }
    for(var i = begini ; i < endi ; 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;
    }
    // console.log(fieldName + ":" + key,sortMap[key]);
    break;
    }
    }
    }
    for(var p in sortMap){
    var count = sortMap[p] * 1;
    // console.log(">>>>>" + ":" + p,count);
    $(target).bootstrapTable(‘mergeCells‘,{index:index,field:fieldName,colspan: 1,rowspan: count});
    index += count;
    }

}

使用:
var data1 = $(‘#table‘).bootstrapTable(‘getData‘,true);
mergeCells($(‘#table‘),data1,"proname",["promonth","pkno","zb"],1);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读