/**
站在用户的角度思考问题,与客户深入沟通,找到宁晋网站设计与宁晋网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站建设、网站制作、企业官网、英文网站、手机端网站、网站推广、域名与空间、网站空间、企业邮箱。业务覆盖宁晋地区。
- 合并单元格
- @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, 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;
}
}
/**
- 计算合并
/
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);
当前名称:BootstrapmergeCells合并单元格(多列)
文章链接:https://www.cdcxhl.com/article24/pisoce.html
成都网站建设公司_创新互联,为您提供云服务器、营销型网站建设、微信公众号、网站设计公司、电子商务、品牌网站建设
广告
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源:
创新互联