)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create a Row template in TreeGrid?

Platform: ASP.NET MVC |
Control: TreeGrid |
Published Date: January 23, 2015 |
Last Revised Date: May 29, 2019

In TreeGrid control, you can customize each row by providing templates or Jsrender script elements. These script elements can be provided as templates for the TreeGrid row using RowTemplateId property. The following is the code example for a simple Jsrender template.

CSHTML

<script id="rowTemplateScript" type="text/x-jsrender”>
<tr>
<td class="border" style='height:30px;'>
<div>{{:#data['EmployeeID']}}</div>
</td>
//..           
</tr>
</script>
<script id="altRowTemplateScript" type="text/x-jsrender”>
<tr>
<td class="border" style='height:30px;' />
<div>{{:#data['EmployeeID']}}</div>
</td>
//..           
</tr>
</script>

For providing alternate row style in TreeGrid using templates, the AltRowTemplateId property can be used. The following code example is for applying templates for MVC TreeGrid rows.

CSHTML

@(Html.EJ().TreeGrid("TreeGridContainer")      
.RowTemplateId("rowTemplateScript")
.AltRowTemplateId("altRowTemplateScript")
)                

The following code snippet explains how to use the row template in MVC TreeGrid control.

CSHTML

<script id="rowTemplateScript" type="text/x-jsrender”>
<tr>
<td class="border" style='height:30px;'>
<div>{{:#data['EmployeeID']}}</div>
</td>
//..           
</tr>
</script>
<script id="altRowTemplateScript" type="text/x-jsrender”>
<tr>
<td class="border" style='height:30px;'>
<div>{{:#data['EmployeeID']}}</div>
</td>
//..           
</tr>
</script>
@(Html.EJ().TreeGrid("TreeGridContainer")      
// ...       
.RowTemplateId("rowTemplateScript")
.AltRowTemplateId("altRowTemplateScript")
.Datasource(ViewBag.datasource)                                             
// ...
)                

 

2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Megatron
Feb 04, 2016
hi How can I add an icon to the row, depending on the data item, like a book icon vs person icon in the same column Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon