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


    //获取列表数据
    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();
        }
  • 相关阅读:
    第三次作业成绩
    现代程序设计 作业6
    动态期末成绩
    课堂作业成绩公布(游戏服务器以及客户端设计)
    第二次作业(homework-02)成绩公布
    指定长度,页面显示换行
    java学习流程
    对象比对
    开发语言转型
    Asp.Net 自定义储存Session方式
  • 原文地址:https://www.cnblogs.com/blogtt/p/11168296.html
Copyright © 2020-2023  润新知