Can't load data from database to a Jquery Grid - asp.net-mvc-4

The problem im facing is I can't populate a Jqgrid from database, it just show me the data in Json format.
View (ListarDistritos)
#model IEnumerable<Entidades.Base.ENDistrito>
<script src="#Url.Content("~/Scripts/Base/modGrid.js")"></script>
<script src="#Url.Content("~/Content/JqueryGrid/jquery-1.9.0.min.js")"></script>
<link href="#Url.Content("~/Content/JqueryGrid/jquery-ui-1.9.2.custom.css")" rel="stylesheet" />
<script src="#Url.Content("~/Content/JqueryGrid/jquery.jqGrid.js")"></script>
<link href="#Url.Content("~/Content/JqueryGrid/ui.jqgrid.css")" rel="stylesheet" />
<script src="#Url.Content("~/Content/JqueryGrid/grid.locale-en.js")"></script>
<link href="#Url.Content("~/Content/estilo.css")" rel="stylesheet" />
<h2>#ViewBag.Message</h2>
<table id="grid">
</table>
<div id="pager"></div>
ModGrid.JS
var lastsel;
$(document).ready(function() {
$("#grid").jqGrid({
url: '/MantDistritos/ListarDistritos',
datatype: "json",
mtype: 'GET',
colNames: ['Id', 'Descripcion'],
colModel: [
{
name: 'IdDistrito', index: 'IdDistrito', sortable: false, align: 'left', width: '200',
editable: true, edittype: 'text'
},
{
name: 'DescripcionDistrito', index: 'DescripcionDistrito', sortable: false, align: 'left', width: '200',
editable: true, edittype: 'text'
}
],
jsonReader: {
repeatitems: false,
id: "0"
},
pager: jQuery('#pager'),
sortname: 'DescripcionDistrito',
rowNum: 10,
rowList: [10, 20, 25],
sortorder: "",
height: 125,
viewrecords: true,
rownumbers: true,
caption: 'Distritos',
width: 750,
editurl: "/Home/PerformCRUDAction",
onCellSelect: function (rowid, iCol, aData) {
if (rowid && rowid !== lastsel) {
if (lastsel)
jQuery('#grid').jqGrid('restoreRow', lastsel);
jQuery('#grid').jqGrid('editRow', rowid, true);
lastsel = rowid;
}
}
})
jQuery("#grid").jqGrid('navGrid', '#pager', { edit: false, add: true, del: true, search: false, refresh: true },
{ closeOnEscape: true, reloadAfterSubmit: true, closeAfterEdit: true, left: 400, top: 300 },
{ closeOnEscape: true, reloadAfterSubmit: true, closeAfterAdd: true, left: 450, top: 300, width: 520 },
{ closeOnEscape: true, reloadAfterSubmit: true, left: 450, top: 300 });
});
controller(MantDistritos)
public class MantDistritosController : Controller
{
public JsonResult ListarDistritos()
{
ViewBag.Message = Resources.Language.Title_Page_MTD_L;
var distrito = new LNClientes().DistritoListar();
return Json(distrito,JsonRequestBehavior.AllowGet);
}
}
When i execute the application it shows me this
[{"IdDistrito":1,"DescripcionDistrito":"MAGDALENA DEL MAR"},{"IdDistrito":2,"DescripcionDistrito":"JESUS MARIA"},{"IdDistrito":3,"DescripcionDistrito":"PUEBLO LIBRE"},{"IdDistrito":4,"DescripcionDistrito":"LIMA 36"},{"IdDistrito":5,"DescripcionDistrito":"BARRANCO"},{"IdDistrito":6,"DescripcionDistrito":"MIRAFLORES"},{"IdDistrito":7,"DescripcionDistrito":"SAN ISIDRO"},{"IdDistrito":8,"DescripcionDistrito":"SAN JUAN DE LURIGANCHO"},{"IdDistrito":9,"DescripcionDistrito":"SAN JUAN DE MIRAFLORES"},{"IdDistrito":10,"DescripcionDistrito":"LOS OLIVOS"},{"IdDistrito":11,"DescripcionDistrito":"COMAS"},{"IdDistrito":12,"DescripcionDistrito":"SURCO"}]
But it didn't show me any data inside the Jquery grid.
If i use ActionResult instead of JsonResult it shows me the Jquery grid but with no data.
Any clue to solve my issue would be appreciate
Thanks.

your json data seems to be fine. i find no error. Seems there is an error in your jsonReader. ID is the name of the Column. it should be of the form
jsonReader : {
root:"data", // Here your posted json data
page: "currpage", // shows current page
total: "totalpages", // total pages
records: "totalrecords" // total records
},
this url may help you to understand better. JsonReader wiki
And if you dont want to be bother about pages and total you can simply
jsonReader : {
root:"data",
page: function(obj) { return 1; }, // page as 1
total: function(obj) { return 1; }, // total as 1
records: function(obj) { return reponse.length;},
},

Related

Data is not loading at JqGrid in Asp.net Core

Data is not getting loaded in JqGrid from controller in ASP.NET Core.
I tried two ways, you can see two different methods in controller which I tried.
What am I doing wrong?
Index.cshtml
<link rel="stylesheet" href="/css/ui.jqgrid.css" />
<link rel="stylesheet" href="/css/jquery-ui.css" />
<script type="text/javascript" src="/js/grid.locale-en.js"></script>
<script type="text/javascript" src="/js/jquery.jqGrid.min.js"></script>
<table id="jqGrid"></table>
<div id="jqGridPager"></div>
#section scripts {
<script type="text/javascript">
$(document).ready(function () {
$("#jqGrid").jqGrid({
url:'#Url.Action("Index", "Maintenance")',
mtype: "POST",
datatype: "json",
colModel: [
{ label: 'Badge', name: 'Badge', key: true, width: 75 },
{ label: 'User ID', name: 'User', width: 150 },
{ label: 'EmailAddress', name: 'EmailAddress', width: 150 },
{ label: 'FULL_NAME_PREFERRED', name: 'FULL_NAME_PREFERRED', width: 150 },
{ label: 'Active', name: 'Active', width: 150 }
],
viewrecords: true,
width: 780,
height: 250,
rowNum: 20,
pager: "#jqGridPager"
});
});
</script>
}
MaintenanceController
Way 1
public IActionResult Index()
{
var lstMaintenanceModels = repos.GetUsers();
return View(lstMaintenanceModels);
}
Way 2
public JsonResult Index()
{
var lstMaintenanceModels = repos.GetUsers();
return Json(lstMaintenanceModels);
}
Starup.cs
services.AddControllers().AddNewtonsoftJson(options =>
{
// Use the default property (Pascal) casing
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
Output what i am getting right now
Way 1
Way 2
You need to write all js code in #section Scripts{}, Because the key in the json returned by the controller is lowercase, and what you wrote here is uppercase, it cannot be received. So in page you need to wirte like this :
The page needs to receive the value of json type, so you need to use the second method, or return the model directly, the program will automatically serialize it to json.
Code
<link crossorigin="anonymous" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" integrity="sha512-aOG0c6nPNzGk+5zjwyJaoRUgCdOrfSDhmMID2u4+OIslr0GjpLKo7Xm0Ao3xmpM4T8AmIouRkqwj1nrdVsLKEQ==" rel="stylesheet"></link>
<link crossorigin="anonymous" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.5/css/ui.jqgrid.min.css" integrity="sha512-xAIWSSbGucVRdutqUD0VLDowcMF/K8W87EbIoa9YUYB4bTyt/zeykyuu9Sjp0TPVdgrgGgBVCBowKv46wY5gDQ==" rel="stylesheet"></link>
<link crossorigin="anonymous" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.5/plugins/css/ui.multiselect.min.css" integrity="sha512-UuhJihFIXhnP4QEzaNXfLmzY9W3xoeTDATm0buV4wb2qJKoikNn568f0zA5QmrX0sp6VZzqE6fffvsTYU34tGA==" rel="stylesheet"></link>
<table id="dataTable"></table>
<div id="pager"></div>
#section Scripts
{
<script crossorigin="anonymous" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script crossorigin="anonymous" integrity="sha512-xt9pysburfYgFvYEtlhPDo8qBEPsupsDvWB8+iwspD+oQTvAdDEpA1aIKcH6zuABU528YitH6jtP0cAe5GrwKA==" src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.5/jquery.jqgrid.min.js"></script>
<script>
jQuery("#dataTable").jqGrid({
url:'#Url.Action("GetUsers", "Home")',
datatype: "json",
mtype: 'POST',
//here name must be
colModel: [
{ label: 'Badge', name: 'badge', key: true, width: 75 },
{ label: 'User ID', name: 'user', width: 150 },
{ label: 'EmailAddress', name: 'emailAddress', width: 150 },
{ label: 'FULL_NAME_PREFERRED', name: 'fulL_NAME_PREFERRED', width: 150 },
{ label: 'Active', name: 'active', width: 150 }
],
loadonce: true,
width: 780,
height: 250,
rowNum: 20,
pager: "#pager"
});
</script>
}
If the parameter datatype is 'json', jqGrid expects the following default format for JSON data
{
"total": "xxx",
"page": "yyy",
"records": "zzz",
"rows" : [
{"id" :"1", "cell" :["cell11", "cell12", "cell13"]},
{"id" :"2", "cell":["cell21", "cell22", "cell23"]},
]
}
You can read about this there^
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data
Try this:
return Json(new { rows = repos.GetUsers() } );

JQgrid is not loading data when i redirect from one page to another in asp.net mvc4

i have an issue with my jqgrid in asp.net mvc4. i am creating user form, in this i will be adding data to user details, and when i click submit, it will be added to the database, and based on its result it will redirect to the respective page.
If adding is success, then it will be redirected to userlist page, where i have my JQgrid,the problem is, i can see the grid, but no data is there in the grid. What would be my issue.
My controller code to add a new user looks like this:
public ActionResult CreateNewUser(Tbl_Users tbl_users)
{
int userId = 1;
tbl_users.CreatedBy = userId;
tbl_users.CreatedOn = DateTime.Now;
tbl_users.ModifiedBy = null;
tbl_users.ModifiedOn = null;
if (ModelState.IsValid)
{
db.Tbl_Users.Add(tbl_users);
db.SaveChanges();
return RedirectToAction("**ListUsers**", "**Admin**");
}
ViewBag.UserCity = new SelectList(db.Tbl_Mst_City, "CityId", "CityName", tbl_users.UserCity);
ViewBag.UserDesignation = new SelectList(db.Tbl_Mst_Designation, "DesignationID", "Designation", tbl_users.UserDesignation);
ViewBag.RoleId = new SelectList(db.Tbl_Roles, "RoleID", "Role", tbl_users.RoleId);
ViewBag.CreatedBy = new SelectList(db.Tbl_Users, "UserID", "UserName", tbl_users.CreatedBy);
return View(tbl_users);
}
And My controller action to load my grid is
public ActionResult ListUsers()
{
return View();
}
public JsonResult GetUSerDetails(string sidx = "UserID", string sord = "asc", int page = 1, int rows = 5)
{
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = db.Tbl_Users.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var userdata = db.Tbl_Users.OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize)
.Select(u =>
new
{
u.UserID,
u.UserName,
u.UserEmail,
u.UserMobile,
u.UserCity,
u.UserDesignation,
u.RoleId,
u.CreatedBy,
u.CreatedOn
}).ToList();
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (
from u in userdata.AsEnumerable()
select new
{
i = u.UserID,
cell = new string[] { u.UserID.ToString(), u.UserName, u.UserEmail, u.UserMobile, u.UserCity.ToString(), u.UserDesignation.ToString(), u.RoleId.ToString(), u.CreatedBy.ToString(), u.CreatedOn.ToString() }
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
My View Page For the List User and JQgrid is looks like this:
#model FSLIWeb.Models.Tbl_Tasks
#{
ViewBag.Title = "ListUsers";
Layout = "~/Views/Shared/AdminDashboardLayout.cshtml";
}
#Html.ActionLink(" User List", "Index")
<h2>Index</h2>
<table id="jQGridDemo" width:"1024px">
</table>
<div id="jQGridDemoPager" style="width:100%">
</div>
<script type="text/javascript">
jQuery("#jQGridDemo").jqGrid({
url: 'Admin/GetUserDetails',
datatype: "json",
colNames: ['UserID','UserName','UserEmail','Contact Num','City','UserDesignation','RoleId','CreatedBy','CreatedOn'],
colModel: [
{ name: 'UserID', index: 'UserID', width: 75, align: 'center', sortable: true, editable: false, key: true, editrules: { required: true} },
{ name: 'UserName', index: 'UserName', width: 120, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} },
{ name: 'UserEmail', index: 'UserEmail', width: 100, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} },
{ name: 'UserMobile', index: 'UserMobile', width: 100, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} },
{ name: 'City', index: 'City', width: 100, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} },
{ name: 'UserDesignation', index: 'UserDesignation', width: 85, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} },
{ name: 'RoleId', index: 'RoleId', width: 70, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} },
{ name: 'CreatedBy', index: 'CreatedBy', width: 70, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} },
{ name: 'CreatedOn', index: 'CreatedOn', width: 70, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} }
],
mtype: 'GET',
loadonce: true,
rowList: [5, 10, 20, 30],
pager: '#jQGridDemoPager',
sortname: 'UserID',
viewrecords: true,
sortorder: 'desc',
width:"100%",
caption: "List Of Users",
//editurl: "//EditUser/"
});
jQuery("#jQGridDemo").jqGrid('navGrid', '#jQGridDemoPager',
{ edit: true, add: true, del: true, search: true },
{ url: "/Admin/EditUser/", closeAfterEdit: true, beforeShowForm: function (formid) { $("#UserID", formid).hide(); } },
{ url: "/Admin/AddNewUser/", closeAfterAdd: true, beforeShowForm: function (formid) { $("#UserID", formid).hide(); } },
{ url: "/Admin/DeleteUser/" }, {});
$("#search").filterGrid("#grid", {
gridModel: false,
filterModel: [{
label: 'Search',
name: 'search',
stype: 'text'
}]
});
</script>
Your Valuable Suggestion will help me to get solved this problem.
Thanks in Advance
The data URL in the jqGrid definition should be like this:
jQuery("#jQGridDemo").jqGrid({
url: '/Admin/GetUserDetails',
...
});

