Index.cshtml
@Html.EJS().Grid("Grid").DataSource(dataManger =>
{
dataManger.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor");
}).AllowPaging().DetailTemplate("#DetailGridTemplate").DetailDataBound("detailDataBound").Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").Add();
col.Field("EmployeeID").HeaderText("Employee ID").IsPrimaryKey(true).Add();
col.Field("CustomerID").HeaderText("CustomerID").Add();
}).Render()
</div>
<script id="DetailGridTemplate" type="text/x-template">
<div id="ChildGridone${OrderID}"></div>
<div id="childGridtwo${OrderID}"></div>
</script>
<script>
function detailDataBound(e) {
var childGridData = @Html.Raw(Json.Encode(ViewBag.childdata));
var data = new ej.data.DataManager({
url: "/Home/ChildDatasource",
adaptor: new ej.data.UrlAdaptor,
crossDomain: true
});
var firstdetailgrid = new ej.grids.Grid({
dataSource: data,
load: function (args) {
this.query = new ej.data.Query().addParams("EmployeeID", e.data.EmployeeID) // Pass the parent grid row data to server end
},
columns: [
{ field: 'FirstName', headerText: 'Employee Name', width: 110 },
{ field: 'EmployeeID', headerText: 'Employee ID', width: 110 }
]
});
firstdetailgrid.appendTo(e.detailElement.querySelector('#ChildGridone' + e.data.OrderID));
var seconddetailGrid = new ej.grids.Grid({
dataSource: childGridData,
columns: [
{ field: 'CustomerID', width: 110 },
{ field: 'Freight', width: 110 }
]
});
seconddetailGrid.appendTo(e.detailElement.querySelector('#childGridtwo' + e.data.OrderID));
}
</script>
[HomeController.cs]
public ActionResult ChildDatasource(OrdersDetails id, DataManagerRequest dm)
{
ICollection<Employee1Details> empcol = empdata.ToList();
if (empcol.Count == 0)
{
ChildBindData();
}
var ord = id.EmployeeID;
IEnumerable<Employee1Details> DataSource = empdata.Where(or => or.EmployeeID == ord).ToList();//get the parent grid data in server side while pass this data through addParams
return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
} |