[Index.cshtml]
public ActionResult Index()
{
var ds = new NorthwindDataContext();
var query = from emp in ds.EmployeeViews select emp;
ViewBag.datasource = query.ToList();
ViewBag.data = new NorthwindDataContext().OrdersViews.ToList();
var DetailData = new NorthwindDataContext().OrdersViews.Where(ord => ord.EmployeeID == 1).Take(5).ToList();
ViewBag.dataSource1 = DetailData;
return View();
} |
[Index.cshtml]
@(Html.EJ().Grid<EmployeeView>("MasterGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.Columns(col =>
{
...
})
.ClientSideEvents(eve => { eve.RowSelected("rowSelected"); })
)
<div class="label1">
Detail Grid
</div>
@(Html.EJ().Grid<OrdersView>("DetailGrid")
.Datasource((IEnumerable<object>)ViewBag.dataSource1)
.Columns(col =>
{
...
})
)
<script type="text/javascript">
$(function () {
window.rowSelected = function (args) {
var value = args;
$.ajax({
type: "POST",
url: "/Home/Event",
success: function (data) {
var employeeID = value.data.EmployeeID; //get the EmployeeId value to filter the data
var datasource = data;
var detaildata = ej.DataManager(datasource).executeLocal(ej.Query().where("EmployeeID", ej.FilterOperators.equal, employeeID, false).take(10));
var gridObj = $("#DetailGrid").ejGrid("instance");
gridObj.dataSource(ej.DataManager(detaildata.slice(0, 5)));
},
});
}
});
</script>
[Controller.cs]
public ActionResult Event()
{
var ds = new NorthwindDataContext();
var data = from ord in ds.OrdersViews select ord;
ViewBag.datasource = data.ToList();
return Json(data, JsonRequestBehavior.AllowGet);
} |
[Index.cshtml]
success: function (data) {
var employeeID = value.data.EmployeeID;
var datasource = data;
var detaildata = ej.DataManager(datasource).executeLocal(ej.Query().where(ej.Predicate('EmployeeID', ej.FilterOperators.equal, 1, true).and('CustomerID', ej.FilterOperators.startsWith, 'V', true)).take(5));
var gridObj = $("#DetailGrid").ejGrid("instance");
gridObj.dataSource(ej.DataManager(detaildata.slice(0, 5)));
},
}); |