My problem is that while trying to implement usage of the Autoload feature, I cannot get it to make GET requests to my Action at all to attempt to load the next set of data. The first initial load works fine
I tried following the example here http://trirand.com/blog/jqgrid/jqgrid.html
The feature is listed under the item on the left hand side titled New in Version 3.4 – Autoloading when scrolling
What is the mistake here?
Here is my js grid code
<script type='text/javascript'>
$(document).ready(function()
{
$('#gvEmps').jqGrid(
{
url:'RecordEmpGrid',
datatype: 'json',
colNames:['Select Training(s)'],
colModel :
[
{name: 'Select Training(s)', index: 'TrainingName', width: '300', align: 'Left'}
],
rowNum: 15,
scroll: true,
rowList:[10,20,30],
pager: '#gvEmpsPager',
sortname: 'TrainingName',
viewrecords: true,
sortorder: 'desc',
jsonReader:
{
repeatitems : true,
},
caption: ''
});
});
</script>
Html
<table id="gvEmps" class="SGrid scroll"></table>
<div id="gvEmpsPager" class="scroll"></div>
Controller
//will never hit this action when scrolling, only first time on page load
[HttpGet]
public ActionResult RecordEmpGrid(string sidx, string sord, int page, int rows)
{
var gr = new GridResult(sidx, sord, page, rows);
var skip = rows * page - rows;
DataTable dt = null;
using (var mr = new MultipleRecords(Product.Utility, "evaluateSql"))
{
mr["sql"] = "SELECT * FROM TT.Training WHERE CompanyId = 190 ORDER BY TrainingName ASC";
dt = mr.GetDataTable();
}
gr.Total = dt.Rows.Count;
var records = new MultipleRecords(dt);
foreach (var row in records.Skip(skip).Take(rows))
{
gr.AddDataRow(new []{row["TrainingTypeID"].String, row["TrainingName"].String });
}
return Json(gr.Data, JsonRequestBehavior.AllowGet);
}
My json wrapper object
public class GridResult
{
private List<object> m_rowData = new List<object>();
private string m_order;
private string m_idx;
private int m_rows;
private int m_page;
public int Total { get; set; }
public GridResult()
{
}
public GridResult(string sidx, string sord, int page, int rows)
{
m_idx = sidx;
m_order = sord;
m_page = page;
m_rows = rows;
}
public void AddDataRow(object[] columnData)
{
m_rowData.Add(columnData);
}
private object m_data;
public object Data
{
get
{
return m_data ?? (m_data = BuildData());
}
}
protected object BuildData()
{
var id = 1;
return new
{
total = Total,
page = m_page++,
records = m_rows,
rows = (from row in m_rowData
select new
{
id = id++,
cell = row
}
).ToArray()
};
}
}
The issue was inside my json helper object. I blame poor naming conventions for this but it appears that I was mixing the records & total parameters up.
switching those two solved the problem.
Here is a great link that lead me to the discovery. This guy is a jqGrid guru.
http://blogs.teamb.com/craigstuntz/2009/04/15/38212/