easyUI 行合并 整列更新

通过我对jQuery几天的学习 整合出以下对列合并 并对代码的高度封装 整体效果出来 数据为真实数据暂不方便展出
1.本文版权归作者所有
2.基本类高度封装不需要读者再进行扩展 复制粘贴 完成读者的业务即可
3.作者不反对复制代码
4.完整读完我的代码请读者也学会封装代码 以后易用
5.基本类中的函数经过各种测试基本没有问题
6.随着需求的增加基本类我会及时更新 不影响之前的功能
7.如果有疑问请在评论中提交即可
8.列更新直接调用for循环你的数据集list 调用:

// 这样即可全部刷新
list.forEash(item=>{
$("#table").datagrid("refreshRow",i); //i 为行号 从0开始
})
EasyUI 列合并(jQuery 扩展插件)

$.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;
                                    }
                                }
                            }
                        });
                });
        });
    }
});
封装的基本类

function Base() {

    const SUBMIT_STATUS_YES =1;
    const SUBMIT_STATUS_NO = -1;

    this.tableId = 'Mytable';
    this.propertyNames = ['',''];  //要合并的列
    this.ignoreList = [''];
    this.editIndex = -1;
    this.hasEditData = new Array();
    var submitStatus = -1;


    this.init = function(){
        var me = this;
            $('#'+this.tableId).datagrid({
                onClickCell: function(index,field,value){
                    me.editorDatagrid(index,field,value);
                }
            })
        this.InitSubmitStatus();

    }
    this.merge = function(){
        $("#"+this.tableId).datagrid("autoMergeCells",this.propertyNames);
    }
    this.ignore = function(field){
        var arr =  this.propertyNames;
        this.ignoreList.forEach(item=>{arr.push(item);})
        return !arr.includes(field);
    }
    this.editorDatagrid=function(index,field,value){
            if(submitStatus == SUBMIT_STATUS_YES){
                return false;
            }
            if(!this.ignore(field) && this.editIndex == -1){
                return false;
            }
            if(this.editIndex != -1){
                $("#"+this.tableId).datagrid('endEdit', this.editIndex);
                $("#"+this.tableId).datagrid("autoMergeCells", this.propertyNames);
                var row =  $('#'+this.tableId).datagrid('getData').rows[this.editIndex];
                this.hasEditData.push(row);
                if(this.ignore(field)){
                    $("#"+this.tableId).datagrid('beginEdit',index);
                }
                this.editIndex = index;
            }else{
                if(this.ignore(field)){
                    $("#"+this.tableId).datagrid('beginEdit',index);
                }
                this.editIndex = index;
            }
    }
    this.getHasEditDataArray = function(){
        return this.hasEditData;
    }
    this.getValue = function(v){
            if(v){
                return v;
            }
            return '';
    }
    this.getGlobalArray = function(){
        var rows = $("#"+this.tableId).datagrid("getRows");
        var dataList = new Array();
        if(rows &&rows.length>0) {
            for (var i = 0; i < rows.length; i++) {
                dataList.push(rows[i]);
            }
        }
        return dataList;
    }
    this.updateSubmitStatus = function(){
        submitStatus = SUBMIT_STATUS_YES;
    }
    this.InitSubmitStatus = function(){
        submitStatus = SUBMIT_STATUS_NO
    }
    this.submitInfoAbleEdit = function(){
        this.InitSubmitStatus();
    }

    this.submitInfoDisAbleEdit = function(){
        this.updateSubmitStatus();
    }

}

