eayUI-datagrid 的当前页合计and总合计

一、HTML代码

 1 <table id="dg" class="easyui-datagrid" style="width: 100%; height: 400px;" data-options="">
 2                 <thead>
 3                     <tr>
 4                         <th data-options="field:‘DeviceId‘,checkbox:true"></th>
 5                         <th data-options="field:‘DeviceName‘, width:120,align:‘center‘" >名称</th>
 6                         <th data-options="field:‘DeviceUnitName‘, width:80,align:‘center‘">单位</th>
 7                         <th data-options="field:‘MakePlace‘, width:120,align:‘center‘">产地</th>                           <th data-options="field:‘OriginalValue‘,width:90,align:‘center‘">资产原值</th>
 8                         <th data-options="field:‘BuyTime‘, width:120,align:‘center‘">购置日期</th>
 9
10                     </tr>
11                 </thead>
12             </table>

二、JS代码:showFooter: true,代表grid添加总合计行。

 1 $(".easyui-datagrid").datagrid({
 2                 rownumbers: true,
 3                 singleSelect: false,
 4                 fitColumns: false,
 5                 idField: ‘DeviceId‘,
 6                 method: ‘post‘,
 7                 url: ‘/Admin/Report/DeviceDetialListSearch‘,
 8                 remoteSort: false,
 9                 multiSort: false,
10                showFooter: true,
11                 pagination: true,
12                 pageSize: 10,
13                 pageList: [10,20,30],
14                 queryParams: {
15                     ‘DeviceIdList‘:"",
16                 ‘DeviceName‘:$("#DeviceName").combobox(‘getValue‘),
17
18                 },
19                 onLoadSuccess: function () {
20                     //$("#dg").datagrid(‘clearChecked‘);//清除复选框
21                     //$("#dg").datagrid(‘load‘);
22                 }
23             });

