溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Bootstrap mergeCells合并單元格(多列)

發(fā)布時(shí)間:2020-07-20 22:00:29 來(lái)源:網(wǎng)絡(luò) 閱讀:7329 作者:hecnet 欄目:web開(kāi)發(fā)

/**

  • 合并單元格
  • @param target 目標(biāo)表格對(duì)象
  • @param data 原始數(shù)據(jù)(在服務(wù)端完成排序)
  • @param fieldName 合并參照的屬性名稱
  • @param fieldList 要合并的字段集合[不含fieldName]![]
  • @param colspan 合并開(kāi)始列
    */
    function mergeCells(target, data, fieldName, fieldList, colspan) {
    // 聲明一個(gè)map計(jì)算相同屬性值在data對(duì)象出現(xiàn)的次數(shù)和
    var sortMap = {};
    var index = 0;
    var begini=0;
    var endi = 0;
    // 統(tǒng)計(jì)fieldName長(zhǎng)度
    getCount(target, data, 0, data.length, fieldName, 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, data, begini, endi, fieldList[i], index, null);
    }
    }
    index = begini = endi;
    }

}

/**

  • 計(jì)算合并
    /
    function getCount(target, data, begini, endi, fieldName, index, 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);

Bootstrap mergeCells合并單元格(多列)

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI