json: var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = new
{
city = "bj",
district = "bj",
telphone = "010-8888888",
createTime = "2011-1-1",
address = "everywhere in beijing",
name = "KFC"
}
};
Controller:public JsonResult GetJsonData(string sidx, string sord, int page, int rows)
{
string json = Request["sp"] == null ? "" : Request["sp"].ToString();
JqGridModel jqGridModel = new JqGridModel();
Object obj = jqGridModel.GridData(sidx, sord, page, rows);
return Json(obj, JsonRequestBehavior.AllowGet);
}
js:jQuery().ready(
function () {
jQuery("#list1").jqGrid(
{
url: '/Home/GetJsonData',
datatype: "json",
mtype:"GET",
colNames: ['姓名', '地区', '城市', '地址', '电话', '创建时间'],
colModel: [
{ name: 'name', index: 'name', width: 75 },
{ name: 'district', index: 'district', width: 90 },
{ name: 'city', index: 'city', width: 100 },
{ name: 'rows.address', index: 'address', width: 160 },
{ name: 'telphone', index: 'telphone', width: 80 },
{ name: 'createTime', index: 'createTime', width: 150, sortable: true }
],
rowNum: 10,
autowidth: true,
height: 'auto',
pager: jQuery('#pager1'),
sortname: 'name',
viewrecords: true,
sortorder: "desc",
caption: "商户列表",
jsonReader: {
total: "total",
page: "page",
records: "records",
//root: function (obj) {
// var jsondata = eval('(' + obj + ')');
// return jsondata.rows;
//},
root:"rows",
repeatitems: false,
},
multiselect: true
});
});