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 相关文章推荐
JS按位非(~)运算符与~~运算符的理解分析
Jul 31 Javascript
JS常用函数使用指南
Nov 23 Javascript
javascript中的遍历for in 以及with的用法
Dec 22 Javascript
JS判断网页广告是否被浏览器拦截过滤的代码
Apr 05 Javascript
JavaScript实现节点的删除与序号重建实例
Aug 05 Javascript
浏览器复制插件zeroclipboard使用指南
Mar 26 Javascript
Javascript 基础---Ajax入门必看
Jul 06 Javascript
通过Ajax使用FormData对象无刷新上传文件方法
Dec 08 Javascript
vue.js从安装到搭建过程详解
Mar 17 Javascript
jQuery动态添加.active 实现导航效果代码思路详解
Aug 29 jQuery
JS window对象简单操作完整示例
Jan 14 Javascript
javascript实现前端成语点击验证
Jun 24 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 文件上传实例代码
2012/04/19 PHP
php去掉URL网址中带有PHPSESSID的配置方法
2014/07/08 PHP
php 删除一维数组中某一个值元素的操作方法
2018/02/01 PHP
jquery的Theme和Theme Switcher使用小结
2010/09/08 Javascript
jQuery ul标签下拉菜单演示代码
2010/12/11 Javascript
优化innerHTML操作(提高代码执行效率)
2011/08/20 Javascript
基于jquery实现的省市区级联无ajax
2013/09/24 Javascript
jquery获取复选框被选中的值
2014/04/10 Javascript
javascript中Function类型详解
2015/04/28 Javascript
avalonjs制作响应式瀑布流特效
2015/05/06 Javascript
详谈表单格式化插件jquery.serializeJSON
2017/06/23 jQuery
利用jsonp与代理服务器方案解决跨域问题
2017/09/14 Javascript
vue技术分享之你可能不知道的7个秘密
2018/04/09 Javascript
webstrom Debug 调试vue项目的方法步骤
2018/07/17 Javascript
Angularjs 根据一个select的值去设置另一个select的值方法
2018/08/13 Javascript
Vue-router 切换组件页面时进入进出动画方法
2018/09/01 Javascript
Element ui 下拉多选时新增一个选择所有的选项
2019/08/21 Javascript
axios如何利用promise无痛刷新token的实现方法
2019/08/27 Javascript
layui 关闭open弹出框 刷新table表格页面的方法
2019/09/16 Javascript
详解vue-cli项目在IE浏览器打开报错解决方法
2020/12/10 Vue.js
利用Python爬虫给孩子起个好名字
2017/02/14 Python
python文件操作之批量修改文件后缀名的方法
2018/08/10 Python
使用Python向DataFrame中指定位置添加一列或多列的方法
2019/01/29 Python
Python一个简单的通信程序(客户端 服务器)
2019/03/06 Python
python定时按日期备份MySQL数据并压缩
2019/04/19 Python
pytorch常见的Tensor类型详解
2020/01/15 Python
Python3读写Excel文件(使用xlrd,xlsxwriter,openpyxl3种方式读写实例与优劣)
2020/02/13 Python
python字符串判断密码强弱
2020/03/18 Python
维多利亚的秘密阿联酋官网:Victoria’s Secret阿联酋
2019/12/07 全球购物
小学敬老月活动方案
2014/02/11 职场文书
会计专业个人自我鉴定
2014/03/21 职场文书
产品质量承诺书
2014/03/27 职场文书
军训口号
2014/06/13 职场文书
2014年房产经纪人工作总结
2014/12/08 职场文书
2015年全国爱眼日活动方案
2015/05/05 职场文书
2016年党员公开承诺书格式范文
2016/03/24 职场文书