- Home
- Forum
- ASP.NET MVC
- Hide header row in child grid + custom background in child grid + expand only certain parents based on one of their model properties
Hide header row in child grid + custom background in child grid + expand only certain parents based on one of their model properties
Thanks for using Syncfusion products.
Query 1: Child rows shouldn't have an header
We can get the child grid’s header element using “getHeaderTable” method and remove it in “Create” event of the child grid as follows,
|
@(Html.EJ().Grid<object>("HierarchyGrid") .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource) .ChildGrid(child => .ClientSideEvents(eve => { eve.Create("childCreate"); });
})
<script type="text/javascript"> function childCreate(args) {
this.getHeaderTable().remove(); |
Refer to the below link for more clarification about getHeaderTable method,
http://help.syncfusion.com/js/api/ejgrid#methods:getheadertable
Query 2: Child rows background should be gray so that it's more clear that they refer to child elements
We can differ the odd rows and even rows for the grid using “e-row” and “e-alt_row” classes of the “tr” elements.
Refer to the below code example for setting background color for the child grid (“.e-childGrid”) rows,
|
<style type="text/css"> .e-childGrid .e-row { background-color: grey; } .e-childGrid .e-alt_row { background-color:lightgrey; } </style>
@(Html.EJ().Grid<object>("HierarchyGrid") . . . . . . . . . . . . .ChildGrid(child => { . . . . . . . . //Adding class for the child grid element .CssClass("e-childGrid")
})
)
|
Refer to the below link for more clarification about “cssClass“ property,
http://help.syncfusion.com/js/api/ejgrid#members:cssclass
Query 3: Instead of expanding each and every parent row, only parent rows with a certain Model value should be expanded
We can achieve your requirement in RowDataBound event of the parent grid as follows,
|
@(Html.EJ().Grid<object>("HierarchyGrid")
)
<script type="text/javascript">
function dataBound(args) { if (args.data.City == "London") this.expandCollapse($(args.row.find(".e-detailrowcollapse"))); } </script> |
Refer to the below link for more clarification about “expandCollapse” method,
We have created a sample with the above code examples and the same can be downloaded from the following link,
http://www.syncfusion.com/downloads/support/directtrac/general/MVCAPP~2576413506.ZIP
Regards,
Gowthami V.
We are happy to hear that your requirement has been achieved.
Thanks & Regards,
Gowthami V.
Attachment: cell_text_from_post_77482cfa.7z
We have analyzed your requirement and we can achieve your requirement partially.
We have analyzed your requirement and we can achieve it partially. If we add a cell for the particular child row, then the next child rows gets misaligned due to the addition of an extra “td” element to the row.
To avoid this, we have loaded the text to the existing child row cell instead of adding a new cell in “DataBound” event of the parent Grid as follows,
|
@(Html.EJ().Grid<object>("HierarchyGrid") . . . . . . . . .ClientSideEvents(eve => { eve.DataBound("dataBound").RowDataBound("rowDataBound");}) .ChildGrid(child => { child.Datasource((IEnumerable<object>)ViewBag.datasource1) .QueryString("EmployeeID") . . . . . . . . })
)
<script type="text/javascript"> function dataBound(args) {
$(".btn").ejButton({
text: "click", click: function (args) { $(this.element.closest("tr").find("td")[1]).load("/Grid/GetData", {data: parseInt($(this.element.closest("tr").find("td")[1]).text()) });
} }); }
|
We have created a sample with the above requirement and the same can be downloaded from the following link,
http://www.syncfusion.com/downloads/support/directtrac/general/ze/MvcApplication4-1910659991.zip
Refer to the below screenshot,
Regards,
Gowthami V.
We are happy to hear that your issue has been resolved.
Get back to us if you need further assistance.
Regards,
Seeni Sakthi Kumar S.
|
@(Html.EJ().Grid<object>("HierarchyGrid")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource) .Adaptor(AdaptorType.RemoteSaveAdaptor)) . . . . .ChildGrid(child => //child grid
{ . . . . . . . . .ClientSideEvents(eve => { eve.Create("childCreate"); }); //create event in child grid
})
)
<script type="text/javascript"> function childCreate(args)
{
this.getHeaderTable().remove();
} </script> |
From the above code example we have bound the Create event for the child grid and from that we have remove the header element of child grid using getHeaderTable method in grid.
Refer to the below link for more clarification about getHeaderTable method and Create event in grid.
https://help.syncfusion.com/api/js/ejgrid#methods:getheadertable
- 10 Replies
- 5 Participants
-
CA Carlo
- Dec 22, 2015 04:14 PM UTC
- Apr 28, 2017 09:52 AM UTC