在下面的代码中,动作方法GetData()
将数据加载到jqgrid。但有趣的是,它显示它有数据,但行没有显示数据,分页器组件显示它有多个页面,我可以单击行,甚至在单击某行时仍显示蓝色边框颜色,但仍未显示数据。为什么JQGrid未能显示数据?
我做了一切,我可以找到问题,有没有办法解决这个问题?
操作方法:
DBContext db = new DBContext();
public ActionResult Index()
{
return View();
}
public JsonResult GetData()
{
try
{
var customers = db.Customers.Select(x => new { x.CustomerID, x.FirstName, x.MiddleName,x.CompanyName, x.SalesPerson, x.EmailAddress }).ToList();
return Json(customers, JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
throw;
}
}
的观点:
<script src="~/Scripts/jquery-3.1.0.js"></script>
<script src="~/Scripts/jquery-ui-1.12.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/i18n/grid.locale-en.js"></script>
<script src="~/Scripts/jquery.jqGrid.min.js"></script>
<h2>Index</h2>
<table id="customerGrid"></table>
<div id="pager1"></div>
@section scripts{
<script>
$(function() {
jQuery("#customerGrid").jqGrid({
url: 'Home/GetData',
datatype: "json",
mtype: "GET",
postData:'',
colNames: ['Customer ID', 'First Name', 'Last Name'],
colModel: [
{ name: 'customerid', index: 'CustomerID', key:true,sorttype:'int', width: 100 },
{ name: 'firstname', index: 'FirstName', width: 100 },
{ name: 'lastname', index: 'LastName', width: 100 }
],
viewrecords: true,
gridview: true,
autoencode: true,
loadonce: true, //if all data loaded at once
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager1',
sortname: 'customerid',
viewrecords: true,
sortorder: "desc",
caption: "Customer List",
width:600
});
jQuery("#customerGrid").jqGrid('navGrid', '#pager1', { edit: false, add: false, del: false });
})
</script>
}
什么是常用的jqgrid版本? –
是否有适合JQGrid和视频的文档 –
@vitofila:没有“常用”的jqGrid版本。它最初由Tony Tomov以三位数开发,并且可以在MIT/GPLv2许可下免费获得。他发布了[声明](http://www.trirand.com/blog/?p=1438),将jqGrid更名为Guriddo jqGrid JS,并将其改为商业版(请参见价格[here](http://guriddo.net) /?PAGE_ID = 103334))。之后,我开始了基于jqGrid 4.7的fork“free jqGrid”,它修复了许多bug并实现了许多新功能。我使用4.x.y作为版本号,因为我试图保持**与旧版本的jqGrid **的兼容性。 – Oleg