1,jqGrid的自定義按鈕事件,是在左下角導航欄產生的,html
jQuery(grid_selector).jqGrid('navGrid', "#tableId",sql
{ edit: true,add: true, del: true,view: true},json
{post
//edit按鈕的一些屬性url
能夠增長一些上述四個方法的設置spa
beforeShowForm: function (e) {}debug
},{code
//add按鈕的一些屬性orm
},{...},{...}htm
//在上述四個方括號後直接調用此方法 .jqGrid('navButtonAdd',pager_selector,{ buttonicon:'icon-globe purple', caption:'history', position:'last', title:'view history', onClickButton:function(){ debugger; //得到某行id var gr = jQuery("#grid-table").jqGrid('getGridParam', 'selrow'); //得到某行數據 var grr = jQuery("#grid-table").jqGrid('getRowData',gr); if (gr != null) alert("history"+grr.name); else alert("Please Select Row"); } })
那麼自定義的history按鈕就能夠了,觸發的是查詢功能
2,彙總
方法1
jQuery(grid_selector).jqGrid({ //地址 url: "/jqGrid/select.html", //發送數據 postData: {"stock": $("#stock").val(), "name": $("#lastSales").val(), "note": $("#notes").val()}, //發送方式 mtype: "get", datatype: "json", //表格高度 height: 400, //列名 colNames: [' ', 'ID', 'Last Sales', 'Name', 'Stock', 'Ship via', 'Notes','Amt'], colModel: [ {name: 'id', index: 'id', width: 60, sorttype: "int", editable: true}, {name: 'sdate', index: 'sdate', width: 90, editable: true, sorttype: "date", unformat: pickDate}} ], //彙總 footerrow : true, userDataOnFooter : true
彙總首先要顯示出如圖中的彙總行,他是最下放突出的一行,須要在方法1裏設置兩個屬性
footerrow : true, userDataOnFooter : true,
而後想要顯示total:和總金額1060怎麼作呢
1,總金額是 後臺代碼經過sql本身計算的,而後放到userdate裏
以圖片爲例
note | amt |
note1 | 100 |
note2 | 1050 |
Totals: | 1060 |
能看到,Totals 顯示在note這一列裏,總金額顯示在amt的這一列裏。
因此後臺返回的json中,userdate這樣設置
userdata:{amt:1060,note:"Totals"}便可