jqGrid表格底部汇总、合计行footerrow处理
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”);
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: vue element upload实现图片本地预览
下一篇: vue实现axios图片上传功能