jqGrid Paging - no ajax call to get next page

I have a page with two jqGrids on it in different elements. When I first load the page, Firebug reports an ajax call to get the first 15 rows as expected, and the pager accurately shows the number of pages and the number of records. However, when I click the arrows on the pager, no ajax call is traced in Firebug, so I am pretty sure that something is not wired correctly. The odd thing is that I have other pages with only one jqGrid and paging works as expected. I have breakpoints in my controller (MVC4) and the initial load hits them just fine and all of the arguments are correct:
#region GetUnManagedMerchants
public JsonResult GetUnManagedMerchants(string id, string sidx, string sord, int page, int rows)
{
return GetSomeMerchants(id, false, sidx, sord, page, rows);
}
#endregion
Here is my script code:
$(document).ready(function () {
jQuery("#grdUnManaged").jqGrid({
url: '/Ajax/GetUnManagedMerchants/' + $('#UserInContext_UserId').val(),
datatype: 'json',
mType: 'GET',
colNames: ['', 'UnManaged Merchant', ''],
colModel: [
{ name: 'Manage', key: true, index: 'manage', width: 20, sortable: false, formatter: function () { return '<img src="#Url.Content("~/content/images/icons/merchant.png")" width="16" height="16" alt="Merchants" />'; } },
{ name: 'Name', index: 'name', width: 325 },
{ name: 'id', index: 'id', width: 0, hidden: true , key: true}
],
pager: '#grdUnManagedPager',
rowNum: 15,
width: 450,
height: 300,
viewrecords: true,
caption: 'Current UnManaged Merchants',
beforeSelectRow: function (rowid, e) {
var iCol = $.jgrid.getCellIndex(e.target);
if (iCol == 0) {
var merchantId = jQuery(this).getRowData(rowid)['id'];
var userId = $('#UserInContext_UserId').val();
ManageMerchant(userId, merchantId);
return true;
}
return false;
}
});
jQuery("#grdUnManaged").jqGrid('navGrid', '#grdUnManagedPager', { add: false, edit: false, del: false, search: false, refresh: true });
});
Please help me with what is missing! This is the last item I need to fix prior to finishing this project.
Thanks!
I have made the changes you suggest (Thanks) yet I still do NOT get an ajax call back when I click on the pager to see a subsequent page. I am re-posting my entire script with both grids.
<script type="text/javascript">
var buttonNames = {};
buttonNames[0] = 'Manage';
$(document).ready(function () {
jQuery('#currentUserHeader').html('<h3>Merchant Lists for ' + $('#UserInContext_Email').val() + '.</h3>');
jQuery("#grdManaged").jqGrid({
url: '/Ajax/GetManagedMerchants/' + $('#UserInContext_UserId').val(),
datatype: 'json',
mType: 'GET',
colNames: ['', 'Managed Merchant', ''],
colModel: [
{ name: 'Manage', index: 'Manage', width: 20, sortable: false, formatter: function () { return '<img src="#Url.Content("~/content/images/chevron.png")" width="16" height="16" alt="Merchants" />'; } },
{ name: 'Name', index: 'Name', width: 325 },
{ name: 'id', index: 'id', width: 0, hidden: true, key: true }
],
pager: '#grdManagedPager',
rowNum: 15,
width: 450,
height: 300,
viewrecords: true,
caption: 'Current Managed Merchants',
beforeRequest: function () {
var getUrl = '/Ajax/GetManagedMerchants/' + $('#UserInContext_UserId').val();
$('#grdManaged').setGridParam([{ url: getUrl }]);
},
beforeSelectRow: function (rowid, e) {
var iCol = $.jgrid.getCellIndex(e.target);
if (iCol == 0) {
var merchantId = jQuery(this).getRowData(rowid)['id'];
var userId = $('#UserInContext_UserId').val();
UnManageMerchant(userId, merchantId);
return true;
}
return false;
}
});
jQuery("#grdManaged").jqGrid('navGrid', '#grdManagedPager', { add: false, edit: false, del: false, search: false, refresh: true });
});
</script>
<script type="text/javascript">
$(document).ready(function () {
jQuery("#grdUnManaged").jqGrid({
url: '/Ajax/GetUnManagedMerchants/' + $('#UserInContext_UserId').val(),
datatype: 'json',
mType: 'GET',
colNames: ['', 'UnManaged Merchant', ''],
colModel: [
{ name: 'Manage', index: 'Manage', width: 20, sortable: false, formatter: function () { return '<img src="#Url.Content("~/content/images/chevron-left.png")" width="16" height="16" alt="Merchants" />'; } },
{ name: 'Name', index: 'Name', width: 325 },
{ name: 'id', index: 'id', width: 0, hidden: true , key: true}
],
pager: '#grdUnManagedPager',
rowNum: 15,
width: 450,
height: 300,
viewrecords: true,
caption: 'Current UnManaged Merchants',
beforeRequest: function () {
var getUrl = '/Ajax/GetUnManagedMerchants/' + $('#UserInContext_UserId').val();
$('#grdUnManaged').setGridParam([{ url: getUrl }]);
},
beforeSelectRow: function (rowid, e) {
var iCol = $.jgrid.getCellIndex(e.target);
if (iCol == 0) {
var merchantId = jQuery(this).getRowData(rowid)['id'];
var userId = $('#UserInContext_UserId').val();
ManageMerchant(userId, merchantId);
return true;
}
return false;
}
});
jQuery("#grdUnManaged").jqGrid('navGrid', '#grdUnManagedPager', { add: false, edit: false, del: false, search: false, refresh: true });
});
may be your jqgrid overrides each other,may be on click paging second jqgrid overrides some thig,,,
but hope this help..
http://www.codeproject.com/Articles/594150/MVC-Basic-Site-Step-4-jqGrid-In

