[英]jqgrid does not display rows
我使用此鏈接構建了基本的jqgrid: http ://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx
這是我的代碼:
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '/Home/GridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['ProductID', 'ProductName'],
colModel: [
{ name: 'ProductID', index: 'ProductID', width: 40, align: 'left' },
{ name: 'ProductName', index: 'ProductName', width: 40, align: 'left'}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'My first grid'
});
});
public ActionResult GridData(string sidx, string sord, int page, int rows)
{
List<Product> listProducts = new List<Product>(){new Product(){ProductName = "koekies",ProductID = 1},
new Product(){ProductName = "snoepjes",ProductID = 2}};
return Json(listProducts, JsonRequestBehavior.AllowGet);
}
您是否閱讀了鏈接的整個帖子? 他返回的json看起來與您返回的內容有很大不同。
public ActionResult GridData(string sidx, string sord, int page, int rows) {
var jsonData = new {
total = 1, // we'll implement later
page = page,
records = 3, // implement later
rows = new[]{
new {id = 1, cell = new[] {"1", "-7", "Is this a good question?"}},
new {id = 2, cell = new[] {"2", "15", "Is this a blatant ripoff?"}},
new {id = 3, cell = new[] {"3", "23", "Why is the sky blue?"}}
}
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
該id字段很重要,jsgrid喜歡知道您要添加的行號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.