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>
 

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 使用腾讯云直播开发直播功能违法吗_腾讯云直播插件

    使用腾讯云直播开发直播功能违法吗_腾讯云直播插件前言:最近公司开发app直播功能,我是后端,使用java开发,经过考虑选择使用腾讯的云直播功能,主要是考虑到腾讯在这方面可以说是很有实力的了。然后就是选择产品的问题,腾讯提供了几种直播的解决方案,最完整的是互动直播,这是一套比较完善的直播解决方案,但是费用比较贵,所以。。。我们选择了云直播和云通信(IM)组合,主要是因为本来app中就集成云通信,也就是云直播用来做视频交互,云通信用来做弹幕和直…

  • 使用Fiddler进行Mock测试

    使用Fiddler进行Mock测试目录1、接口抓包2、复制该接口数据到本地3、修改你要mock的数据4、替换json文件1)在websession面板中找到对应的请求,然后将其拖到AutoResponder面板中。2)在RuleEditor中单击“Findafile…”,选择本地json文件的路径。5、激活规则6、save,刷新页面1、接口抓包找到要mock的接口,打开fiddler抓包以某某接口为例,找到下面的接口http://XXX/SYSTEMS2、复制该接口数据到本..

  • 计算机入门新人必学,电脑新手入门教程 让你快速上手

    计算机入门新人必学,电脑新手入门教程 让你快速上手随着互联网时代的快速发展,电脑发展也相当的成熟,新手学电脑可以快速入门,是每个新手梦寐以求的事情,但是不会所有人都可以快速上手,最近很多用户咨询我关于零基础学电脑先学什么,或者是电脑新手入门必学什么东西,那么接下来,我就给大家精心准备了电脑新手入门教程,大家一起来看看吧。电脑新手入门教程1、第一步是鼠标演练,先要熟悉拖动、复制、粘贴、移动等,主要训练自己对功能的了解和熟练度。2、开始学习用键盘打字…

  • Runnable 和Callable的实现与区别,应用场景

    Java提供了三种创建线程的方法1:通过实现Runnable接口2:通过继承Thread接口3:通过Callable和Future创建线程相同点都是接口都可以编写多线程程序都采用Thread.start()启动线程不同点(1)Callable规定的方法是call(),Runnable规定的方法是run()。其中Runnable可以提交给Thread来包装下,直接启动一个…

  • xx学OD — 函数参考

    xx学OD — 函数参考

  • 大数据认知作业[通俗易懂]

    大数据认知作业[通俗易懂]大数据认知实习作业目录关于作者关于大数据我对大数据的认识目前大数据应用利用大数据的实例大数据分析交通目录关于作者各位博友大家好,我是新晋小白JW,作为一名刚步入学习的小白,我会发表一些我的主观看法,望大家多多指导关于大数据大数据(bigdata),指无法在一定时间范围内用常规软件工具进行捕捉、管理和处理的数据集合,是需要新处理模式才能具有更强的决策力、洞察发现力和流程优化能力的海量、高增长率和多样化的信息资产。具有海量的数据规模、快速的数据流转、多样的数据类型和价值密度低的四大特征。大数据的5V

发表回复

您的电子邮箱地址不会被公开。

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