How to refresh jqgrid using the response data returned from the edit

I am using the inlineNav edit options for Adding and Editing rows. The data is being updated to the database correctly, but I can't find a way to refresh the grid after a successful save without posting back to the server.
All of the Questions & Answers that I find recommend doing
$.('grid').trigger('reloadGrid');
But that seems unnecessary if the response from the server already contains the required data. It is primarily an issue when adding a new record and the ID value is displayed as jqg1.
I am using ASP.NET MVC4, with jqGrid 4.4.4.
Here is my view
$(document).ready(function () {
var emptyMsgDiv = $('<div>No school codes to display.</div>');
var grid = $('#tblSchools');
grid.jqGrid({
datatype: 'json',
viewrecords: true,
url: '#Url.Action("SchoolsGridData")',
editurl: '#Url.Action("EditSchoolsGridData")',
colNames: ['School ID', 'Name', 'SACE Number', 'School Code', 'LEA Code', 'DFEE Code', 'Active'],
colModel: [
{ name: 'SchoolId', index: 'SchoolId', width: 80, key: true },
{ name: 'Name', index: 'Name', width: 190, editable: true },
{ name: 'SaceSchoolNumber', index: 'SaceSchoolNumber', width: 105, editable: true, sortable: false },
{ name: 'Code', index: 'Code', width: 105, editable: true, sortable: false },
{ name: 'LeaCode', index: 'LeaCode', width: 80, editable: true, sortable: false },
{ name: 'DfeeCode', index: 'DfeeCode', width: 80, editable: true, sortable: false },
{ name: 'Active', index: 'Active', width: 80, editable: true, sortable: false }
],
shrinkToFit: true,
height: "100%",
caption: 'School list',
rowNum: 10,
rowList: [10, 15, 20],
emptyrecords: 'No school codes to display.',
pager: '#schoolsPager',
loadComplete: function () {
var count = grid.getGridParam();
var ts = grid[0];
if (ts.p.reccount === 0) {
grid.hide();
emptyMsgDiv.show();
} else {
grid.show();
emptyMsgDiv.hide();
}
}
}).trigger('reloadGrid', [{ page: 1 }]);
emptyMsgDiv.insertAfter(grid.parent());
grid.jqGrid('navGrid', "#schoolsPager", { edit: false, add: false, del: true });
grid.jqGrid('inlineNav', '#schoolsPager', {
addParams: {
position: "last",
addRowParams: {
"keys": true,
"aftersavefunc": function (rowid, response) {
alert('row: ' + rowid + ', response: ' + $.param(response));
}
}
},
editParams: {
"aftersavefunc": function (rowid, response) {
alert('row: '+rowid+', response: '+response);
}
}
});
});
</script>
<h3>Maintain Schools</h3>
<table id="tblSchools"></table>
<div id="schoolsPager" class="gridPager"></div>
and my Controller
public JsonResult EditSchoolsGridData(string oper, string SchoolId, string Name, string SaceSchoolNumber, string Code, string LeaCode, string DfeeCode, string Active)
{
[Update Logic]
return SchoolsGridData(string.Empty, "asc", 1, 10);
}
[HttpGet]
public JsonResult SchoolsGridData(string sidx, string sord, int? page, int? rows)
{
[Get data logic]
}
I can see the response json being displayed in the aftersavefunc, but can't find a way to bind it to the grid.
Is what I'm trying to do even possible?
You can use the addRowData method which will set the data to grid with our reloading the grid
jQuery("#tblSchools").jqGrid('addRowData', response.SchoolId, response, "first");
See the jqgrid methods wiki for more details

