How can I help you?
Template in EJ2 JavaScript TreeView control
5 Mar 20258 minutes to read
The TreeView control allows you to customize the look of TreeView nodes by using the nodeTemplate property. This property accepts either a template string or an HTML element ID.
In the following sample, employee information such as employee photo, name, and designation has been included using the nodeTemplate property.
The template expression should be provided inside the ${...} interpolation syntax.
ej.base.enableRipple(true);
var employees = [
{ id: 1, name: 'Steven Buchanan', eimg: '10', job: 'CEO', hasChild: true, expanded: true },
{ id: 2, pid: 1, name: 'Laura Callahan', eimg: '2', job: 'Product Manager', hasChild: true },
{ id: 3, pid: 2, name: 'Andrew Fuller', eimg: '7', job: 'Team Lead', hasChild: true },
{ id: 4, pid: 3, name: 'Anne Dodsworth', eimg: '1', job: 'Developer' },
{ id: 5, pid: 1, name: 'Nancy Davolio', eimg: '4', job: 'Product Manager', hasChild: true },
{ id: 6, pid: 5, name: 'Michael Suyama', eimg: '9', job: 'Team Lead', hasChild: true },
{ id: 7, pid: 6, name: 'Robert King', eimg: '8', job: 'Developer ' },
{ id: 8, pid: 7, name: 'Margaret Peacock', eimg: '6', job: 'Developer' },
{ id: 9, pid: 1, name: 'Janet Leverling', eimg: '3', job: 'HR' },
];
var treeObj = new ej.navigations.TreeView({
fields: { dataSource: employees, id: 'id', parentID: 'pid', text: 'name', hasChildren: 'hasChild' },
cssClass: 'custom',
nodeTemplate: '#treeTemplate'
});
treeObj.appendTo('#tree');#container {
visibility: hidden;
}
#loader {
color: #008cff;
height: 40px;
width: 30%;
position: absolute;
font-family: 'Helvetica Neue', 'calibiri';
font-size: 14px;
top: 45%;
left: 45%;
}