@(Html.EJ().Grid<object>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .AllowSorting() .AllowFiltering() .Columns(col => { col.Field("EmployeeID").HeaderText("Employee ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); col.Field("FirstName").HeaderText("First Name").Width(100).Add(); col.Field("Title").Width(120).Add(); col.Field("City").Width(100).Add(); col.Field("Country").Width(100).Add(); }) .ChildGrid(child => { child.Datasource((IEnumerable<object>)ViewBag.datasource2) .QueryString("EmployeeID") .AllowPaging() .AllowSorting() .Columns(col => { col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); col.Field("ShipCity").HeaderText("ShipCity").Width(100).Add(); col.Field("Freight").Width(120).Add(); col.Field("ShipName").Width(100).Add(); }); |
Primary Tables
Employee |
ID |
Name |
DepartmentID |
Department |
ID |
Name |
Project |
ID |
Name |
Relationship Tables
ProjectDepartment |
ID |
ProjectID |
DepartmentID |
Active |
ProjectEmployee |
ID |
ProjectID |
EmployeeID |
Active |
Basically for each project I want to be able to display
Departments in the main grid while showing employees within the sub grid. Now this is doable with the primary tables
(employee and department) using hierarchical grid as per the example on the
syncfusion website. However I want to
incorporate the data stored in the relationship tables as well in the grids
(i.e. showing a checkbox to indicate whether each department is associated with
the project as well as each employee within the department is associated with
the project). By unchecking the check box just simply set the Active columns to false.
ID (from ProjectDepartment) |
Project |
Checkbox |
1 |
First Project |
Yes |
ID (from ProjectEmployee) |
Employee |
Checkbox |
1 |
Krishna |
No |
2 |
Rama |
Yes |
ID (from ProjectDepartment) |
Project |
Checkbox |
2 |
Second Project |
No |
ID (from ProjectEmployee) |
Employee |
Checkbox |
1 |
David |
No |
Regards
Prasanthan
Regards,
Prasanna Kumar N.S.V
View Models
Departmental Project |
ID |
Project Name |
Department Name |
Active |
Employees in Project |
Department Name |
Project Name |
Employee Name |
Active |
Department |
Department
involved with the Project |
|
Sales |
|
Yes |
|
Employee |
Employ working
on Project |
|
Krishna |
No |
|
Rama |
Yes |
Research Development |
||
|
Employee |
Employ working
on Project |
David |
No |
@(Html.EJ().Grid<object>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .AllowSorting() .EditSettings( edit => edit.AllowEditing()) .ClientSideEvents( eve => eve.RowDataBound("querycell").DetailsExpand("expand")) .Columns(col => { col.Field("SupplierID").HeaderText("Supplier ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); col.Field("CompanyName").HeaderText("Company Name").Width(100).Add(); col.Field("ContactName").HeaderText("Contact Name").Width(100).Add(); col.Field("Active").HeaderText("Active").Width(100).EditType(EditingType.Boolean).Add(); }) .ChildGrid(child => { child.Datasource((IEnumerable<object>)ViewBag.datasource2) .QueryString("SupplierID") .AllowPaging() .EditSettings(edit => edit.AllowEditing()) .AllowSorting() .Columns(col => { col.Field("ProductID").Width(120).IsPrimaryKey(true).Add(); col.Field("ProductName").Width(100).Add(); col.Field("CategoryID").Width(100).Add(); col.Field("Discontinued").Width(100).Add(); }); }) )
<script type="text/javascript"> function querycell(args) { if (!args.data.Active) { args.row.find(".e-icon").addClass("e-hide"); } } function expand(args) { if (!args.masterData.Active) { args.cancel = true; args.detailsRow.hide(); } } |