I am able to display my records on jqGrid however the paging is not working. I have 90 records in total and its always showing the first 10 records even though the page number did increase. I had checked the return values to jqGrid from my method and it did show a different set of records being sent to jqGrid but jqGrid is not able to display that new set of records. Below is my code. Please help me. I need this to work urgently. thanks
public JsonResult CheckReading(int page, int rows, string sidx, string sord)
{
IList<SamplerReading> Model =
(IList<SamplerReading>)Session["samplerReadingArray"];
int totalRecords = Model.Count + 1;
int pageSize = rows;
int pageIndex = Convert.ToInt32(page) - 1;
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
string orderBy = string.Format("{0} {1}", sidx, sord);
var sales = Model.AsQueryable()
.OrderBy(orderBy) // Uses System.Linq.Dynamic library for sorting
.Skip(pageIndex * pageSize)
.Take(pageSize);
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = (
from s in Model
select new
{
i = s.ReadingId,
cell = new string[] {
s.SamplingDate.ToShortDateString(),
s.Ph.ToString(),
s.Ec.ToString(),
s.Arsenic.ToString(),
s.Temperature.ToString(),
s.OilAndGrease.ToString(),
s.DepthToCollar.ToString()
}
}).ToArray()
};
return Json(jsonData);
}
where
<table id="list" cellpadding="0" cellspacing="0">
</table>
<div id="pager" style="text-align: center;">
</div>
and
<script type="text/javascript">
var gridimgpath = '/Scripts/jqgrid/themes/redmond/images';
var gridDataUrl = '/Shared/CheckReading';
jQuery("#list").jqGrid({
url: gridDataUrl,
datatype: "json",
mtype: 'GET',
colNames: ['Sampling Date', 'pH', 'EC', 'Arsenic', 'Temperature',
'Oil and Grease', 'Depth to Collar'],
colModel: [
{ name: 'SamplingDate', index: 'SamplingDate', width: 100, align: 'left'},
{ name: 'Ph', index: 'Ph', width: 30, align: 'left' },
{ name: 'Ec', index: 'EC', width: 30, align: 'left' },
{ name: 'Arsenic', index: 'Arsenic', width: 30, align: 'left' },
{ name: 'Temperature', index: 'Temperature', width: 30, align: 'left' },
{ name: 'Oil And Grease', index: 'OilAndGrease', width: 30, align:'left'},
{ name: 'Depth To Collar', index: 'DepthToCollar', width:30,align:'right'}
],
rowNum: 10,
rowList: [10, 20, 30],
imgpath: gridimgpath,
height: 'auto',
width: '900',
pager: jQuery('#pager'),
sortname: 'ReadingId',
viewrecords: true,
sortorder: "desc",
caption: "Sampler Readings",
edit: true
}).navGrid("#pager", { edit: true, add: false, del: false });
</script>