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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 基于Intel PXA272的Bootloader的设计与实现

    基于Intel PXA272的Bootloader的设计与实现

    2021年7月28日
    64
  • CRC校验算法[通俗易懂]

    CRC(CyclicRedundancyCheck):循环冗余检验。在链路层被广泛使用的检错技术。CRC原理:1、发送端1.1、在发送端先将数据分组,每组k个数据。假定要传送的数据是M。1.2、在数据M后面添加供差错检测的n位冗余码,然后构成一帧发送出去,一共发送(k+n)位。虽然添加n位冗余码增大了数据传送的开销,但是可以进行差错检测,当传输可能出现差错时,付出这种代价是值

    2022年4月18日
    76
  • LDAP 中的 RDN「建议收藏」

    LDAP 中的 RDN「建议收藏」什么是RDN,RDN和DN又有什么关系呢?很多第一次接触到LDAP的童鞋,经常会被一堆名字搞得晕头转向。RDN(relativedistinguishedname)中文翻译就是相对专有名字。一般指dn逗号最左边的部分,如cn=baby。DN是由多个RDN组织而成的。CN=cwikius,ou=Users,dc=jumpcloud,dc=com上面的RDN就不是一个了,这个DN的RDN就有4个,分别是:CN=cwikius ou=Use

    2022年6月18日
    41
  • RAID 磁盘阵列 详解[通俗易懂]

    RAID 磁盘阵列 详解[通俗易懂]RAID,Redundant Arrays of Independent Disks的简称,独立磁盘冗余阵列,简称磁盘阵列。 磁盘阵列其实也分为软阵列 (Software Raid)和硬阵列 (Hardware Raid) 两种.  软阵列:即通过软件程序并由计算机的 CPU提供运行能力所成. 由于软件程式不是一个完整系统故只能提供最基本的 RAID容错功能. 其他如热备用硬盘的设置,

    2022年6月9日
    60
  • ActionBar 背景色修改

    ActionBar 背景色修改

    2021年6月20日
    87
  • 写给夏燕第十一个男人「建议收藏」

    写给夏燕第十一个男人「建议收藏」悲哀,(李旧)是她第十一个男人。她想要什么呢???很多男人吗?很多是多少?我是她第十个男人,我原理她了:“说自己以前走的路不可能回头了,叫我不要在过问她以前的事了”。过也两个月后,可还死不改心,还有多少男人被她骗呢?   夏燕(安徽宿松人) 她电话13764996496 15300910532 13917482046   过年回家时,我和夏燕(我第一个女人)认识我不到24小时,就和她发生过关系,还

    2022年9月18日
    1

发表回复

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

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