在 jqGrid 中有属性loadonce:true那么我只得到第一页记录。我怎样才能得到第二页和第三页的记录。
代码:
$(function () {
$("#pendingAppgrid").jqGrid({
colNames: ['Name', 'Email'],
colModel: [
{ name: 'Name', index: 'Name', sortable: true, align: 'left', width: '200',
editable: false, edittype: 'text',search:true
},
{ name: 'Email', index: 'Email', sortable: false, align: 'left', width: '200',
editable: false, edittype: 'text',search:true
},
],
pager: jQuery('#pager'),
sortname: 'Name',
rowNum: 15,
rowList: [10, 20, 25],
sortorder: "desc",
height: 345,
ignoreCase: true,
viewrecords: true,
rownumbers: true,
caption: 'Pending Approvals',
width: 660,
url: "@Url.Content("~/Home/PendingApprovals")",
datatype: 'json',
mtype: 'GET',
loadonce: true
})
jQuery("#pendingAppgrid").jqGrid('filterToolbar', { searchOnEnter: true, enableClear: false });
});
服务器代码
public ActionResult PendingApprovals(int page, int rows, string sidx, string sord)
{
//return View(GetPendingApprovals());
int currentPage = Convert.ToInt32(page) - 1;
int totalRecords = 0;
List<ViewModels.Channel.UserChannels> lTemChannel = new List<ViewModels.Channel.UserChannels>();
List<ViewModels.Channel.UserChannels> lstChannel = new List<ViewModels.Channel.UserChannels>();
lTemChannel = GetPendingApprovals();
foreach (ViewModels.Channel.UserChannels cha in lTemChannel)
{
ViewModels.Channel.UserChannels channelWithLogo = new ViewModels.Channel.UserChannels();
channelWithLogo.ID = cha.ID;
channelWithLogo.Name = cha.Name;
channelWithLogo.Email = cha.Email;
lstChannel.Add(channelWithLogo);
}
totalRecords = lstChannel.Count;
var totalPages = (int)Math.Ceiling(totalRecords / (float)rows);
lstChannel = lstChannel.ToList<ViewModels.Channel.UserChannels>();
IPagedList<ViewModels.Channel.UserChannels> ilstChannel;
switch (sord)
{
case "desc":
ilstChannel = lstChannel.OrderByDescending(m => m.Name).ToPagedList(page, rows);
break;
case "asc":
ilstChannel = lstChannel.OrderBy(m => m.Name).ToPagedList(page, rows);
break;
default:
ilstChannel = lstChannel.OrderBy(m => m.Name).ToPagedList(page, rows);
break;
}
var data = ilstChannel;
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (from m in data
select new
{
id = m.ChannelID,
cell = new object[]
{
m.Name,
m.Email
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
在这里,我只得到第一页记录。我有更多的页面。搜索功能工作正常。问题是我只是第一页记录。没有得到其他页面记录。我怎样才能得到另一个页面记录。请帮忙。