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


相关推荐

  • java如何实现封装_java如何实现封装

    java如何实现封装_java如何实现封装Java中类的封装是如何实现的封装是将对象的信息隐藏在对象内部,禁止外部程序直接访问对象内部的属性和方法。java封装类通过三个步骤实现:(1)修改属性的可见性,限制访问。(2)设置属性的读取方法。(3)在读取属性的方法中,添加对属性读取的限制。Java中什么叫封装呢?继承和多态都明白些,就是封装理解不上去,老师没关于这个问题,我想举一个例子:lz如果你接触过老的面向过程的编程,以前…

    2022年7月7日
    17
  • PHP验证邮箱地址代码

    PHP验证邮箱代码:functionisEmail($email){returnstrlen($email)>6&&preg_match("/^[\w\

    2021年12月20日
    65
  • 数据结构与算法二叉树的算法_数据结构c语言二叉树的深度

    数据结构与算法二叉树的算法_数据结构c语言二叉树的深度一、什么是二叉树1.概述首先,需要了解树这种数据结构的定义:树:是一类重要的非线性数据结构,是以分支关系定义的层次结构。每个结点有零个或多个子结点;没有父结点的结点称为根结点;每一个非根结点有且

    2022年8月16日
    7
  • python课程安排

    作为最流行的脚本语言之一,python具有内置的高级数据结构和简单面向对象编程思想实现。同时,其语法简洁而清晰,类库丰富而强大,非常适合进行快速原型开发。另外,python可以运行在多种系统平台下,从

    2022年3月29日
    48
  • mysql查询语句执行过程及运行原理命令_MySQL常用命令

    mysql查询语句执行过程及运行原理命令_MySQL常用命令Mysql查询语句执行原理数据库查询语句如何执行?DML语句首先进行语法分析,对使用sql表示的查询进行语法分析,生成查询语法分析树。 语义检查:检查sql中所涉及的对象以及是否在数据库中存在,用户是否具有操作权限等 视图转换:将语法分析树转换成关系代数表达式,称为逻辑查询计划; 查询优化:在选择逻辑查询计划时,会有多个不同的表达式,选择最佳的逻辑查询计划; 代码生成:必须将逻辑查…

    2025年6月9日
    2
  • 导出的Excel名字乱码_恢复的excel文件乱码

    导出的Excel名字乱码_恢复的excel文件乱码因为经常要用到导出功能,之前因为文件名乱码,所以都用英文或是拼音缩写来代替,今天特意要接觉下这个问题。顺便记录下。望对小白有用。/***导出结算详情列表*@return*/publicvoiddepositLogExport(){Stringtitle=”押金流水报表”;StringexcelName=”押金流水报表.xls”;OutputStreamos=null;t…

    2022年8月30日
    2

发表回复

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

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