bootstrapTable之表格合并
作者:互联网
1.思路
1>数据序列化。整理出同字段值并列行的数据格式。如:
[{name: wang}, {name: wang}, {name:fu}, {name: fu}]
2>计算同字段值并列行的个数数组。如:
[2, 2]
3>利用bootstrapTable自带的mergeCells方法进行合并。如
$(target).bootstrapTable('mergeCells',{index:index, field:fieldName, colspan: colspan, rowspan: count});
2.代码
mergeCells(TBArr,"name", "name", 1, $('#dt-table'))
function mergeCells(data,name,fieldName,colspan,target){
//声明一个map计算相同属性值在data对象出现的次数和
var sortMap = {};
for(var i = 0 ; i < data.length ; i++){
for(var prop in data[i]){
if(prop == name){
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,index,name,表格,colspan,合并,prop,sortMap,var 来源: https://blog.csdn.net/qq_44308920/article/details/121095959