当前位置: 首页 > 编程日记 > 正文

easyui 报表合并单元格

前段时间工作中碰到有需求,要求数据按下图所示格式来显示,当时在园子里看到了一篇文章(时间久了,想不起是哪一篇),研究了后做出了如下的DEMO,在此当作学习笔记,简单记录一下。

首先是效果图,如下:

数据库临时建的DEMO表,如下:

前台代码,如下:

<form id="form1"><div data-options="region:'north',title:'查询条件',collapsible:false,height:'auto'"><div class="cx-box"><ul class="cx-ul"><li><span>登录名称</span><input id="txtName" type="text" /></li><li><span>操作员名</span><input id="txtDeptName" type="text" /></li><li><span>角色</span><input id="txtRole" class="easyui-combobox" style="height:22px;width:132px" /></li><li><span>学生</span><input id="txtStudent" style="height:22px;width:132px" /></li></ul><div class="cx-button"><a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width: 60px;" οnclick="QueryData();">查询</a><a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" style="width: 60px;" οnclick="AddData();">添加</a></div><div class="clear"></div></div></div><div data-options="region:'center'"><div class="easyui-layout" data-options="fit:true,border:false"><div data-options="region:'center',title:'用户列表',border:false" id="datadiv"><table id="datagrid"></table></div></div></div><input type="hidden" id="hidOperatorId" /><input type="hidden" id="hidDeptCode" />
</form>
<script>$.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;}}}});});});}});var sortFlag = false;       $(function () {//加载数据 $("#datagrid").datagrid({url: 'GetDtUser1',border: false,singleSelect: true,rownumbers: true,toolbar: "#toolbar",columns: [[{ field: 'id',hidden:true, title: '序号', width: 100 },{ field: 'sex', title: '性别', width: 100 },{field: 'divr_user', title: '姓名', width: 100},{field: 'price', title: '单价', width: 100},{field: 'num', title: '数量', width: 100},{field: 'sum', title: '金额', width: 100,formatter: function (value, row, index) {if (!value && (row.price != "" && row.num != "")) {return row.price * row.num;}else if(!value && row.price != ""){return row.price;}else {return value;}}}]],onLoadSuccess: function (data) {if (data.total > 0) {if (!sortFlag) $(this).datagrid("autoMergeCells", ['sex']);var rows = $('#datagrid').datagrid('getRows');var currArea = '';var total = 0;//小计var sumTotal = 0;//合计var len = rows.length - 1;var objectArray = [];$.each(rows, function (i, item) {//循环所有行记录var sum = 0;//计算小计的sumif (item.price != "" && item.num != "") {sum = item.price * item.num;} else {sum = item.price;}if (!currArea) {//判断是还是是当前区域id,如果不是赋值当前记录的sex给变量currArea = item.sex;}if (currArea == item.sex) {//如果是当前的区域id,计数小计total += sum;} else {//不是当前的,添加datagrid的一条行数据sumTotal += total;objectArray.push({index: i,row: {sex: '<span class="subtotal">小计</span>',sum: '<span class="subtotal">' + total.toFixed(2) + '</span>'}});currArea = item.sex;total = sum;}if (i == len) {//最后一行sumTotal += total;objectArray.push({index: i,row: {sex: '<span class="subtotal">小计</span>',sum: '<span class="subtotal">' + total.toFixed(2) + '</span>'}});}});var num = 0;$.each(objectArray, function (i, item) {//循环所有待添加的插入行记录,对应插入位置是原始行数据对应记录的最后一行if (i < objectArray.length - 1) {//判断是否是最后一行item.index = item.index + num;$('#datagrid').datagrid('insertRow', {index: item.index,	// 索引从0开始row: item.row});$('#datagrid').datagrid('mergeCells', {index: item.index,field: 'sex',colspan: '4'})num++;} else {$('#datagrid').datagrid('appendRow',item.row);$('#datagrid').datagrid('appendRow',{sex: '<span class="subtotal">合计</span>',sum: '<span class="subtotal">' + sumTotal.toFixed(2) + '</span>'});$('#datagrid').datagrid('mergeCells', {index: $('#datagrid').datagrid('getRows').length - 2,field: 'sex',colspan: '4'})$('#datagrid').datagrid('mergeCells', {index: $('#datagrid').datagrid('getRows').length - 1,field: 'sex',colspan: '4'})}});}}});});</script>

转载于:https://www.cnblogs.com/skye-mei/p/7998303.html

相关文章:

HDU2594 KMP next数组的应用

这道题就是给你两个串s1, s2让你求出s1 s2的最长相同前缀和后缀&#xff0c; 我们直接将s1 s2连接到一起然后处理一下next数组即可&#xff0c; 注意答案应该是min(len(s1), len(s2) , next[len]), 代码如下&#xff1a; #include <cstdio> #include <cstring> #in…

c语言中浮点数和整数转换_C中的数据类型-整数,浮点数和空隙说明

c语言中浮点数和整数转换C中的数据类型 (Data Types in C) There are several different ways to store data in C, and they are all unique from each other. The types of data that information can be stored as are called data types. C is much less forgiving about d…

【如何快速的开发一个完整的iOS直播app】(美颜篇)

前言在看这篇之前&#xff0c;如果您还不了解直播原理&#xff0c;请查看这篇文章如何快速的开发一个完整的iOS直播app(原理篇)开发一款直播app&#xff0c;美颜功能是很重要的&#xff0c;如果没有美颜功能&#xff0c;可能分分钟钟掉粉千万&#xff0c;本篇主要讲解直播中美颜…

Linux内核分析——第五章 系统调用

第五章 系统调用 5.1 与内核通信 1、系统调用在用户空间进程和硬件设备之间添加了一个中间层&#xff0c;该层主要作用有三个&#xff1a; &#xff08;1&#xff09;为用户空间提供了一种硬件的抽象接口 &#xff08;2&#xff09;系统调用保证了系统的稳定和安全 &#xff08…

BZOJ 3110

http://www.lydsy.com/JudgeOnline/problem.php?id3110 整体二分区间修改树状数组维护 #include<cstdio> #define FOR(i,s,t) for(register int is;i<t;i) inline int max(int a,int b){return a>b?a:b;} inline int min(int a,int b){return a<b?a:b;} type…

css 选择器 伪元素_CSS伪元素-解释选择器之前和之后

css 选择器 伪元素选择器之前 (Before Selector) The CSS ::before selector can be used to insert content before the content of the selected element or elements. It is used by attaching ::before to the element it is to be used on.CSS ::before选择器可用于在选定…

各种面试题啊1

技术 基础 1.为什么说Objective-C是一门动态的语言&#xff1f; 什么叫动态静态 静态、动态是相对的&#xff0c;这里动态语言指的是不需要在编译时确定所有的东西&#xff0c;在运行时还可以动态的添加变量、方法和类 Objective-C 可以通过Runtime 这个运行时机制&#xff0c…

PEP8 Python

写在前面 对于代码而言&#xff0c;相比于写&#xff0c;它更多是读的。 pep8 一、代码编排 缩进&#xff0c;4个空格的缩进&#xff0c;编辑器都可以完成此功能&#xff1b;每行最大长度79&#xff0c;换行可以使用反斜杠&#xff0c;换行点要在操作符的后边。类和top-level函…

粒子滤波 应用_如何使用NativeScript开发粒子物联网应用

粒子滤波 应用If youre developing any type of IoT product, inevitably youll need some type of mobile app. While there are easy ways, theyre not for production use.如果您要开发任何类型的物联网产品&#xff0c;则不可避免地需要某种类型的移动应用程序。 尽管有简单…

wkwebView基本使用方法

WKWebView有两个delegate,WKUIDelegate 和 WKNavigationDelegate。WKNavigationDelegate主要处理一些跳转、加载处理操作&#xff0c;WKUIDelegate主要处理JS脚本&#xff0c;确认框&#xff0c;警告框等。因此WKNavigationDelegate更加常用。 比较常用的方法&#xff1a; #p…

引用类型(一):Object类型

对象表示方式 1、第一种方式&#xff1a;使用new操作符后跟Object构造函数 var person new Object();<br/> person.name Nicholas;<br/> person.age 29; 2、对象字面量表示法 var person {name:Nicholas,age:29 } *:在age属性的值29的后面不能添加逗号&#xf…

(第四周)要开工了

忙碌的一周又过去了&#xff0c;这周的时间很紧&#xff0c;但是把时间分配的比较均匀&#xff0c;考研复习和各门功课都投入了一定的精力&#xff0c;所以不像前三周一样把大多数时间都花费在了软件工程上。也因为结对项目刚开始&#xff0c;我们刚刚进行任务分工以及查找资料…

统计数字,空白符,制表符_为什么您应该在HTML中使用制表符空间而不是多个非空白空间(nbsp)...

统计数字,空白符,制表符There are a number of ways to insert spaces in HTML. The easiest way is by simply adding spaces or multiple character entities before and after the target text. Of course, that isnt the DRYest method.有多种方法可以在HTML中插入空格。…

Python20-Day02

1、数据 数据为什么要分不同的类型 数据是用来表示状态的&#xff0c;不同的状态就应该用不同类型的数据表示&#xff1b; 数据类型 数字&#xff08;整形&#xff0c;长整形&#xff0c;浮点型&#xff0c;复数&#xff09;&#xff0c;字符串&#xff0c;列表&#xff0c;元组…

Android网络框架-OkHttp3.0总结

一、概述 OkHttp是Square公司开发的一款服务于android的一个网络框架&#xff0c;主要包含&#xff1a; 一般的get请求一般的post请求基于Http的文件上传文件下载加载图片支持请求回调&#xff0c;直接返回对象、对象集合支持session的保持github地址&#xff1a;https://githu…

第一天写,希望能坚持下去。

该想的都想完了&#xff0c;不该想的似乎也已经尘埃落定了。有些事情&#xff0c;终究不是靠努力或者不努力获得的。顺其自然才是正理。 以前很多次想过要努力&#xff0c;学习一些东西&#xff0c;总是不能成&#xff0c;原因很多&#xff1a; 1.心中烦恼&#xff0c;不想学…

mac gource_如何使用Gource显示项目的时间表

mac gourceThe first time I heard about Gource was in 2013. At the time I watched this cool video showing Ruby on Rails source code evolution:我第一次听说Gource是在2013年 。 当时&#xff0c;我观看了这段很酷的视频&#xff0c;展示了Ruby on Rails源代码的演变&a…

insert语句让我学会的两个MySQL函数

我们要保存数据到数据库&#xff0c;插入数据是必须的&#xff0c;但是在业务中可能会出于某种业务要求&#xff0c;要在数据库中设计唯一索引&#xff1b;这时如果不小心插入一条业务上已经存在同样key的数据时&#xff0c;就会出现异常。 大部分的需求要求我们出现唯一键冲突…

对PInvoke函数函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。...

C#引入外部非托管类库时&#xff0c;有时候会出现“对PInvoke函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配”的报错。 通常在DllImport标签内加入属性CallingConventionCallingConvention.Cdecl即可解决该问题。 如&#xff1a; [Dll…

Python字符串方法用示例解释

字符串查找方法 (String Find Method) There are two options for finding a substring within a string in Python, find() and rfind().在Python中的字符串中有两个选项可以找到子字符串&#xff1a; find()和rfind() 。 Each will return the position that the substring …

关于命名空间namespace

虽然任意合法的PHP代码都可以包含在命名空间中&#xff0c;但只有以下类型的代码受命名空间的影响&#xff0c;它们是&#xff1a;类&#xff08;包括抽象类和traits&#xff09;、接口、函数和常量。在声明命名空间之前唯一合法的代码是用于定义源文件编码方式的 declare 语句…

一 梳理 从 HDFS 到 MR。

MapReduce 不仅仅是一个工具&#xff0c;更是一个框架。我们必须拿问题解决方案去适配框架的 map 和 reduce 过程很多情况下&#xff0c;需要关注 MapReduce 作业所需要的系统资源&#xff0c;尤其是集群内部网络资源的使用情况。这是MapReduce 框架在设计上的取舍&#xff0c;…

huffman树和huffman编码

不知道为什么&#xff0c;我写的代码都是又臭又长。 直接上代码&#xff1a; #include <iostream> #include <cstdarg> using namespace std; class Node{ public:int weight;int parent, lChildren, rChildren;Node(int weight, int parent, int lChildren, int …

react 监听组合键_投资组合中需要的5个React项目

react 监听组合键Youve put in the work and now you have a solid understanding of the React library.您已经完成工作&#xff0c;现在对React库有了扎实的了解。 On top of that, you have a good grasp of JavaScript and are putting its most helpful features to use …

Unity 单元测试(PLUnitTest工具)

代码测试的由来 上几个星期上面分配给我一个装备系统,我经过了几个星期的战斗写完90%的代码. 后来策划告诉我需求有一定的改动,我就随着策划的意思修改了代码. 但是测试(Xu)告诉我装备系统很多功能都用不上了. Xu: 我有300多项测试用例,现在有很多项都无法运行了. 你修改了部分…

Best Time to Buy and Sell Stock II

题目&#xff1a; Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multipl…

求给定集合的幂集

数据结构中说这个问题可以用类似8皇后的状态树解法。 把求解过程看成是一棵二叉树&#xff0c;空集作为root&#xff0c;然后遍历给定集合中的元素&#xff0c;左子树表示取该元素&#xff0c;右子树表示舍该元素。 然后&#xff0c;root的左右元素分别重复上述过程。 就形成…

angular 命令行项目_Angular命令行界面介绍

angular 命令行项目Angular is closely associated with its command-line interface (CLI). The CLI streamlines generation of the Angular file system. It deals with most of the configuration behind the scenes so developers can start coding. The CLI also has a l…

oracle-imp导入小错filesize设置

***********************************************声明*********************************************************************** 原创作品&#xff0c;出自 “深蓝的blog” 博客。欢迎转载&#xff0c;转载时请务必注明出处。否则追究版权法律责任。表述有错误之处&#xf…