三、后台Controller函数 DeviceDetialListSearch(); StringBuilder jsonBuilder 就是要添加的Footer。和分页一起整合成Json传到前台datagrid,会自动识别。PageCount 是当前页行数,PageValues就是当前页 原值那一列 OriginalValue的总合计。SearchForDetail()求得是当前页的数据。SearchForDetailSum()求得是总合计。

  1  public ActionResult DeviceDetialListSearch()
  2         {
  3             DataTable dt = new DataTable();
  4             FADeviceInfoModel InfoModel = new FADeviceInfoModel();
  5             string DeviceIdList = Request["DeviceIdList"];
  6
  7             int pageSize = int.Parse(Request["rows"]);
  8             int nowPage = int.Parse(Request["page"]);
  9             int recordCount = 0;  //搜索条件下的总记录数量
 10             dt = InfoModel.SearchForDetail(pageSize, nowPage, out recordCount, DeviceIdList,Request["DeviceName"]);
 11             //当前页统计
 12             string PageValues = "";
 13             int PageCount = 0;
 14             if (dt != null)
 15             {
 16                 PageValues = dt.Compute("Sum(OriginalValue)", "").ToString();
 17                 PageCount = dt.Rows.Count;
 18             }
 19
 20             DataTable DtTotal = InfoModel.SearchForDetailSum(DeviceIdList,Request["DeviceName"]);
 21
 22             StringBuilder jsonBuilder = new StringBuilder();
 23             # region 当前页总合计
 24             jsonBuilder.Append("{");
 25             jsonBuilder.Append("\"");
 26             jsonBuilder.Append("DeviceName");
 27             jsonBuilder.Append("\":\"");
 28             jsonBuilder.Append("当前页总合计");
 29             jsonBuilder.Append("\",");
 30
 37             jsonBuilder.Append("\"");
 38             jsonBuilder.Append("DeviceUnitName");
 39             jsonBuilder.Append("\":\"");
 40             jsonBuilder.Append("数量");
 41             jsonBuilder.Append("\",");
 42
 43             jsonBuilder.Append("\"");
 44             jsonBuilder.Append("MakePlace");
 45             jsonBuilder.Append("\":\"");
 46             jsonBuilder.Append(PageCount);
 47             jsonBuilder.Append("\",");
 48
 49             jsonBuilder.Append("\"");
 50             jsonBuilder.Append("OriginalValue");
 51             jsonBuilder.Append("\":\"");
 52             jsonBuilder.Append("原值");
 53             jsonBuilder.Append("\",");
 54
 55             jsonBuilder.Append("\"");
 56             jsonBuilder.Append("BuyTime");
 57             jsonBuilder.Append("\":\"");
 58             jsonBuilder.Append(PageValues);
 59             jsonBuilder.Append("\"");
 60             jsonBuilder.Append("},");
 61             #endregion
 62
 63             #region 总合计
 64             jsonBuilder.Append("{");
 65             jsonBuilder.Append("\"");
 66             jsonBuilder.Append("DeviceName");
 67             jsonBuilder.Append("\":\"");
 68             jsonBuilder.Append("总合计");
 69             jsonBuilder.Append("\",");
 70
 77             jsonBuilder.Append("\"");
 78             jsonBuilder.Append("DeviceUnitName");
 79             jsonBuilder.Append("\":\"");
 80             jsonBuilder.Append("数量");
 81             jsonBuilder.Append("\",");
 82
 83             jsonBuilder.Append("\"");
 84             jsonBuilder.Append("MackePlace");
 85             jsonBuilder.Append("\":\"");
 86             jsonBuilder.Append(DtTotal.Rows[0]["SumCount"]);
 87             jsonBuilder.Append("\",");
 88
 89             jsonBuilder.Append("\"");
 90             jsonBuilder.Append("OriginalValue");
 91             jsonBuilder.Append("\":\"");
 92             jsonBuilder.Append("原值");
 93             jsonBuilder.Append("\",");
 94
 95             jsonBuilder.Append("\"");
 96             jsonBuilder.Append("BuyTime");
 97             jsonBuilder.Append("\":\"");
 98             jsonBuilder.Append(DtTotal.Rows[0]["SumOriginalValue"]);
 99             jsonBuilder.Append("\"");
100             jsonBuilder.Append("}");
101             #endregion
102
103             return Content(MyJson.DataTableToJsonByPage(dt, recordCount, jsonBuilder.ToString()));
104         }

四、Model函数:SearchForDetail()求得是当前页的数据。

 1  public DataTable SearchForDetail(int pageSize, int nowPage, out int recordCount, string DeviceIdList, string DeviceName)
 3         {
 4             string sqlCondition = " ";
 5             if (DeviceIdList != null && !DeviceIdList.Equals(""))
 6                 sqlCondition += " and FADeviceInfo.DeviceId not in (" + DeviceIdList + ")";
 7             if (DeviceName != null && !DeviceName.Equals(""))
 8                 sqlCondition += " and (FADeviceInfo.DeviceName like ‘%" + DeviceName + "%‘ or FADeviceInfo.DeviceInputCode like ‘%" + DeviceName + "%‘)";
 9
10             string sqlOn = " left join FADepartment on FADeviceInfo.DepartmentId=FADepartment.DepartmentId ";
11             sqlOn += " left join FADeviceUnit on FADeviceInfo.DeviceUnitId=FADeviceUnit.DeviceUnitId ";
12
13             string sqlOrder = " order by DeviceId desc ";
14             string sqlResult = " DeviceId,DeviceStatus,DeviceCode,DeviceName,DepartmentName,DeviceSpec,DeviceUnitName,OriginalValue,MakePlace,BuyTime,FinancialCode ";
15
16             string sqlSon = "(select top " + (nowPage - 1) * pageSize + " DeviceId from FADeviceInfo " + sqlOn + " where 1 = 1 " + sqlCondition + sqlOrder + ")";
17             string sql = " select top " + pageSize + sqlResult + " from FADeviceInfo  " + sqlOn + " where DeviceId not in " + sqlSon + sqlCondition + sqlOrder;
18             string sqlCount = "select count(*) from FADeviceInfo " + sqlOn + " where 1 = 1 " + sqlCondition;
19
20             DataTable dataTable = new DataTable();
21             dataTable = db.MyExecuteQuery(sql);
22             recordCount =db.GetCount(sqlCount);
23             return dataTable;
24         }

