<script type="text/javascript">
$(document).ready(function () {
var firstClick = true;
$('.editor-date > input').datepicker();
$('.getdata').click(function () {
if (!firstClick) {
$("#GridTable").trigger("reloadGrid");
}
else
{
firstClick = false;
$('#GridTable').jqGrid({
url: '<%= Url.Action("GetData", "Report") %>',
datatype: 'json',
mtype: 'POST',
colNames: ['Log ID'],
colModel: [{ name: 'LogID', index: 'MessageLogID', key: true, formatter: pointercursor }],
multiselect: true,
sortname: 'LogID',
sortorder: "asc",
viewrecords: true,
pager: '#pager',
rowNum: 20,
rowList: [5, 10, 20, 50],
postData: {
IdParam: function ()
{ return $('#LogID').val(); }
},
jsonReader: {
repeatitems: false,
id: 'LogID',
records: 'TotalRecords',
total: 'TotalPages',
page: 'CurrentPage',
root: 'Rows'
},
loadError: function (xhr, status, error) {
messageBox('Error', 'Error occurred loading data.');
},
height: 'auto',
width: 'auto'
});
});
}
Report Controller Method
public ActionResult GetData(string sidx, string sord, int page, int rows, int IdParam){}
I am trying to load only the needed data from the database ...so when the first page is displayed I am getting 20 rows from db then when the user clicks on next button in the grid I am again hitting the db call and getting next 20 rows now if I debug the method I can see my data coming into the method call but the grid goes to the 2nd page and displays nothing. I mean that the grid is showing the loading sign and then just nothing happens even for the last button I don't get any data but on pager it shows total 100 pages and I can keep going next but only the page no. increments there is no data displayed in the grid.. any help will be appreciated...I tried to read about the Onpaging event but not able to figure out how to implement it in this scenario..
Quick Observation: If I change the row count from 20 to 5 10 or 50 that gets the data and displays on the first page its just that the next pages are not getting displayed...
Controller Method:
int pageSize = rows;
int pageIndex = page - 1;
int totalPages = 0;
//call to the db using Entity FrameWork..
var Log = SERVICE.GetData_sp(IdParam,sidx,sord,page,rows,total).ToList()
var totalCount = Convert.ToInt32(total.Value); //converting because I am getting it as Output parameter from the Store-Proc in objet.parameter type.
totalPages = (int)Math.Ceiling(totalCount / (float)pageSize);
JqGridData gridData = new JqGridData { CurrentPage = page, TotalPages = totalPages, TotalRecords = totalCount };//getting the correct values as I cross checked it by just exec the store-proc.
//storing data in gridData obj from Log.
return Json(gridData);