using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Trirand.Web.Mvc;
using System.Web.UI.WebControls;
namespace JQGridMVCExamples.Models
{
public class EmployeeJqGridModel
{
public JQGrid EmployeesGrid { get; set; }
public EmployeeJqGridModel()
{
EmployeesGrid = new JQGrid
{
Columns = new List()
{
new JQGridColumn { DataField = "EmployeeID",
PrimaryKey = true,
Width = 50 },
new JQGridColumn { DataField = "FirstName" },
new JQGridColumn { DataField = "LastName" },
new JQGridColumn { DataField = "Region"}
},
Width = Unit.Pixel(350),
Height = Unit.Percentage(100)
};
}
}
}
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<JQGridMVCExamples.Models.EmployeeJqGridModel>" %>
<%@ Import Namespace="Trirand.Web.Mvc" %>
<%@ Import Namespace="JQGridMVCExamples.Models" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Hierarchy Custom Row Details</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://www.trirand.net/aspnetmvc/Scripts/trirand/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="http://www.trirand.net/aspnetmvc/Scripts/trirand/jquery.jqGrid.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/themes/redmond/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="http://www.trirand.net/aspnetmvc/Content/themes/ui.jqgrid.css" />
</head>
<body>
<div>
<%= Html.Trirand().JQGrid(Model.EmployeesGrid, "EditDialogGrid") %>
</div>
<br /><br />
<div>
<% Html.RenderPartial("CodeTabs"); %>
</div>
<script type="text/javascript">
function showSubGrid(subgrid_id, row_id)
{
$.ajax({
url: '<%= Url.Action("GetEmployeeDetails", "grid") %>' + "?employeeID=" + row_id,
type: "GET",
success: function(html) {
$("#" + subgrid_id).append(html);
}
});
}
</script>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Trirand.Web.Mvc;
using JQGridMVCExamples.Models;
namespace JQGridMVCExamples.Controllers.Grid
{
public partial class GridController : Controller
{
// This is the default action for the View. Use it to setup your grid Model.
public ActionResult HierarchyCustomRowDetails()
{
// Get the model (setup) of the grid defined in the /Models folder.
var model = new EmployeeJqGridModel();
HierarchyCustomRowDetails_SetUpGrid(model);
// Pass the custmomized grid model to the View
return View(model);
}
// parentRowID is automatically passed from the parent grid to the child grid. Note: parentRowID is case sensitive
public JsonResult HierarchyCustomRowDetails_EmployeesDataRequested(string parentRowID)
{
// Get both the grid Model and the data Model
// The data model in our case is an autogenerated linq2sql database based on Northwind.
var northWindModel = new NorthwindDataContext();
var model = new EmployeeJqGridModel();
HierarchyCustomRowDetails_SetUpGrid(model);
return model.EmployeesGrid.DataBind(northWindModel.Employees);
}
public ContentResult GetEmployeeDetails(int employeeID)
{
var northWindModel = new NorthwindDataContext();
string result = @"| FirstName | {0} | |
| LastName | {1} | |
| Title | {2} | |
| Title of Courtesy | {3} | |
| Birth Date | {4} | |
| Hire Date | {5} | |
| Address | {6} | |
| City | {7} | |
| Postal Code | {8} |