我在用jqGrid时表上总是顶个“undefined”方框,而且不能翻页了,网上查了说是分页的问题,注释掉pager: jQuery('#pager')“undefined”方框就不出现了,但是注释掉之后分页的按钮都没有了,我实在不知道怎么办了。。。我用的是MVC2的框架,代码如下,另外弱弱地求一款较好的jQuery的表格插件,最好是有详细文档和Demo的。
view中代码:
......
<link rel="stylesheet" type="text/css" href="../../Content/jqGridCss/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" href="../../Content/jqGridCss/redmond/jquery-ui-1.7.1.custom.css" />
<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.jqGrid-3.7.2/jquery.jqGrid.min.js" type="text/javascript"></script>
.......
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '/Home/GridData/',
datatype: 'json',
mtype: 'POST',
colNames: ['Id', 'Votes', 'Title'],
colModel: [
{ name: 'Id', index: 'Id', width: 40, align: 'left' },
{ name: 'Votes', index: 'Votes', width: 100, align: 'left' },
{ name: 'Title', index: 'Title', width: 400, align: 'left'}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
//imgpath: '/scripts/themes/basic/images',
caption: 'My first grid'
});
});
</script>
.......
<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
controler中代码:
[HttpPost]
public ActionResult GridData(string sidx, string sord, int page, int rows)
{
int totalPages = 1; // we'll implement later
int pageSize = rows;
int totalRecords = 3; // implement later
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
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);
}
推荐一个:http://kb.cnblogs.com/page/70038/
jqgrid有DEMO可以下载:http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx
http://www.cnblogs.com/PM_2004/archive/2010/02/25/1673722.html
@weiwei5444 太感谢了!!