jqGrid表格底部匯總、合計(jì)行footerrow處理
jqGrid提供了表格底部匯總、合計(jì)行功能,我們先看下user-guide關(guān)于jqGrid合計(jì)行都有哪些說(shuō)明?然后再看個(gè)DEMO,看看jqGrid表格底部匯總、合計(jì)行到底如何實(shí)現(xiàn)。
1、user-guide關(guān)于jqGrid合計(jì)行的說(shuō)明
1)表格配置:footerrow, boolean, 默認(rèn)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
表格是否顯示底部合計(jì)行。
2)表格配置:userDataOnFooter,boolean,默認(rèn)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.
如果設(shè)為true,則userData可以用來(lái)填充匯總行。
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、一個(gè)DEMO,如何利用gridComplete事件進(jìn)行表格數(shù)據(jù)匯總并賦值給合計(jì)行
1)案例截圖
2)html代碼
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>jggrid底部匯總行</title> <link rel="stylesheet" rel="external nofollow" /> <link rel="stylesheet" rel="external nofollow" /> <link rel="stylesheet" rel="external nofollow" /> <link rel="stylesheet" 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: "零件號(hào)", 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: "訂單號(hào)", name: "bill_no", width: 120}, {label: "訂單數(shù)量", 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:"--合計(jì)--",goods_count:total_count}); } }); getBills(); }); </script> </body> </html>
3)代碼說(shuō)明:
- 表格構(gòu)建時(shí),設(shè)置:footerrow: true
- gridComplete(jqGridGridComplete)事件處理,進(jìn)行數(shù)據(jù)匯總并賦值給合計(jì)行
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)獲取匯總行數(shù)據(jù)
var row = $("#orders").jqGrid(“footerData”, “get”);
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JQuery實(shí)現(xiàn)用戶名無(wú)刷新驗(yàn)證的小例子
本人也是JQuery初學(xué)者,寫(xiě)了個(gè)用戶名無(wú)刷新驗(yàn)證的簡(jiǎn)單例子,拿來(lái)分享,共同學(xué)習(xí)一下吧。2013-03-03jQuery插件fullPage.js實(shí)現(xiàn)全屏滾動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了jQuery全屏滾動(dòng)插件fullPage.js的使用方法,可制作全屏滾動(dòng)網(wǎng)頁(yè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12jquery實(shí)現(xiàn)界面點(diǎn)擊按鈕彈出懸浮框
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)界面點(diǎn)擊按鈕彈出懸浮框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03jQuery實(shí)現(xiàn)美觀的多級(jí)動(dòng)畫(huà)效果菜單代碼
這篇文章主要介紹了jQuery實(shí)現(xiàn)多級(jí)動(dòng)畫(huà)效果菜單代碼,涉及jquery針對(duì)頁(yè)面元素的遍歷及事件綁定操作頁(yè)面元素樣式變換的技巧,界面美觀實(shí)用,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09EasyUi 打開(kāi)對(duì)話框后控件賦值及賦值后不顯示的問(wèn)題解決辦法
這篇文章主要介紹了easyUi 打開(kāi)對(duì)話框后控件賦值,以及賦值后不顯示的問(wèn)題解決辦法,解決方法非常簡(jiǎn)單,只需要將賦值語(yǔ)句修改下就好,下面小編給大家簡(jiǎn)單介紹下,需要的朋友參考下2017-01-01jquery中郵箱地址 URL網(wǎng)站地址正則驗(yàn)證實(shí)例代碼
QQ網(wǎng)站有一個(gè)網(wǎng)站舉報(bào)的功能,看了一些js代碼覺(jué)得寫(xiě)得很不錯(cuò),我就拿下來(lái)了,下面是一個(gè)email驗(yàn)證與url網(wǎng)址驗(yàn)證js代碼,分享給大家2013-09-09jQuery插件HighCharts繪制2D餅圖效果示例【附demo源碼下載】
這篇文章主要介紹了jQuery插件HighCharts繪制2D餅圖效果,結(jié)合完整實(shí)例形式分析了jQuery使用HighCharts插件繪制餅圖效果的操作步驟與相關(guān)實(shí)現(xiàn)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03