I keep getting this error in Firebug:
d is undefined
[Break On This Error] randId:function(d){return(d?d:b.jgrid....(i,d);if(g)return d;return d.length>
I use JqGrid Version: 4.3.1
My controller method looks like this :
public JsonResult CategoryList(int page)
{
List<CategoryDTO> categories = ServiceUtil.AuctionService.ListCategories();
List<dynamic> json = new List<dynamic>();
if (categories != null && categories.Count > 0)
{
foreach (CategoryDTO cat in categories)
{
json.Add(new { Id = cat.Id, Name = cat.Name, Update = cat.LastUpdate, Regex = cat.ValidationXSD });
}
}
var result = new
{
total = 1,
page = page,
records = categories == null ? 0 : categories.Count,
rows = (from cat in categories.Take(10)
select
new { Id = cat.Id, Name = cat.Name, Update = cat.LastUpdate, Regex = cat.ValidationXSD }
).ToArray()
};
return Json(result, JsonRequestBehavior.AllowGet);
}
The view like this :
$(document).ready(function () {
$("#jqgridListCategory").jqGrid({
url: '/Admin/ManageCategory/CategoryList',
datatype: 'json',
mtype: 'GET',
colNames: ['Id', 'Name', 'LastUpdate', 'RegularExpression'],
colModel: [{ name: 'Id', index: 'Id', width: 40, align: 'left' }, { name: 'Name', index: 'Name', width: 400, align: 'left' }, { name: 'LastUpdate', index: 'LastUpdate', width: 40, align: 'left' }, { name: 'RegularExpression', index: 'RegularExpression', width: 40, align: 'left'}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
caption: 'Categories'
});
});
I cannot figure out what is wrong, any ideas?
Edit 1: Use latest jquery version 1.7.2.
Edit 2: I do not expect Regex from controller to be nothing but a string in View
The
CategoryListaction produce the data in the wrong format. Either you have to usejsonReaderor change the code ofCategoryListaction.The standard format of items from the
rowspart of the server response should be like the followingIf the first column
Idis unique and can be used as the id of the row you can use just array or strings instead:In the jqGrid you should add
key: trueto the list of the properties of the column ‘Id’ and add the following jqGrid optionI recommend you to play with the demo project from my old answer or with it’s modification from another answer.