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)案例截图

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”);

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

jqGrid表格底部汇总、合计行footerrow处理的更多相关文章

  1. react中useState使用:如何实现在当前表格直接更改数据

    这篇文章主要介绍了react中useState的使用:如何实现在当前表格直接更改数据,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  2. Pandas如何将表格的前几行生成html实战案例

    这篇文章主要介绍了Pandas如何将表格的前几行生成html实战案例,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下

  3. Ant Design Vue 修改表格头部样式的详细代码

    这篇文章主要介绍了Ant Design Vue 修改表格头部样式,首先用到的是customHeaderRow这个API,类型是一个函数,本文通过完整代码给大家详细讲解,需要的朋友可以参考下

  4. JavaScript实现动态加载删除表格

    这篇文章主要为大家详细介绍了JavaScript实现动态加载删除表格,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  5. element-table如何实现自定义表格排序

    这篇文章主要介绍了element-table如何实现自定义表格排序,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  6. jQuery实现可以编辑的表格实例详解【附demo源码下载】

    这篇文章主要介绍了jQuery实现可以编辑的表格,涉及jQuery响应鼠标事件动态操作页面元素的相关技巧,需要的朋友可以参考下

  7. Python使用pandas将表格数据进行处理

    这篇文章主要介绍了Python使用pandas将表格数据进行处理,文章围绕主题展开详细的内容介绍,具有一定的参考价值,感兴趣的小伙伴可以参考一下

  8. js动态生成表格(节点操作)

    这篇文章主要为大家详细介绍了js动态生成表格,进行节点操作,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  9. iOS实现可以纵向横向滑动的表格实例代码

    这篇文章主要给大家介绍了利用iOS实现可以纵向横向滑动的表格的相关资料,文中给出了详细的实现方法示例代码,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧。

  10. js实现添加删除表格操作

    这篇文章主要为大家详细介绍了js实现添加删除表格操作,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

随机推荐

  1. js中‘!.’是什么意思

  2. Vue如何指定不编译的文件夹和favicon.ico

    这篇文章主要介绍了Vue如何指定不编译的文件夹和favicon.ico,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  3. 基于JavaScript编写一个图片转PDF转换器

    本文为大家介绍了一个简单的 JavaScript 项目,可以将图片转换为 PDF 文件。你可以从本地选择任何一张图片,只需点击一下即可将其转换为 PDF 文件,感兴趣的可以动手尝试一下

  4. jquery点赞功能实现代码 点个赞吧!

    点赞功能很多地方都会出现,如何实现爱心点赞功能,这篇文章主要为大家详细介绍了jquery点赞功能实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  5. AngularJs上传前预览图片的实例代码

    使用AngularJs进行开发,在项目中,经常会遇到上传图片后,需在一旁预览图片内容,怎么实现这样的功能呢?今天小编给大家分享AugularJs上传前预览图片的实现代码,需要的朋友参考下吧

  6. JavaScript面向对象编程入门教程

    这篇文章主要介绍了JavaScript面向对象编程的相关概念,例如类、对象、属性、方法等面向对象的术语,并以实例讲解各种术语的使用,非常好的一篇面向对象入门教程,其它语言也可以参考哦

  7. jQuery中的通配符选择器使用总结

    通配符在控制input标签时相当好用,这里简单进行了jQuery中的通配符选择器使用总结,需要的朋友可以参考下

  8. javascript 动态调整图片尺寸实现代码

    在自己的网站上更新文章时一个比较常见的问题是:文章插图太宽,使整个网页都变形了。如果对每个插图都先进行缩放再插入的话,太麻烦了。

  9. jquery ajaxfileupload异步上传插件

    这篇文章主要为大家详细介绍了jquery ajaxfileupload异步上传插件,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  10. React学习之受控组件与数据共享实例分析

    这篇文章主要介绍了React学习之受控组件与数据共享,结合实例形式分析了React受控组件与组件间数据共享相关原理与使用技巧,需要的朋友可以参考下

返回
顶部