123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /*
- * 返回json格式中 最好默认带有ID列
- 默认显示 20列
- * 列表id = 'gridTable'
- 列表url = 'Handler.ashx?action=page'
- 列表datatype = 'json'
- 列表colNames = ['ID', '名称', '性别', '手机', '邮箱']
- 列表colModel = 。。。
- 列表标题 caption = '用户列表'
- 列表修改URL editurl = 'Handler.ashx?action=oper'
- 列表默认排序 sortname = 'ID';
- 页码ID gridPagerID = 'gridPager'
- */
- //最后选中的行
- var lastsel;
- function myJqGrid(id, url, datatype, colNames, colModel, caption,
- sortname, gridPagerID, sortorder, height, width, multiselect, rownumbers) {
- var myGrid = $('#' + id);
- myGrid.jqGrid( {
- url : url,
- datastr : 'data.json',
- datatype : datatype,
- pager : gridPagerID,
- height : height,
- width : width,
- rowNum : 25,
- rowList : [ 10, 20, 50 ],
- colNames : colNames,
- colModel : colModel,
- jsonReader : {
- repeatitems : false,
- root : function(obj) {
- return obj.rows;
- },
- page : function(obj) {
- return obj.pageindex;
- },
- total : function(obj) {
- return obj.pagecount;
- },
- records : function(obj) {
- return obj.total;
- }
- },
- prmNames : {
- page : 'page',
- rows : 'pageSize',
- sort : 'sortorder',
- order : 'sortname'
- },
- hidegrid : false,
- rownumbers : rownumbers,
- multiselect : multiselect,
- loadonce : false,
- sortname : sortname,
- sortorder : sortorder,
- viewrecords : true,
- caption : caption,
- altRows : true,
- onSelectRow : function(id) {
- if (id && id !== lastsel) {
- myGrid.jqGrid('restoreRow', lastsel);
- lastsel = myGrid.jqGrid('getRowData', id)[sortname];
- }
- },
- onCellSelect : function(rowid, index, contents, event) {
- if (index != 1) {
- lastsel = myGrid.jqGrid('getRowData', rowid);
- $("#f1").attr("action",
- "showInfoAction.action?id=" + lastsel["id"]).submit();
- }
- }
- });
- }
|