日期:2014-05-20 浏览次数:20856 次
<script type="text/javascript">
$(document).ready(function(){
var url ='grid!execute.action';
$("#grid").jqGrid({
url:url,
datatype : 'json',
colNames:['编号','姓名','密码','年龄','地址'],
colModel:[
{name:'id',index:'id',width:90,sorttype:"int"},
{name:'username',index:'username',width:110},
{name:'password',index:'password',width:80},
{name:'age',index:'age',width:80,sorttype:"int"},
{name:'address',index:'address',width:90}
],
rowNum:10,
rowList:[10,20,30],
pager:"pjmap",
multiselect:false,
sortname:'id',
viewrecords:true,
sortorder:"desc",
jsonReader:{
root:"dataRows",
page: "page",
total: "total",
repeatitems:false
},
caption:"jqGrid test",
height:220
});
});
</script>
</head>
<body>
<table id="grid"></table>
<div id="pjmap"></div>
</body>
public class GridAction extends ActionSupport {
	private static final long serialVersionUID=1L;
	private int page = 1;
	private int total = 3;
	private int rows = 12;
	private List dataRows = new ArrayList();
	@Override
	public String execute() throws Exception {
		System.out.println("已进入action");
		JSONArray t_list = new JSONArray();
		for(int i=0;i<3;i++){
			JSONObject student = new JSONObject();
			student.put("id",i);
			student.put("username","徐华星");
			student.put("password","123");
			student.put("age",20);
			student.put("address","USA");
			dataRows.add(i,student);
		}
		System.out.println(dataRows.toString());
		return SUCCESS;
	}