Using MVC2 and EF framework. Most references/blog posts I've found so far pertain to binding a single table and its data (sometimes hierarchical) to a jqGrid with editing capabilities. I don't need this. I don't even need to edit the data--just display. I need to display and page the data. Sorting is a plus, searching a bonus I guess.
jqGrid's documentation shows the data source being bound as follows:
return gridModel.OrdersGrid.DataBind(northWindModel.Orders);
But, I only have my Entities context without a reference to the view model. Could I create an Entity set here? Not very familiar with this.
All my view models contain data from several different tables. What can I do to bind the view model properties to a jqGrid? I'm playing with Trirand's 30-day trial of jqGrid for MVC. Again, I just need to display and page the data, but I'm not sure how to hook up the view models to the jqGrid data source.
Edit
public ActionResult test()
{
var gridModel = new testmodel();
var viewModel = gridModel.testgrid;
SetupTestGrid(viewModel);
return View(gridModel);
}
private void SetupTestGrid(JQGrid viewModel)
{
viewModel.ID = "TestGrid";
viewModel.DataUrl = Url.Action("SearchTestGridDataRequested");
viewModel.ToolBarSettings.ShowEditButton = false;
viewModel.ToolBarSettings.ShowAddButton = false;
viewModel.ToolBarSettings.ShowDeleteButton = false;
}
public JsonResult SearchTestGridDataRequested(string sidx, string sord, int page, int rows)
{
var gridModel = new testmodel(sidx, sord, page, rows);
SetupTestGrid(gridModel.testgrid);
return Json(gridModel.datasource);
}
In testmodel and testmodel(parameters), I create an anonymous type (named datasource) containing Phil Haack's parameters; total, page, records and rows. This property is JSON'ified in the last statement of SearchTestGridDataRequested.