This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtemplate.tsx
More file actions
59 lines (58 loc) · 2.85 KB
/
template.tsx
File metadata and controls
59 lines (58 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { SampleBase } from '../common/sample-base';
import {TreeViewComponent} from '@syncfusion/ej2-react-navigations';
import './template.css';
export class Template extends SampleBase<{}, {}> {
public mailBox: { [key: string]: Object }[] = [
{ id: 1, name: 'Favorites', hasChild: true },
{ id: 2, pid: 1, name: 'Sales Reports', count: '4' },
{ id: 3, pid: 1, name: 'Sent Items' },
{ id: 4, pid: 1, name: 'Marketing Reports ', count: '6'},
{ id: 5, name: 'My Folder', hasChild: true, expanded: true },
{ id: 6, pid: 5, name: 'Inbox', selected: true , count: '20'},
{ id: 7, pid: 5, name: 'Drafts', count: '5'},
{ id: 8, pid: 5, name: 'Deleted Items'},
{ id: 9, pid: 5, name: 'Sent Items' },
{ id: 10, pid: 5, name: 'Sales Reports' , count: '4'},
{ id: 11, pid: 5, name: 'Marketing Reports', count: '6' },
{ id: 12, pid: 5, name: 'Outbox'},
];
private fields: Object = { dataSource: this.mailBox, id: 'id', parentID: 'pid', text: 'name', hasChildren: 'hasChild' };
private cssClass: string = "template-tree";
private nodeTemplate(data: any): JSX.Element {
return (
<div>
<div className="treeviewdiv">
<div className="textcontent">
<span className="treeName">{data.name}</span>
</div>
{ data.count &&
<div className="countcontainer">
<span className="treeCount e-badge e-badge-primary" >{data.count}</span>
</div>
}
</div>
</div>
)};
render() {
return (
<div className = 'control-pane'>
<div className='control-section'>
<div className='tree-control-wrapper'>
{/* Render the TreeView using template option */}
<TreeViewComponent fields={this.fields} nodeTemplate={this.nodeTemplate as any} cssClass={this.cssClass}/>
</div>
</div>
<div id="action-description">
<p>This sample demonstrates the template functionalities of the TreeView. Select the root node by clicking on it, or expand the root node and select the customized child node.</p>
</div>
<div id="description">
<p>The <code>TreeView</code> component has an option to customize the node structure through the <code>nodeTemplate</code> property, so that the tree node can be formed with any custom structure.</p>
<p>In this demo, the node is formed as like webmail with folder name and number of unread messages.</p>
<p>For more information, you can refer to the <a href="http://ej2.syncfusion.com/react/documentation/treeview/template.html" target="_blank">Templates</a> section from the documentation.</p>
</div>
</div>
)
}
}