Answer the question
In order to leave comments, you need to log in
How to populate jqGrid asp.mvc 5?
I can’t fill jqgrid , what I want to display comes from the server (I make a console log in the console). But the information does not fit into the grid itself.
(function ($) {
$(document).ready(function () {
loadTable();
});
function loadTable() {
$.ajax({
url: 'Users/getGridData',
datatype: "json",
method: "GET",
contentType: "application/json; charset=utf-8",
success: function (result) {
console.log("success");
console.log(result);
$("#jqg").jqGrid({
colNames: ['Name', 'Age'],
colModel: [
{
name: 'Name',
index: 'Name',
width: 150,
sortable: true
},
{
name: 'Age',
index: 'Age',
width: 80,
sortable: true
}
],
}).navGrid("#pager", { edit: true, add: true, del: true, search: true, refresh: true });
}
})
}
}(jQuery));
[HttpGet]
public ActionResult getGridData()
{
//var user = db.User.Include(u => u.UserType1);
//string res = JsonConvert.SerializeObject(user.ToList());
//return res;
Dictionary<string, object> assocArray = new Dictionary<string, object>();
assocArray["Name"] = "Ivan";
assocArray["Age"] = "22";
return Json(assocArray,JsonRequestBehavior.AllowGet);
}
Answer the question
In order to leave comments, you need to log in
Maybe I don't understand something. And where do you use result in success somehow? I see that you are writing it to the console, but filling jqGrid is hardcoded.
UPD : Hope it helps www.codeproject.com/Articles/609442/Using-JqGrid-i...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question