I want to fill jqGrid from a stored procedure, there was 1 good example is given at following link, but my problem is that I am not using model to retrieve data, any SOLUTION ?
I am using jqGrid + SQL Server 2008 + ASP.net MVC3 (c#)
Example of jqGrid filling by stored procedure with Model
Here by am giving the code that i am using currently
VIEW CODE
$(document).ready(function () {
$('#History').jqGrid({
//url from wich data should be requested
url: '@Url.Action("UploadData")?entity=' + getEntity(),
//type of data
datatype: 'json',
//url access method type
mtype: 'GET',
//columns names
colNames: ['ID', 'File','Uploaded', 'By'],
//columns model
colModel: [
{ name: 'ID', index: 'ID', align: 'left', editable: false },
{ name: 'File', index: 'File', align: 'left', editable: false, formatter: "text", width: '105px' },
{ name: 'Uploaded', index: 'Uploaded', align: 'left', editable: false, formatter: "text", width: '102px' },
{ name: 'By', index: 'By', align: 'left', editable: false, formatter: "text", width: '78px' },
],
//pager for grid
pager: $('#Historypager'),
//number of rows per page
rowNum: 15,
//initial sorting column
sortname: 'File',
//initial sorting direction
sortorder: 'asc',
//we want to display total records count
viewrecords: true,
//Sets the caption for grid
caption: 'Upload History',
//grid height
height: '100%'
});
$('#History').jqGrid('navGrid', '#Historypager', { add: false, del: false, edit: false, search: false });
$('#History').jqGrid('hideCol', "ID");
var dialogPosition = $(this).offset();
});
CONTROLLER METHOD
public JsonResult UploadData(string sidx, string sord, int page, int rows, string entity)
{
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
var entitytype = Request.QueryString["entity"].ToString().Trim();
var uploadlist = objEntities.Uploads.Where(u => u.TableName == entitytype).ToList().AsQueryable(); // fetches the data from upload table
int totalRecords = uploadlist.ToList().Count(); // total records in the current table
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize); // counts the total no. of pages
if (sord.Trim().ToLower() == "asc") // fetches data according the sorting order
uploadlist = uploadlist.OrderBy(x => TypeHelper.GetPropertyValue(x, sidx)).Skip(pageIndex * pageSize).Take(pageSize);
else
uploadlist = uploadlist.OrderByDescending(x => TypeHelper.GetPropertyValue(x, sidx)).Skip(pageIndex * pageSize).Take(pageSize);
// fetches data and sets it in JSON format
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = (from b1 in uploadlist
select new
{
id = b1.ID,
cell = new string[] {
Convert.ToString(b1.ID),
b1.File,
Convert.ToString(b1.Uploaded),
Convert.ToString(b1.By)
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet); // returns the data back to the jqgrid
}
In this Example i’ve used LINQ demo, but now in new task i’ve to use Stored Procedure to fetch the data…
CONTROLLER CODE