在jquery框架中,常常会利用到jqGrid建立表格,这也是比较常见的形式:
1、加载相应的jqGrid文件包;
2、列表中显示的常规属性必须与model属性保持一致:
colNames:['Id','角色名称','允许所有监测器组','允许所有策略组', '更新者','更新时间','操作'],
colModel:[{
align : 'center',
key:true,
name:'id',//
index:'id',
width:500,
hidden:true,
},{
align : 'center',
name : 'roleName',//
index : 'roleName',
width : 500,
hidden:false,
},{
align : 'center',
name : 'isAllNetPort',
index : 'isAllNetPort',
width : 500,
hidden:false,
},{
align : 'center',
name : 'isAllStraGrp',
index : 'isAllStraGrp',
width : 500,
hidden:false,
},{
align : 'center',
name : 'updater',//
index : 'updater',
width : 500,
hidden:false,
},{
align : 'center',
name : 'updateTime',//
index : 'updateTime',
width : 500,
hidden:false,
},{
align : 'center',
name:'操作',
index:'operation',
width:1500,
resizable:false,
}],
rowNum:20,
rowList:[20,30,40],
pager: '#'+pagerId,
sortname: 'id',
scroll:false,
autowidth : true,
hidegrid: false,
altRows : false,
viewrecords : true,
multiselect : true,
sortorder : 'desc',
height:'auto',
caption : "<span class='glyphicon glyphicon-th-list'></span>角色管理列表",
});
//属性保持一致性。
3、外键的理解:一般在领域模型model中,非常规类型的属性,即是对象类型的属性,如果在列表中这些属性是不被直接显示的,则做成外键过滤掉,当然列表中某列显示的是引用的是数据库中别的表的属性,需要添加外键显示:
try
{
JqGridResponseBean jqGridObject = new JqGridResponseBean();
JsonConfig cfg = JsonFilter.getFilter(new String[] { "rolemenu",
"adminrole", "roleMonitorGroup", "rolePolicyGroup","roleEventFilter","roleoperation"});// 过滤外键
JSONObject jsonObject = JSONObject.fromObject(jqGridObject, cfg);
writeRepnonseJson(jsonObject, response);
}
catch (Exception e)
{
this.logger.error(e.getMessage(), e);
writeRepnonse("Grid查找响应记录失败.", response);
}