jqGrid表格底部汇总、合计行footerrow处理


Posted in Javascript onAugust 21, 2019

jqGrid提供了表格底部汇总、合计行功能,我们先看下user-guide关于jqGrid合计行都有哪些说明?然后再看个DEMO,看看jqGrid表格底部汇总、合计行到底如何实现。

1、user-guide关于jqGrid合计行的说明

1)表格配置:footerrow, boolean, 默认false

If set to true this will place a footer table with one row below the gird records and above the pager. The number of columns equal those specified in colModel
表格是否显示底部合计行。

2)表格配置:userDataOnFooter,boolean,默认false

When set to true we directly place the user data array userData in the footer if the footerrow parameter is set to true. The rules are as follows: If the userData array contains a name which matches any name defined in colModel, then the value is placed in that column. If there are no such values nothing is placed. Note that if this option is used we use the current formatter options (if available) for that column. See footerData method.
如果设为true,则userData可以用来填充汇总行。

3)汇总行赋值:footerData([string action], [object data], [boolean format])

This method gets or sets data on the grid footer row. When set data in the footer row, the data is formatted according to the formatter (if defined) in coModel. The method can be used if footerrow option is set to true.
parameters
string action - can be ‘get' or ‘set'. The default is get. ‘get' returns an object of type name:value, where the name is a name from colModel. This will return data from the footer. The other two options have no effect in this case. ‘set' takes a data object and places the values in the footer The value is formatted according to the definition of the formatter in colModel - see next parameter. The object should be in name:value pair, where the name is the name from colModel
object data - data to be set in the footer in name:value pair, where the name should correspond to the name of colModel in order to be set in the appropriate cell.
boolean format - default is true. This instruct the method to use the formatter (if set in colModel) when new values are set. A value of false will disable the using of formatter

2、一个DEMO,如何利用gridComplete事件进行表格数据汇总并赋值给合计行

1)案例截图

jqGrid表格底部汇总、合计行footerrow处理

2)html代码

<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8" />
 <title>jggrid底部汇总行</title>
 
 <link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow" />
 <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="external nofollow" />
 <link rel="stylesheet" href="https://cdn.bootcss.com/jqueryui/1.11.0/jquery-ui.min.css" rel="external nofollow" />
 <link rel="stylesheet" href="https://js.cybozu.cn/jqgrid/v5.3.1/css/ui.jqgrid.css" rel="external nofollow" />
 <script src="https://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
 <script src="https://js.cybozu.cn/jqgrid/v5.3.1/js/jquery.jqGrid.min.js"></script>
 <script src="https://js.cybozu.cn/jqgrid/v5.3.1/js/i18n/grid.locale-en.js"></script>
</head>
<body>
<div class="page-content container">
 <div class="page-body"> <!-- page-body -->
 <div class="panel panel-default" id="panel-orders">
  <table id="orders"></table>
 </div>
 </div>
</div>
<script type="text/javascript">
 var data = [];
 function getBills() {
 var rowCount = 10;
 for (var i = 0; i < rowCount; i ++) {
  data.push({
  sid: i,
  goods_no: i + 1,
  goods_name: '零件名称' + rowCount + i,
  car_type_name: '车型' + rowCount + i,
  package_name: '包装器具' + rowCount + i,
  unit_name: '件',
  snp: 0.89,
  bill_amount: rowCount + i,
  goods_count: rowCount + i,
  bill_no: 'BN0000000' + i,
  qrcode: '1000000000' + i,
  barcode: '1000000000' + i,
  })
 }
 $("#orders").jqGrid("clearGridData").jqGrid('setGridParam',{data: data || []}).trigger('reloadGrid');
 }
 $(function() {
 $("#orders").jqGrid({
  colModel: [
  {label: "零件号", name: "goods_no", width: 60},
  {label: "零件名称", name: "goods_name", search:false, width: 180},
  {label: "车型", name: "car_type_name", width: 70},
  {label: "包装器具", name: "package_name", width: 70},
  {label: "单位", name: "unit_name", width: 40},
  {label: "订单号", name: "bill_no", width: 120},
  {label: "订单数量", name: "goods_count", width: 80},
  ],
  datatype: 'local',
  rownumbers: true,
  height: 300,
  rowNum: 1000,
  footerrow: true,
  gridComplete: function() {
  var rows = $("#orders").jqGrid("getRowData"), total_count = 0;
     for(var i = 0, l = rows.length; i<l; i++) {
      total_count += (rows[i].goods_count - 0);
     }
     $("#orders").jqGrid("footerData", "set", {goods_name:"--合计--",goods_count:total_count});
     }
 });
 getBills();
 });
</script>
</body>
</html>

