62,046
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link type="text/css" href="css/jquery-ui.min.css" rel="stylesheet" />
<link type="text/css" href="plugins/jquery.jqGrid-4.4.3/css/ui.jqgrid.css" rel="stylesheet" />
<script type="text/javascript" src="plugins/jquery.jqGrid-4.4.3/js/jquery-1.7.2.min.js"></script>
<!--<script type="text/javascript" src="plugins/jquery.jqGrid-4.4.3/js/jquery.jqGrid.min.js"></script>-->
<script type="text/javascript" src="plugins/jquery.jqGrid-4.4.3/js/jquery.jqGrid.src.js"></script>
<script type="text/javascript" src="plugins/jquery.jqGrid-4.4.3/js/i18n/grid.locale-cn.js"></script>
<script type="text/javascript">
$(function () {
$("#jqGrid").jqGrid({
url: "handler/msgSettings.ashx",
datatype: "json",
mtype: "GET",
colNames: ['GprsID', 'DeviceName', 'DeviceType'],
colModel: [
{ name: 'GprsID', width: 20 },
{ name: 'DeviceName', width: 80 },
{ name: 'DeviceType', width: 80 }
],
viewrecords: true, // show the current page, data rang and total records on the toolbar
width: 780,
height: 700,
rowNum: 10,
loadonce: true, // this is just for the demo
sortname: '_id',
sortorder: 'desc',
caption: "设备列表",
pager: "#jqGridPager",
jsonReader: { // 用于设置如何解析从Server端发回来的json数据
root:"grids",
page: "page", // json中代表当前页码的数据
total: "total", // json中代表页码总数的数据
records: "records", // json中代表数据行总数的数据
repeatitems: false//注意此时的json结构
},
prmNames: { // 默认设置——如何将Grid所需要的参数传给Server
page:"page", // 表示请求页码的参数名称
rows:"rows", // 表示请求行数的参数名称
sort: "sidx", // 表示用于排序的列名的参数名称
order: "sord", // 表示采用的排序方式的参数名称
search:"_search", // 表示是否是搜索请求的参数名称
nd:"nd", // 表示已经发送请求的次数的参数名称
id:"id", // 表示当在编辑数据模块中发送数据时,使用的id的名称
oper:"oper", // operation参数名称(我暂时还没用到)
editoper:"edit", // 当在edit模式中提交数据时,操作的名称
addoper:"add", // 当在add模式中提交数据时,操作的名称
deloper:"del", // 当在delete模式中提交数据时,操作的名称
subgridid:"id", // 当点击以载入数据到子表时,传递的数据名称
npage: null,
totalrows:"totalrows" // 表示需从Server得到总共多少行数据的参数名称,参见jqGrid选项中的rowTotal
}
});
});
</script>
</head>
<body>
<table id="jqGrid"></table>
<div id="jqGridPager"></div>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using UnsionService.model;
using UnsionService.Interface;
using System.Web.Script.Serialization;// for json serialization
using System.Collections.Specialized;
namespace UnsionService.Web.MG.handler
{
public class msgSettings : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string page = context.Request["page"];
string records = context.Request["rows"];
string totalPage = "20";
string jsonStr = GetSwitchDeviceInfoJson(page, totalPage, records);
context.Response.Write(jsonStr);
}
private string GetSwitchDeviceInfoJson(string page, string totalPage, string records)
{
List<Switch_Device> list = UnsionService.Interface.Switch_DeviceDao.Instance.GetSwitches();
StringBuilder outSb = new StringBuilder ();
outSb.Append("{\"page\" : '" + page + "', \"total\" : '" + totalPage + "', \"records\" : '" + records + "', \"grids\":");
List<Dictionary<string, string>> infoList = new List<Dictionary<string, string>>(list.Count);
for (int i = 0; i < list.Count; i++)
{
Dictionary<string, string> tmpDict = new Dictionary<string, string>();
tmpDict.Add("GprsID", list[i].GprsID);
tmpDict.Add("DeviceName", list[i].DeviceName);
tmpDict.Add("DeviceType", "开关");
infoList.Add(tmpDict);
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
StringBuilder deviceInfoSb = new StringBuilder();
serializer.Serialize(infoList, deviceInfoSb);
outSb.Append(deviceInfoSb);
outSb.Append("}");
return outSb.ToString();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
colNames: ['GprsID', 'DeviceName', 'DeviceType'],
colModel: [
{ name: 'GprsID', width: 20 },
{ name: 'DeviceName', width: 80 },
{ name: 'DeviceType', width: 80 }
],
改成 columns
columns: [[
{ field: 'GprsID', title: 'GprsID' },
{ field: "DeviceName", title: "DeviceName", width: "60" },
{ field: "DeviceType", title: "DeviceType", width: "60" }
]]
试试