zoukankan      html  css  js  c++  java
  • Easyui Datagrid相同连续列合并扩展(一)

    一.autoMergeCellAndCells实现效果

    function onLoadSuccess(data){
    	$(this).datagrid("autoMergeCellAndCells",['productid','productname']);
    }
    

      二.autoMergeCells实现效果

    function onLoadSuccess(data){
             $(this).datagrid("autoMergeCells",['productid','productname']);
     }

    三.扩展

    $.extend($.fn.datagrid.methods, {
        autoMergeCells : function (jq, fields) {
            return jq.each(function () {
                var target = $(this);
                if (!fields) {
                    fields = target.datagrid("getColumnFields");
                }
                var rows = target.datagrid("getRows");
                var i = 0,
                j = 0,
                temp = {};
                
                for (i; i < rows.length; i++) {
                    var row = rows[i];
                    j = 0;
                    for (j; j < fields.length; j++) {
                        var field = fields[j];
                        var tf = temp[field];
                        if (!tf) {
                            tf = temp[field] = {};
                            tf[row[field]] = [i];
                        } else {
                            var tfv = tf[row[field]];
                            if (tfv) {
                                tfv.push(i);
                            } else {
                                tfv = tf[row[field]] = [i];
                            }
                        }
                    }
                }
                $.each(temp, function (field, colunm) {
                    $.each(colunm, function () {
                        var group = this;
                        
                        if (group.length > 1) {
                            var before,
                            after,
                            megerIndex = group[0];
                            for (var i = 0; i < group.length; i++) {
                                before = group[i];
                                after = group[i + 1];
                                if (after && (after - before) == 1) {
                                    continue;
                                }
                                var rowspan = before - megerIndex + 1;
                                if (rowspan > 1) {
                                    target.datagrid('mergeCells', {
                                        index : megerIndex,
                                        field : field,
                                        rowspan : rowspan
                                    });
                                }
                                if (after && (after - before) != 1) {
                                    megerIndex = after;
                                }
                            }
                        }
                    });
                });
            });
        },
        autoMergeCellAndCells : function (jq, fields) {
            return jq.each(function () {
                var target = $(this);
                if (!fields) {
                    fields = target.datagrid("getColumnFields");
                }
                var cfield = fields[0];
                if (!cfield) {
                    return;
                }
                var rows = target.datagrid("getRows");
                var i = 0,
                j = 0,
                temp = {};
                for (i; i < rows.length; i++) {
                    var row = rows[i];
                    j = 0;
                    var tf = temp[cfield];
                    if (!tf) {
                        tf = temp[cfield] = {};
                        tf[row[cfield]] = [i];
                    
                    } else {
                        var tfv = tf[row[cfield]];
                        if (tfv) {
                            tfv.push(i);
                        } else {
                            tfv = tf[row[cfield]] = [i];
                            
                        }
                    }
                }
                
                $.each(temp, function (field, colunm) {
                    $.each(colunm, function () {
                        var group = this;
                        
                        if (group.length > 1) {
                            var before,
                            after,
                            megerIndex = group[0];
                            for (var i = 0; i < group.length; i++) {
                                before = group[i];
                                after = group[i + 1];
                                if (after && (after - before) == 1) {
                                    continue;
                                }
                                var rowspan = before - megerIndex + 1;
                                if (rowspan > 1) {
                                    for(var j=0;j<fields.length;j++){
                                        target.datagrid('mergeCells', {
                                            index : megerIndex,
                                            field : fields[j],
                                            rowspan : rowspan
                                       });
                                    }
                                }
                                if (after && (after - before) != 1) {
                                    megerIndex = after;
                                }
                            }
                        }
                    });
                });
            });
        }
        
    });
  • 相关阅读:
    pytest.mark.parametrize里面indirect参数详细解释
    linux环境安装python环境
    gitlab怎么给别人新增项目权限
    VMware虚拟机下的CentOS7如果Ping不通百度,解决办法
    ip configuration could not be reserved (no available address timeout etc.)虚拟机连接不上网卡解决办法
    虚拟机安装教程
    auto_now与auto_now_add之间的区别
    【二分答案】洛谷P2678 [NOIP2015 提高组] 跳石头/P1824 进击的奶牛/P2440木材加工/P1873 砍树
    团体程序设计天梯赛PTA L2-021点赞狂魔
    团体程序设计天梯赛PTA L2-020功夫传人
  • 原文地址:https://www.cnblogs.com/zt528/p/5563703.html
Copyright © 2011-2022 走看看