码迷,mamicode.com
首页 > 其他好文 > 详细

bootstrap table合并单元格(该版本是简单的应用)

时间:2019-07-13 10:52:48      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:出现   ESS   table   child   data   get   数据   business   tar   

 

//获取列表数据
function loadTableData(tableId, request, data) {
    $.ajax({
        type : "GET",
        url : request,
        contentType : ‘application/json‘,
        dataType : "json",
        data : data,
        success : function(json) {
            //从后台获取到数据后进行表格的渲染
            $(‘#featureBusinessClassifyTable‘).bootstrapTable(‘load‘, json);
            //合并单元格,获取单元格中的数据
            var data = $(tableId).bootstrapTable(‘getData‘, true);
            //合并单元格
             mergeCells(data, "business", 1, $(tableId));
             mergeCells(data, "sm", 1, $(tableId));
             mergeCells(data, "technicalCore", 1, $(tableId));
        },
        error : function(json) {
            console.log("失败" + json);
        }
    })
}

 

以下是核心方法

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;
} 
}
}
for(var prop in sortMap){
console.log(prop,sortMap[prop])
}
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;
}
}

 后台从数据库获取全部数据时,要根据要合并的例进行order by,最大类在最前面然后以此类推,如下:

  public List<NbBusinessClassify> getAllOrderBy(String col,String search) {
          String sql = null;
          if("".equals(search)||search==null){
             sql = "select * from nb_feature_business_classify order by "+col +",SM,technical_core,group_leader";
          }else{
              //sql = "select * from nb_feature_business_classify where business_name like "+ search +" or SM like " +search+" or business_child like "+search+" order by "+col +",SM,technical_core,group_leader";
              sql = "select * from nb_feature_business_classify  where LOCATE(‘"+search+"‘,business_name) >0 or LOCATE(‘"+search+"‘,SM) >0 or LOCATE(‘"+search+"‘,business_child) >0 order by "+col +",SM,technical_core,group_leader";  
          }
          return getSession().createSQLQuery(sql).addEntity(NbBusinessClassify.class).list();
    }

 

bootstrap table合并单元格(该版本是简单的应用)

标签:出现   ESS   table   child   data   get   数据   business   tar   

原文地址:https://www.cnblogs.com/blogtt/p/11168296.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!