在jqGrid中有屬性loadonce:true然後我只獲取第一頁記錄。我怎樣才能得到第二和第三頁的記錄。在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 });
});
Server代碼
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);
}
我在這裏只得到了第一頁的記錄。我有更多的頁面。搜索功能正常工作。問題是我只是第一頁的記錄。沒有獲得其他網頁記錄。我怎麼能得到另一個頁面記錄。請幫助這個。
我做了同樣的事情。改變了datatype ='local'。並在「filterToolbar」之後的函數內部放置了你給出的代碼。但我沒有得到。 – Ram
@Ram,您不需要將數據類型更改爲本地數據類型,jqGrid本身在第一次加載後執行此操作,此時您將選項loadonce設置爲true。您必須在傳呼機中添加此代碼,請發佈分頁代碼。 –
好的。請你能正確地發佈如何做這個分頁。在這裏,我只獲取第一頁記錄。如果我在頁腳部分更改頁面編號:2,則不顯示第二頁記錄。 – Ram