- Home
- Forum
- ASP.NET MVC
- Hierarchical - Parent and Child Select
Hierarchical - Parent and Child Select
Thanks for contacting Syncfusion support.
Hierarchy Grid feature is used to render the Grid inside the grid row. To view the child grid, we use the expand button in each row of the parent grid. The child grid data has been bound based on the foreign key field to querystring property.
Please find the code example, screenshot and sample:
|
@(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(); }); |
Screenshot:
Sample: http://www.syncfusion.com/downloads/support/forum/121558/ze/Sample145862508394122
Hierarchy Grid: http://help.syncfusion.com/aspnetmvc/grid/hierarchy-grid
Refer the online sample for hierarchy grid
Online Sample: http://mvc.syncfusion.com/demos/web/grid/hierarchygrid
If we misunderstood your query, please confirm the following details.
Query : “And once that's done Employees within the selected department can be chosen (via check box on grid row) in the child grid?”
Could you please elaborate the above query?, it will help us to provide the prompt solution.
Query: Perhaps this can be done on Master-Details or TreeGrid or TreeView controls too?
Treeview control will be well suited for your requirement as TreeGrid control is designed to load values across multiple columns.
Regards,
Jayaprakash K
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
Thanks for your New Year wishes and please accept the same from us.
We have analyzed your question and identified the following requirements. Would you review this and let us know if we have missed anything?
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 |
Thanks for providing additional information.
Your requirement has been achieved using rowDataBound and detailExpand events of ejGrid. rowDataBound event triggers every time a request is made to access particular row information and we can get the row details in the arguments. Using that, we check the condition with column value and hide the expand button by adding the class name.
In detailExpand, event we can get the data in the arguments. Using we check the condition with Active and hide the details row element.
Please find the code example and sample:
|
@(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(); } } |
Sample: http://www.syncfusion.com/downloads/support/forum/121558/ze/Sample145862185212000
Refer to the Help documents for the rowDataBound and detailExpand events.
http://help.syncfusion.com/js/api/ejgrid#events:rowdatabound
http://help.syncfusion.com/js/api/ejgrid#events:detailsexpand
Regards,
Prasanna Kumar N.S.V
- 5 Replies
- 3 Participants
-
PR Prasanth
- Dec 30, 2015 08:44 PM UTC
- Jan 6, 2016 09:59 AM UTC