Easyui Datagrid相同连续列合Demo之三

Easyui Datagrid相同连续列合Demo之三

大家好,又见面了,我是全栈君。

效果图:

Easyui Datagrid相同连续列合Demo之三Easyui Datagrid相同连续列合Demo之三

html

复制代码
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Merge Cells for DataGrid - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../demo.css">
    <script type="text/javascript" src="../../jquery.min.js"></script>
    <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../extends.js"></script>
</head>
<body>
    <h2>Merge Cells for DataGrid</h2>
    <p>Cells in DataGrid body can be merged.</p>
    <div style="margin:20px 0;"></div>
    <table class="easyui-datagrid" id="dg" title="Merge Cells for DataGrid" style="width:700px;height:250px"
            data-options="
                rownumbers: true,
                singleSelect: true,
                iconCls: 'icon-save',
                data:qyData,
                method: 'get',
                onLoadSuccess: onLoadSuccess
            ">
        <thead>
            <tr>
                <th data-options="field:'productid',width:100">Product</th>
                <th data-options="field:'productname',width:80">ProductName</th>
                <th data-options="field:'itemid',width:80">Item ID</th>
                <th data-options="field:'listprice',width:80,align:'right'">List Price</th>
                <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>
                <th data-options="field:'attr1',width:240">Attribute</th>
                <th data-options="field:'status',width:60,align:'center'">Status</th>
            </tr>
        </thead>
    </table>
    <input type="button" value="合并" id="mergeCells" οnclick="hb()">
    <script type="text/javascript">
       var qyData = {"total":11,"rows":[
                            
                {"productid":"d1","productname":"p1","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
                {"productid":"d1","productname":"p1","unitcost":10.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
                {"productid":"d1","productname":"p2","unitcost":10.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},
                {"productid":"d2","productname":"p2","unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"},
                {"productid":"d2","productname":"p2","unitcost":12.00,"status":"P","listprice":35.50,"attr1":"Green Adult","itemid":"EST-13"},
                {"productid":"d2","productname":"p2","unitcost":12.00,"status":"P","listprice":158.50,"attr1":"Tailless","itemid":"EST-14"},
                {"productid":"d3","productname":"p3","unitcost":14.00,"status":"P","listprice":83.50,"attr1":"With tail","itemid":"EST-15"},
                {"productid":"d3","productname":"p3","unitcost":14.00,"status":"P","listprice":23.50,"attr1":"Adult Female","itemid":"EST-16"},
                {"productid":"d5","productname":"p5"},
                {"productid":"d4","productname":"p2","unitcost":10.00,"status":"P","listprice":89.50,"attr1":"Adult Male","itemid":"EST-17"},
                {"productid":"d4","productname":"p2","unitcost":10.00,"status":"P","listprice":63.50,"attr1":"Adult Male","itemid":"EST-18"}
            ]}

        var jcData = [
            {"unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
            {"unitcost":10.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"},
            {"unitcost":10.00,"status":"P","listprice":38.50,"attr1":"Venomless","itemid":"EST-11"},
            {"unitcost":12.00,"status":"P","listprice":26.50,"attr1":"Rattleless","itemid":"EST-12"}
        ]
        
        function onLoadSuccess(data){
            $(this).datagrid("autoMergeCellAndCells",['productid','productname']);
        
        }
        
        function hb(){
            var id = "d5";
            var data = $("#dg").datagrid('getData');
            var rows = data.rows;
            var total = data.total;
            var qFileds = ['productid','productname'];
            var qrow = {};
            var n = null;
            var d = 0;
            for(var i = 0;i<rows.length;i++){
               if(rows[i][qFileds[0]] == id){
                 if(n == null)  n = i;
                 d++;
               }
            }
            for(var i = 0;i<qFileds.length;i++){
                qrow[qFileds[i]] = rows[n][qFileds[i]];
            }
            var r = null;
            for(var i = 0;i<jcData.length;i++){
              //Array.prototype.push.apply(jcData[i], qrow);  //数组追加
              jcData[i] = $.extend({}, jcData[i],qrow);//json对象追加
              if(i == 0){
                 r = rows.splice(n,d,jcData[i]);//从n个位置,开始删除d个,并追加jcData 
              }else{
                 r = rows.splice(n,0,jcData[i]);
              }
            }
            total = total - d + jcData.length;
            $("#dg").datagrid('loadData',{total:total,rows:rows})
        }
    </script>
</body>
</html>
 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/108858.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • MCTS (Monte Carlo Tree Search)[通俗易懂]

    MCTS (Monte Carlo Tree Search)[通俗易懂]以下文章摘录自:《机器学习观止——核心原理与实践》京东:https://item.jd.com/13166960.html当当:http://product.dangdang.com/29218274.html(由于博客系统问题,部分公式、图片和格式有可能存在显示问题,请参阅原书了解详情)MCTS(MonteCarloTreeSearch)1.1MCTS概述在前面的学习中,我们分析了蒙特卡洛方法,本章节将为大家解开蒙特卡洛树搜索的“面纱”。虽…

    2022年6月22日
    26
  • SQL SELECT TOP 子句详解

    SQL SELECT TOP 子句详解SQLSELECTTOP子句SELECTTOP子句用于规定要返回的记录的数目。语法如下SELECTTOPnumber|percentcolumn_name(s)FROMtable_name;实例:从MyTables表里选取前两行数据实例2从MyTables表里取前百分之十的数据需要注意的是如下图那是我整张MyTables表的数据,可以看出根本没有十条数据,那那…

    2022年7月13日
    24
  • wget 安装yum_没有yum命令

    wget 安装yum_没有yum命令wget是一个从网络上自动下载文件的自由工具,支持通过HTTP、HTTPS、FTP三个最常见的TCP/IP下载,并可以使用HTTP代理。”wget”这个名称来源于“WorldWideWeb”与“get”的结合。在线安装wget使用命令yum-yinstallwget

    2022年10月17日
    4
  • Python-matplotlib画图(莫烦笔记)

    https://www.zhihu.com/collection/260736383&lt;此处就不自己写了,看了遍,照着写了一边,作者写的不错。不过有些有些偷懒,我只做了常见的功能&gt;作者:触摸壹缕阳光链接:https://zhuanlan.zhihu.com/p/33270402来源:知乎著作权归作者所有,转载请联系作者获得授权。1.前言Matplotlib是一个python的2D绘图库…

    2022年4月4日
    39
  • 一键锁定计算机快捷方式,还原win8系统创建一键锁定计算机的快捷方式的技巧…

    一键锁定计算机快捷方式,还原win8系统创建一键锁定计算机的快捷方式的技巧…今天和大家分享一下关于对win8系统创建一键锁定计算机的快捷方式设置的方法,在使用win8系统的过程中经常不知道如何去对win8系统创建一键锁定计算机的快捷方式进行设置,有什么好的办法去设置win8系统创建一键锁定计算机的快捷方式呢?在这里小编教你只需要1、首先在桌面上的空白处鼠标右击选择“新建–快捷方式”,然后在弹出来的创建快捷方式界面中,在“请键入对象的位置”框中输入:rundll32.ex…

    2022年7月21日
    16
  • vim 注释快捷键_vim编辑器快捷键

    vim 注释快捷键_vim编辑器快捷键我是个vim新手,非常喜欢这个工具,因为纯手工操作吧。可是有些快捷键还是不知道,写Python的时候经常要调试,会批量注释掉一些代码,vim不像pycharm那样Ctrl+/就可以了,反注释还是Ctrl+/。不过vim在这方面显得更强大更灵活点。有两种方法可以实现:第一种方法批量插入字符快捷键:Ctrl+v进入VISUALBLOCK(可视块)模式,按j(向下选取列)或者k

    2022年8月15日
    8

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号