JQgrid 在生成行时不显示数据
JQgrid not showing data while rows are generating
Jqgrid 未显示 JSON 数据,但正在生成行
服务器端代码:
public JsonResult Denominations()
{
.
.
int counter = 0;
var jsonData = new
{
total = result.UserObject.Count,
page = 1,
rows = (
from p in result.UserObject
select new
{
id = ++counter,
cell = new string [] {
p.CurrencyID.ToString(),
p.DenominationID.ToString(),
p.DenominationName.ToString(),
p.DenominatorCount.ToString(),
p.Multiplier.ToString(),
p.TenderID.ToString()
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
服务器端的数据是这样的:
{"total":1,"page":1,"rows":[{"id":1,"cell":["1","1","Penny","0","0.0100","1"]}]}
JavaScript代码:
$("#denominators").jqGrid({
url: '/Denominations?tenderid=1¤cyid=1',
contentType: "application/json",
datatype: "json",
jsonReader: {
root: 'rows',
page: 'page',
total: 'total',
repeatitems: false,
cell: 'cell',
id: 'id',
userdata:'userdata'
},
mtype: "GET",
colNames: ["CurrencyID", "DenominationID", "TenderID", "Multiplier", "DenominationName", "DenominatorCount"],
colModel: [
{ name: "currencyid", width: 80, align: "center" },
{ name: "denominationid", width: 90, align: "center" },
{ name: "tenderid", width: 250 },
{ name: "multiplier", width: 250 },
{ name: "denominationname", width: 95 },
{ name: "denominatorcount", width: 95 },
],
height: 'auto',
loadonce: true,
sortname: "DenominationID",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true
});
查看:
<table id="denominators" ></table>
视图创建包含列 header 的网格,但是生成了行,但行没有任何数据 int。
你用错了jsonReader
。确切地说 属性 repeatitems: false
是错误的。这意味着 rows
数组中每一项的格式是
{
"currencyid": "1",
"denominationid": "1",
"tenderid": 1,
"denominationname": "Penny",
"denominatorcount": "0",
"multiplier": "0.0100"
}
您使用
{
"id": 1,
"cell": [
"1",
"1",
"Penny",
"0",
"0.0100",
"1"
]
}
相反。所以你应该删除 jsonReader
因为输入数据的格式对应于默认的 jsonReader
,但你仍然需要重新排序网格的列或更改你放置在 cell
数组中的项目的顺序以便它对应于 colModel
.
中的列顺序
补充说明:您为 total
使用了错误的值。应该是页数。顺便说一句,你使用 loadonce: true
。在这种情况下,您可以从响应中删除 "total":1,"page":1
部分,只删除 return 数组的 named 项。如果项目,您应该只选择与属性名称相同的列名称。
Jqgrid 未显示 JSON 数据,但正在生成行
服务器端代码:
public JsonResult Denominations()
{
.
.
int counter = 0;
var jsonData = new
{
total = result.UserObject.Count,
page = 1,
rows = (
from p in result.UserObject
select new
{
id = ++counter,
cell = new string [] {
p.CurrencyID.ToString(),
p.DenominationID.ToString(),
p.DenominationName.ToString(),
p.DenominatorCount.ToString(),
p.Multiplier.ToString(),
p.TenderID.ToString()
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
服务器端的数据是这样的: {"total":1,"page":1,"rows":[{"id":1,"cell":["1","1","Penny","0","0.0100","1"]}]}
JavaScript代码:
$("#denominators").jqGrid({
url: '/Denominations?tenderid=1¤cyid=1',
contentType: "application/json",
datatype: "json",
jsonReader: {
root: 'rows',
page: 'page',
total: 'total',
repeatitems: false,
cell: 'cell',
id: 'id',
userdata:'userdata'
},
mtype: "GET",
colNames: ["CurrencyID", "DenominationID", "TenderID", "Multiplier", "DenominationName", "DenominatorCount"],
colModel: [
{ name: "currencyid", width: 80, align: "center" },
{ name: "denominationid", width: 90, align: "center" },
{ name: "tenderid", width: 250 },
{ name: "multiplier", width: 250 },
{ name: "denominationname", width: 95 },
{ name: "denominatorcount", width: 95 },
],
height: 'auto',
loadonce: true,
sortname: "DenominationID",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true
});
查看:
<table id="denominators" ></table>
视图创建包含列 header 的网格,但是生成了行,但行没有任何数据 int。
你用错了jsonReader
。确切地说 属性 repeatitems: false
是错误的。这意味着 rows
数组中每一项的格式是
{
"currencyid": "1",
"denominationid": "1",
"tenderid": 1,
"denominationname": "Penny",
"denominatorcount": "0",
"multiplier": "0.0100"
}
您使用
{
"id": 1,
"cell": [
"1",
"1",
"Penny",
"0",
"0.0100",
"1"
]
}
相反。所以你应该删除 jsonReader
因为输入数据的格式对应于默认的 jsonReader
,但你仍然需要重新排序网格的列或更改你放置在 cell
数组中的项目的顺序以便它对应于 colModel
.
补充说明:您为 total
使用了错误的值。应该是页数。顺便说一句,你使用 loadonce: true
。在这种情况下,您可以从响应中删除 "total":1,"page":1
部分,只删除 return 数组的 named 项。如果项目,您应该只选择与属性名称相同的列名称。