getting exceptions with jqGrid

I am attempting to set up my jqGrid to get data from a function on document.ready. Somehow I am running into several small exceptions when I do this... I thought originally that maybe my json data was malformated...
{"total": 2,
"page": 1,
"records": 15,
"rows": [{
"id": 2148,
"cell": {
"MRN": "840134833",
"Hospital_Fin": "987141516",
"First_Name": "YELLOW",
"Last_Name": "CRAYON",
"Date_of_birth": "\/Date(1253160000000)\/"
}
},
{
"id": 1898,
"cell": {
"MRN": "785528039",
"Hospital_Fin": "6669511596226",
"First_Name": "RAYFIELD",
"Last_Name": "BOYD",
"Date_of_birth": "\/Date(-720298800000)\/"
}
}]}
But it appears to look right.
I get this exception, for instance:
0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'integer': object is null or undefined
I get that exception at the following line in the code...
fmt = $.jgrid.formatter.integer || {};
I set up my grid as follows
$(document).ready(function () {
jQuery("#frTable").jqGrid ({
cmTemplate: { sortable: false },
caption: '#TempData["POPNAME"]' + ' Population',
datatype: 'json',
mtype: 'GET',
url: '#Url.Action("GetAjaxPagedGridData", "Encounters", new { popId = TempData["POPULATIONID"] })',//'/Encounters/GetAjaxPagedGridData/'+ '',
pager: '#pager',
loadonce: true,
height: 450,
gridview: true,
viewrecords: true,
rowNum: 15,
shrinkToFit: false,
autowidth: true,
colNames: [...],
colModel: [
{ name: 'MRN', width: 125, align: 'left' },
{ name: 'Hospital_Fin', width: 145, align: 'left' },
{ name: 'First_Name', width: 115, align: 'left' },
{ name: 'Last_Name', width: 115, align: 'left' },
{ name: 'Date_of_birth', width: 145, align: 'left' },]
Where colNames and colModel are unimportant.
Im at my wits end here. This should be working. What am I missing?
You may be missing the required locale file, where the $.jqgrid.formatter is defined:
jqGrid docs
You need to include jQuery, the jqGrid plugin and one of the jqGrid locale files for it to work, for example:
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
That error sounds to me like you have a problem with an object in your view not having been set. Try setting a static value rather then something like TempData["POPULATIONID"] and I would think you might move forward.