SearchForDetailSum()求得是总合计。

 public DataTable SearchForDetailSum(string DeviceIdListe, string DeviceName)
        {
            string sqlCondition = " 1=1 ";
            if (DeviceIdList != null && !DeviceIdList.Equals(""))
                sqlCondition += " and FADeviceInfo.DeviceId not in (" + DeviceIdList + ")";
            if (DeviceName != null && !DeviceName.Equals(""))
                sqlCondition += " and (FADeviceInfo.DeviceName like ‘%" + DeviceName + "%‘ or FADeviceInfo.DeviceInputCode like ‘%" + DeviceName + "%‘)";

            string sql = " select sum(OriginalValue) as SumOriginalValue,count(*) as SumCount from FADeviceInfo " +
                         " left join FADepartment on FADeviceInfo.DepartmentId=FADepartment.DepartmentId " +
                         " left join FADeviceUnit on FADeviceInfo.DeviceUnitId=FADeviceUnit.DeviceUnitId " +
                         " where " + sqlCondition;

            DataTable dataTable = new DataTable();
            dataTable = db.MyExecuteQuery(sql);
            return dataTable;
        }

五、table转Json函数:参数Footer 就是在 Controller :DeviceDetialListSearch()函数里拼接的stringBuilder,总合计和当前页合计要怎么写怎么统计,可以自己去拼接,然后传到转换函数里来。

 1 public static string DataTableToJsonByPage(DataTable dt, int total, string footer)
 2         {
 3             StringBuilder jsonBuilder = new StringBuilder();
 4             //添加表格总行数
 5             jsonBuilder.Append("{\"total\":" + total + ",\"rows\":");
 6             //添加行数据
 7             jsonBuilder.Append("[");
 8             for (int i = 0; i < dt.Rows.Count; i++)
 9             {
10                 jsonBuilder.Append("{");
11                 for (int j = 0; j < dt.Columns.Count; j++)
12                 {
13                     jsonBuilder.Append("\"");
14                     jsonBuilder.Append(dt.Columns[j].ColumnName);
15                     jsonBuilder.Append("\":\"");
16                     jsonBuilder.Append(dt.Rows[i][j].ToString());
17                     jsonBuilder.Append("\",");
18                 }
19                 jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
20                 jsonBuilder.Append("},");
21             }
22             if (dt.Rows.Count != 0)
23             {
24                 jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
25             }
26             jsonBuilder.Append("]");
27             //添加Footer
28             jsonBuilder.Append(",\"footer\":[");
29             jsonBuilder.Append(footer);
30             jsonBuilder.Append("]}");
31
32             jsonBuilder = jsonBuilder.Replace("\n", "").Replace("\r", "");
33             return jsonBuilder.ToString();
34         }

六丶看看效果图

时间: 2024-10-12 06:09:38

eayUI-datagrid 的当前页合计and总合计的相关文章

eayui datagrid模仿浏览器CTRL+F搜索定位