3)代码说明:

  • 表格构建时,设置:footerrow: true
  • gridComplete(jqGridGridComplete)事件处理,进行数据汇总并赋值给合计行

gridComplete fires after all the data is loaded into the grid and all other processes are complete. Also the event fires independent from the datatype parameter and after sorting paging and etc. Does not fire if datatype is a defined as function.

4)获取汇总行数据

var row = $("#orders").jqGrid(“footerData”, “get”);

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
学习YUI.Ext 第四天--对话框Dialog的使用
Mar 10 Javascript
JS截取字符串常用方法整理及使用示例
Oct 18 Javascript
JavaScript+CSS控制打印格式示例介绍
Jan 07 Javascript
jQuery中get()方法用法实例
Dec 27 Javascript
javascript中typeof操作符和constucor属性检测
Feb 26 Javascript
jquery插件uploadify实现带进度条的文件批量上传
Dec 13 Javascript
在页面中输出当前客户端时间javascript实例代码
Mar 02 Javascript
Node.js环境下编写爬虫爬取维基百科内容的实例分享
Jun 12 Javascript
Angular的Bootstrap(引导)和Compiler(编译)机制
Jun 20 Javascript
浅谈JS中String()与 .toString()的区别
Oct 20 Javascript
Vue2.0用 watch 观察 prop 变化(不触发)
Sep 08 Javascript
JavaScript实现单例模式实例分享
Dec 22 Javascript
Vue仿微信app页面跳转动画效果
Aug 21 #Javascript
Angular 中使用 FineReport不显示报表直接打印预览
Aug 21 #Javascript
深入理解Vue keep-alive及实践总结
Aug 21 #Javascript
vue element 生成无线级左侧菜单的实现代码
Aug 21 #Javascript
微信小程序仿今日头条导航栏滚动解析
Aug 20 #Javascript
Vue中axios的封装(报错、鉴权、跳转、拦截、提示)
Aug 20 #Javascript
Vue formData实现图片上传
Aug 20 #Javascript
You might like
php数组函数序列之next() - 移动数组内部指针到下一个元素的位置,并返回该元素值
2011/10/31 PHP
php实现上传图片生成缩略图示例
2014/04/13 PHP
php实现utf-8转unicode函数分享
2015/01/06 PHP
php使用memcoder将视频转成mp4格式的方法
2015/03/12 PHP
功能强大的PHP图片处理类(水印、透明度、旋转)
2015/10/21 PHP
给WordPress的编辑后台添加提示框的代码实例分享
2015/12/25 PHP
WordPress主题制作中自定义头部的相关PHP函数解析
2016/01/08 PHP
简单实用的PHP文本缓存类实例
2019/03/22 PHP
JavaScript学习点滴 call、apply的区别
2010/10/22 Javascript
页面回到顶部的三种实现(锚标记,js)
2012/10/01 Javascript
js实现二代身份证号码验证详解
2014/11/20 Javascript
jQuery实现鼠标滑过点击事件音效试听
2015/08/31 Javascript
AngularJS中的包含详细介绍及实现示例
2016/07/28 Javascript
jQuery弹出遮罩层效果完整示例
2016/09/13 Javascript
node中使用es5/6以及支持性与性能对比
2017/08/11 Javascript
webpack写jquery插件的环境配置
2017/12/21 jQuery
如何实现一个webpack模块解析器
2018/10/24 Javascript
Angular刷新当前页面的实现方法
2018/11/21 Javascript
使用Vue开发自己的Chrome扩展程序过程详解
2019/06/21 Javascript
Vue + Element UI图片上传控件使用详解
2019/08/20 Javascript
使用Python从有道词典网页获取单词翻译
2016/07/03 Python
Python数据结构之栈、队列及二叉树定义与用法浅析
2018/12/27 Python
解决yum对python依赖版本问题
2019/07/05 Python
django admin后管定制-显示字段的实例
2020/03/11 Python
解决django接口无法通过ip进行访问的问题
2020/03/27 Python
python 实现百度网盘非会员上传超过500个文件的方法
2021/01/07 Python
matplotlib bar()实现多组数据并列柱状图通用简便创建方法
2021/02/24 Python
html5的canvas实现3d雪花飘舞效果
2013/12/27 HTML / CSS
皇马官方商城:Real Madrid Store
2016/09/02 全球购物
泰国折扣酒店预订:Hotels2Thailand
2018/03/20 全球购物
物业保安员岗位职责
2014/03/14 职场文书
外语系毕业生求职自荐信
2014/04/12 职场文书
“5.12”护士节主持词
2015/07/04 职场文书
详解PHP用mb_string处理windows中文字符
2021/05/26 PHP
python和Appium的移动端多设备自动化测试框架
2022/04/26 Python
Python可视化神器pyecharts之绘制地理图表练习
2022/07/07 Python