Here is the view:
@(Html.Kendo().Grid<StudyViewModel>()
.Name("StudyGrid")
.Columns(columns =>
{
columns.Bound(item => item.StudyID);
columns.Bound(item => item.StudyName);
columns.Bound(item => item.StudyDirectorName);
columns.ForeignKey(p => p.NatureOfStudy, (IEnumerable<LRRI.QAM.ViewModels.NatureOfStudyWithIDViewModel>)ViewData["NatureOfStudyList"], "NatureOfStudyID", "NatureOfStudy");
columns.ForeignKey(p => p.Status, (IEnumerable<LRRI.QAM.ViewModels.StudyStatusWithIDViewModel>)ViewData["StudyStatusList"], "StudyStatusID", "StudyStatus");
columns.ForeignKey(p => p.Active, (IEnumerable)ViewData["ActiveList"], "ActiveID", "Active");
})
.ClientDetailTemplateId("studyRegulatoryReferenceTemplate")
.DataSource(ds => ds
.Ajax()
.Model(model =>
{
model.Id(m => m.StudyID);
})
.Sort(sort =>
{
// Sort by Name in descending order
sort.Add(m => m.StudyName).Ascending();
})
.Read(read => read.Action("StudyDataSource", "Study"))
)
.Pageable()
.Sortable()
.Filterable()
)
<script id="studyRegulatoryReferenceTemplate" type="text/kendo-tmpl">
@(Html.Kendo().Grid<LRRI.QAM.Models.StudyRegulatoryReference>()
.Name("RegRef_#=StudyID#")
.Columns(columns =>
{
columns.Bound(o => o.RegulatoryReferenceID);
columns.Bound(o => o.RegulatoryReference);
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("HierarchyBinding_RegulatoryReference", "Study", new { studyID = "#=StudyID#" }))
)
.Sortable()
.ToClientTemplate()
)
</script>
Here is the controller:
public ActionResult StudyDataSource([DataSourceRequest] DataSourceRequest request)
{
var listValues = (from l in _context.Studies
orderby l.StudyName
select new QAM.ViewModels.StudyViewModel()
{
StudyID = l.StudyID,
StudyName = l.StudyName,
ProtocolNumber = l.Protocol.ProtocolNumber,
StudyDirectorFirst = l.StudyDirectorFirst,
StudyDirectorLast= l.StudyDirectorLast,
StudyDirectorName = l.StudyDirectorFirst + " " + l.StudyDirectorLast,
NatureOfStudy = l.NatureOfStudy,
RouteOfAdmin = l.RouteOfAdmin,
Status = l.Status,
StudyType = l.StudyType,
GLP = (((Boolean?)l.GLP ?? false) ? 1 : 0),
Active = (((Boolean?)l.Active ?? false) ? 1 : 0)
});
return Json(listValues.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
public ActionResult HierarchyBinding_RegulatoryReference(int studyID, [DataSourceRequest] DataSourceRequest request)
{
var listValues =
_context.StudyRegulatoryReferences.Where(l => (l.StudyID == studyID))
.OrderBy(l => l.RegulatoryReference);
return Json(listValues.ToDataSourceResult(request));
}