实现基本类 覆盖属性

  $(function () {
  var baseE = new Base();
        function PreViewOfPresaleAnnualBussinessPlan() {
            this.tableId = 'table'; //必须
            this.propertyNames = ['carName', 'typeName', 'category'];  //要合并的列  要和并的列不参与编辑 必须
        }

        var preViewOfPresaleAnnualBussinessPlan = new PreViewOfPresaleAnnualBussinessPlan();
        $.extend(baseE, preViewOfPresaleAnnualBussinessPlan);
        baseE.init();

        $("#confirm").on("click", function () {
            var list = baseE.getHasEditDataArray(); //这是调用基本类中的方法
            var list = baseE.getGlobalArray(); //这是获取所有的行的方法

        });
function onLoadSuccess(data) {
        baseE.merge()
    }
实现列合并并且指定列可编辑
 <table id="table"  rownumbers="true"
               data-options="fitColumns: true,
               iconCls: 'icon-edit',
                remoteSort:true,
                url:url,
                pagination:false,
                singleSelect:true,
                onLoadSuccess:onLoadSuccess,
                method: 'get'">
            <thead frozen="true">
            <tr>
                <th data-options="field:'id',width:80,align:'center',hidden:true"></th>
                <th data-options="field:'carName',width:200,align:'center'">名称</th>
                <th data-options="field:'typeName',width:200,align:'center'">类型</th>
                <th data-options="field:'category',width:200,align:'center'">业务类别</th>
            </tr>
            </thead>
            <thead>
            <tr>
                <th data-options="width:400,align:'center'" colspan="2">1</th>
                <th data-options="width:400,align:'center'" colspan="2">2</th>
                <th data-options="width:400,align:'center'" colspan="2">3</th>
                <th data-options="width:400,align:'center'" colspan="2">4</th>
                <th data-options="width:400,align:'center'" colspan="2">5</th>
                <th data-options="width:400,align:'center'" colspan="2">6</th>
                <th data-options="width:400,align:'center'" colspan="2">7</th>
                <th data-options="width:400,align:'center'" colspan="2">8</th>
                <th data-options="width:400,align:'center'" colspan="2">9</th>
                <th data-options="width:400,align:'center'" colspan="2">10</th>
                <th data-options="width:400,align:'center'" colspan="2">11</th>
                <th data-options="width:400,align:'center'" colspan="2">12</th>
                <th data-options="width:400,align:'center'" colspan="2">合计</th>
            </tr>
                  <tr>
                <th data-options="field:'januaryOld',width:400,align:'center' ">第一</th>
                <th data-options="field:'january',width:400,align:'center' ,editor:'text'">第二</th>
                <th data-options="field:'februaryOld',width:400,align:'center'">第一</th>
                <th data-options="field:'february',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'marchOld',width:400,align:'center'">第一</th>
                <th data-options="field:'march',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'aprilOld',width:400,align:'center'">第一</th>
                <th data-options="field:'april',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'mayOld',width:400,align:'center'">第一</th>
                <th data-options="field:'may',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'juneOld',width:400,align:'center'">第一</th>
                <th data-options="field:'june',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'julyOld',width:400,align:'center'">第一</th>
                <th data-options="field:'july',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'augustOld',width:400,align:'center'">第一</th>
                <th data-options="field:'august',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'septemberOld',width:400,align:'center'">第一</th>
                <th data-options="field:'september',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'octoberOld',width:400,align:'center'">第一</th>
                <th data-options="field:'october',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'novemberOld',width:400,align:'center'">第一</th>
                <th data-options="field:'november',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'decemberOld',width:400,align:'center'">第一</th>
                <th data-options="field:'december',width:400,align:'center',editor:'text'">第二</th>
                <th data-options="field:'totalOld',width:400,align:'center'">近12个月累计</th>
                <th data-options="field:'total',width:400,align:'center',editor:'text'">第二</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
效果
1552900193(1).jpg
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,734评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,931评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,133评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,532评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,585评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,462评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,262评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,153评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,587评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,792评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,919评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,635评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,237评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,855评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,983评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,048评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,864评论 2 354

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,101评论 1 32
  • 1 概述 本文档内容包括easyui的引入和easyui的使用实践,编写该文档的目的,主要为了给下次需要使用的ea...
    科比可比克阅读 3,601评论 2 6
  • 乖,请允许我最后一次这么喊你!当你收到这消息时,我就决定不再挽留你了!其实也不是记恨你,只是你近段决绝的心,对我伤...
    0o油条o0阅读 273评论 0 0
  • 今天开始我要学投资了,入市2年多没看过一本关于股票的书。都是人云亦云。追跌杀涨已经交了5位数的学费啦…… 人家...
    我是007编号330阅读 1,058评论 0 3
  • 这是一篇测试文稿 主要测试编辑页面的功能,包括字体等方面 你好 你好 你好 你好
    xiaoyang阅读 186评论 0 0