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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

How to add header templates for TreeGrid columns


It is possible to customize the column headers in TreeGrid using columns.headerTemplateID property. We need to map the ID of the template script to this property, of the column in which the header must be customized.

It is also possible to wrap the column header text by setting headerTextOverflow property to wrap.

 

The below code example explains about how to customize the column headers with template in TreeGrid.

<div id="TreeGridContainer" style="height:400px;width:100%"></div>
<script type="text/javascript">
$(function () {
$("#TreeGridContainer").ejTreeGrid({
//...
dataSource: projectData,
headerTextOverflow: "wrap",
columns: [
{ field: "taskName", editType: "stringedit", headerTemplateID: "#projectName" },
{ field: "startDate", editType: "datepicker", headerTemplateID: "#dateTemplate" },
{ field: "resourceId", editType: "dropdownedit", dropdownData: projectResources, editParams: { fields: { text: "resourceName", value: "resourceId" } }, headerTemplateID: "#resource" },
{ field: "duration", editType: "numericedit", headerTemplateID: "#durationTemplate" },
{ field: "progress", editType: "numericedit", headerTemplateID: "#progressTemplate" }
]           
})
}); 
</script>
//Customized  column header Templates for TreeGrid
<script type="text/x-jsrender" id="resource">
<div>
<div>
<img src="Images/treegrid/icon-03.png" width="20" height="20" />
</div>
<div style="position:relative; top:3px;">
Resources 
</div>
</div>
</script>
<script type="text/x-jsrender" id="progressTemplate">
<div>
<div>
<img src="Images/treegrid/icon-05.png" width=" 20" height="20" />
</div>
<div style="position:relative; top:3px;">
Progress
</div>
</div>
</script>
<script type="text/x-jsrender" id="projectName">
<div>
<div>
<img src="Images/treegrid/icon-01.png" width="20" height="20" />
</div>
<div style="position:relative; top:3px;">
Task Name
</div>
</div>
</script>
<script type="text/x-jsrender" id="dateTemplate">
<div>
<div>
<img src="Images/treegrid/icon-04.png" width="20" height="20" />
</div>
<div style="position:relative; top:3px;">
Start Date
</div>
</div>
</script>
<script type="text/x-jsrender" id="durationTemplate">
<div>
<div>
<img src="Images/treegrid/icon-02.png" width="20" height="20" />
</div>
<div style="position:relative; top:2px;">
Duration
</div>
</div>
</script>

 

Customized column header in tree grid.

A Sample to render the TreeGrid with customized column header is available in the following link,

Sample

 

 

 

 

 

 

 

 

 

 

ADD COMMENT
You must log in to leave a comment

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