用于存储匹配成功的记录行数,连续点击查询按钮跳过这些行 var tempIndex=[]; 查询函数 function searchText(dg,t){ //参数:$("#datagrid"),$("#text") dg.datagrid("unselectAll"); var rows = dg.datagrid("getData").rows; var columns = dg.datagrid('getColumnFi

PLSQL_基础系列2_分组函数GROUP BY / ROLLUP / CUBE

2014-11-30 BaoXinjian 一.摘要 ROLLUP 运算符生成的结果集类似于 CUBE 运算符生成的结果集. 1. 下面是 CUBE 和 ROLLUP 之间的具体区别: CUBE 生成的结果集显示了所选列中值的所有组合的聚合. ROLLUP 生成的结果集显示了所选列中值的某一层次结构的聚合. 2. ROLLUP 优点: (1). ROLLUP 返回单个结果集,而 COMPUTE BY 返回多个结果集,而多个结果集会增加应用程序代码的复杂性. (2). ROLLUP 可以在服务器游

【案例分享】电力设备生产数据的多层分组统计报表实现

多层分组统计报表即按照不同的数据字段,形成多级分组,并分层级进行合计. 传统报表的实现方式大多基于 Table 控件,虽然可实现多个分组功能,但在报表显示方面有限制,只能呈现上下级的分组,而现代的复杂报表的需求,通常是左右级嵌套,有时甚至要求相同内容的单元格合并,使用 Table 控件,有太多的局限,有了矩表控件,通过简单的拖拽就能轻松实现多层分组报表,不管有多少个分组和分组小计都能简单解决. 下面会通过一个具体的案例,使用葡萄城报表中的矩表控件来讲解实现多层分组统计报表. (一)原始数据 (二

SQL 中GROUP BY 、ROLLUP、CUBE 关系和区别

转自:http://www.cnblogs.com/dyufei/archive/2009/11/12/2573974.html 不言自明,看SQL就完全理解了,不需要过多解释,不错,分享之: ROLLUP 运算符生成的结果集类似于 CUBE 运算符生成的结果集. 下面是 CUBE 和 ROLLUP 之间的具体区别: CUBE 生成的结果集显示了所选列中值的所有组合的聚合. ROLLUP 生成的结果集显示了所选列中值的某一层次结构的聚合. ROLLUP 优点: (1)ROLLUP 返回单个结果集

高级聚合函数rollup(),cube(),grouping sets()

rollup(),cube(),grouping sets() 上面这几个函数,是对group by分组功能做的功能扩展. a.rollup() 功能:在原结果基础上追加一行总合计记录 rollup(字段1,字段2)会追加按字段1进行的合计记录, 最后再追加一个总合计记录 select deptno,count(*) from emp group by rollup(deptno); select deptno,job,count(*) from emp group by rollup(dept

Oracle求部门员工工资占总工资的比率

--根据每个部门来统计部门工资总和 select deptid, sum(sal) 工资合计 from emp group by deptid; --根据每个部门来统计部门工资总和select deptid, 工资合计, sum(工资合计) over() as 总合计  from (select deptid, sum(sal) 工资合计 from emp group by deptid) x;       select     deptid  部门,        工资合计,        总

EasyUI Datagrid 自定义列、Foolter及单元格编辑

1:自定义列,包括 Group var head1Array = []; head1Array.push({ field: 'Id', title: 'xxxx', rowspan: 2 }); head1Array.push({ title: 'yyyy', colspan: 4 }); var head2Array = []; //.each(units,function(i,unit)//colArray.push(field:′Id′,title:unit.Name);//);head2

jQuery EasyUI 使用笔记

大家有四次抢票机会.第一次是放票时间之后的30分钟.第二次机会是开车前的15天.第三个机会是开车前的48小时.第四个机会是开车前的24小时. 1.导入js 2.datagrid重新加载 3.弹出div,打开新页面 4.实现分页 5.双击 6.嵌套子表格 导入JS,CSS    <link href="Themes/default/easyui.css" rel="stylesheet" type="text/css" />    &l

AWK文本处理增强shell功能--AWK完全手册

AWK是一种优良的文本处理工具.它不仅是 Linux 中也是任何环境中现有的功能最强大的数据处理引擎之一. 本文主要摘录池中龙写的Unixawk使用手册(第二版),对其中内容稍微改动.感谢作者的分享. 目 录 1 0作者的话 2 1awk的调用方式 3 2awk的语法 4 3awk的记录.字段与内置变量 5 4awk的内置函数 5 5在命令行使用awk 6 6awk的变量 7 7运算与判断 7 8awk的流程控制 8 8.1BEGIN和END: 8 8.2流程控制语句 9 8.2.1if...e