bootstraptable行合並


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;
    }
}

 

效果圖:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM