Articles in this section
Category / Section

How to add header templates for TreeGrid columns

2 mins read

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

 

 

 

 

 

 

 

 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment