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 相关文章推荐
JavaScript 拾碎[三] 使用className属性
Oct 16 Javascript
JQuery 返回布尔值Is()条件判断方法代码
May 14 Javascript
JS、CSS加载中的小问题探讨
Nov 26 Javascript
基于JavaScript代码实现兼容各浏览器的设为首页和加入收藏
Jan 07 Javascript
jQuery实现多级联动下拉列表查询框
Jan 18 Javascript
JavaScript兼容浏览器FF/IE技巧
Aug 14 Javascript
纯js实现倒计时功能
Jan 06 Javascript
你点的 ES6一些小技巧,请查收
Apr 25 Javascript
详解vue中this.$emit()的返回值是什么
Apr 07 Javascript
eslint 的三大通用规则详解
May 16 Javascript
基于vue实现圆形菜单栏组件
Jul 05 Javascript
解决layui动态添加的元素click等事件触发不了的问题
Sep 20 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开发框架的对比
2013/07/05 PHP
php日历制作代码分享
2014/01/20 PHP
PHP文件上传问题汇总(文件大小检测、大文件上传处理)
2015/12/24 PHP
PHP中使用OpenSSL生成证书及加密解密
2017/02/05 PHP
Yii2框架控制器、路由、Url生成操作示例
2019/05/27 PHP
HTML页面弹出居中可拖拽的自定义窗口层
2014/05/07 Javascript
JavaScript获取网页中第一个链接ID的方法
2015/04/03 Javascript
jQuery基于图层模仿五星星评价功能的方法
2015/05/07 Javascript
jquery获取当前元素索引值用法实例
2015/06/10 Javascript
jQuery原生的动画效果
2015/07/10 Javascript
jquery validate.js表单验证入门实例(附源码)
2015/11/10 Javascript
jQuery插件实现适用于移动端的地址选择器
2016/02/18 Javascript
全面接触神奇的Bootstrap导航条实战篇
2016/08/01 Javascript
Vue父子模版传值及组件传值的三种方法
2017/11/27 Javascript
基于dataset的使用和图片延时加载的实现方法
2017/12/11 Javascript
JavaScript对象的浅拷贝与深拷贝实例分析
2018/07/25 Javascript
详解vue移动端项目代码拆分记录
2019/03/15 Javascript
一文了解Vue中的nextTick
2019/05/06 Javascript
Vue内部渲染视图的方法
2019/09/02 Javascript
python进阶教程之模块(module)介绍
2014/08/30 Python
Python循环语句中else的用法总结
2016/09/11 Python
Python中函数及默认参数的定义与调用操作实例分析
2017/07/25 Python
Python爬取附近餐馆信息代码示例
2017/12/09 Python
Python FTP两个文件夹间的同步实例代码
2018/05/25 Python
对numpy中的数组条件筛选功能详解
2018/07/02 Python
python for循环输入一个矩阵的实例
2018/11/14 Python
详解opencv中画圆circle函数和椭圆ellipse函数
2019/12/27 Python
日本面向世界,国际级的免税在线购物商城:DOKODEMO
2017/02/01 全球购物
Shell如何接收变量输入
2016/08/06 面试题
总经理办公室主任岗位职责
2013/11/12 职场文书
行政专员岗位职责范本
2014/08/26 职场文书
超市开业庆典活动策划方案
2014/09/15 职场文书
先进个人推荐材料
2014/12/29 职场文书
工作违纪检讨书范文
2015/01/26 职场文书
2015年春训学习心得体会范文
2015/03/09 职场文书
vue首次渲染全过程
2021/04/21 Vue.js