var ajsGridAction = { gridId:"gridId", //表格ID toListUrl:"../ajsGrid/toList", //列表页Url findUrl:"../ajsGrid/listAjax", //查询列表Url viewUrl:"../ajsGrid/viewAjax", //查看对象Url addUrl:"../ajsGrid/addAjax", //添加Url saveUrl:"../ajsGrid/saveAjax",//保存Url updateUrl:"../ajsGrid/updateAjax", //修改Url deleteUrl:"../ajsGrid/delete", //删除Url ids:null, id:null, //初始化 init:function(){ ajsGridAction.initGrid(); //初始化表格 }, //是否是实体对象 isEntity:function(obj){ if(null!=obj && 0<obj.length){ return true; }else{ return false; } }, //查看 viewEvent:function(){ var url = ajsGridAction.viewUrl; var data = "id="+this.id; $.ajax({ type: 'POST',url: url,timeout:5000,cache: false,async: false, dataType:'json', data: data, success: function(data){ if(null!= data){ window.alert(data.length); }else{ window.alert("没有返回消息!"); } }, error:function(XMLHttpRequest,errorClass,errorObj){ window.alert("操作失败,请稍后再试!"); } }); }, //保存 saveEvent:function(){ var url = ajsGridAction.viewUrl; var data = "id="+this.id; }, //修改 updateEvent:function(){ var url = ajsGridAction.updateUrl; var data = ""; }, //删除 deleteEvent:function(){ var url = ajsGridAction.deleteUrl; var data = "ids="+this.ids; }, //刷新 refreshEvent:function(){ }, //初始化表格 initGrid:function(){ var url = ajsGridAction.findUrl; $("#list").jqGrid({ url: url, //从后台读取列表的URL地址 datatype: "json", colModel: [ {name: "id", label: "ID"}, {name: "name", label: "名称"}, {name: "number", label: "编码"}, {name: "status", label: "状态", formatter:"dictable", formatoptions:{0:"禁用", 1:"启用", _:"未知"}}, {name: "lastUpdateDate", label: "最后修改日期"}, ], rowList: [10, 20, 30], //可选的每页显示记录数 //+++ 以上两项可以不写,缺省值为rowNum:10, rowList:[10,20,30,40] +++ pager: "#pager", //关键配置,标示要使用分页 sortname: "name", //初始排序字段,应根据每个列表改变 viewrecords: true, sortorder: "asc", //初始排序方向,asc代表正序,desc代表逆序 height: 300, //自动延展高度 autowidth: true, //自动延展宽度 multiselect:true, //显示复选框 //localReader 本地加载 jsonReader: { root: "data", //务必设置,不需要修改 repeatitems: false, //务必设置 id: "id" //返回的列表数据中代表一条数据唯一标示的属性名,应根据每个列表改变 }, //单行选中处理 (参数:id,是否选中) onSelectRow : function(id,selected){ if (selected){ ajsGridAction.id = id; window.alert(ajsGridAction.id); }else{ ajsGridAction.id = null; window.alert(ajsGridAction.id); } }, //全部选中处理 (参数:id集合,是否选中) onSelectAll:function(idList,selected){ //如果全部选中 if(selected){ ajsGridAction.ids = idList.toString(); window.alert(ajsGridAction.ids); }else{ ajsGridAction.ids = null; window.alert(ajsGridAction.ids); } } }); } };
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)