jqGrid后台交互样例

时间:2022-04-27 17:01:15

schoolManageGrid = $("#jqGrid").jqGrid({
url : ctx.path+"/api/school/querySchools",
mtype:"POST",
datatype: "json",
height:contentHeight,
colNames: ['序号', '所属区域', '学校名称', '校长','联系电话','学校类型', '', '操作','state'],
colModel: [
{ name: 'schoolId', index: 'schoolId', width: 60, sorttype: "int", hidden : true },
{ name: 'addressName', index: 'addressName', width: 80 },
{ name: 'schoolName', index: 'schoolName', width: 100 },
{ name: 'contact', index: 'contact', width: 100 },
{ name: 'phone', index: 'phone', width: 100 },
{ name:'schoolTypeName', index:'schoolTypeName'},
{ name:'schoolTypeId', index:'schoolTypeId', width : 0, hidden : true},
{ name : 'act',index : 'act',width : 100,align:'center', sortable : false },
{ name : 'state',index : 'state', hidden : true}
],
gridComplete : function() {
var ids =schoolManageGrid.jqGrid('getDataIDs');
for ( var i = 0; i < ids.length; i++) {
var cl = ids[i];
var rowData = schoolManageGrid.jqGrid('getRowData',cl);
if(rowData.state==1){
enable= "<a href=\"javascript:void(0)\" style='vertical-align:middle;' onclick=\"enableClick("+rowData.state+","+rowData.schoolId+",'"+rowData.schoolName+"');\" >禁用</a>";
}else{
enable= "<a href=\"javascript:void(0)\" style='vertical-align:middle;' onclick=\"enableClick("+rowData.state+","+rowData.schoolId+",'"+rowData.schoolName+"');\" >启用</a>";
}

eid = "<div class='edit' title='编辑' style='vertical-align:middle;' onclick=\"editUser("+ rowData.schoolId+",'"+rowData.schoolName+"','"+rowData.contact+"','"+rowData.phone+"','"+rowData.schoolTypeId+"');\" ></div>";
schoolManageGrid.jqGrid('setRowData', ids[i],
{
act : enable +"<span style='width:40px;display: inline-block;'></span>" + eid
});
}

},
multiselect:false,
autowidth: true,//自适应宽度
shrinkToFit: true,
rowNum : 20,
rowList: [10, 20, 50],
rownumbers:true,//添加左侧行号
altRows:true,//设置为交替行表格,默认为false
pager : '#jqGridPager',
viewrecords: true, //是否在浏览导航栏显示记录总数
hidegrid: false,
jsonReader: {
   root: "data.data",// Json数据
records: "data.totalRows",// 总记录数
total:"data.totalPages",
page:"data.page",
repeatitems: false
   }
});