OrganizationChart visualizes hierarchical organization data.
import { OrganizationChart } from 'primereact/organizationchart';
<script src="https://unpkg.com/primereact/core/core.min.js"></script>
<script src="https://unpkg.com/primereact/organizationchart/organizationchart.min.js"></script>
OrganizationChart requires a model of TreeNode as its value.
export const OrganizationChartDemo = () => {
const data = [{
label: 'F.C Barcelona',
expanded: true,
children: [
{
label: 'F.C Barcelona',
expanded: true,
children: [
{
label: 'Chelsea FC'
},
{
label: 'F.C. Barcelona'
}
]
},
{
label: 'Real Madrid',
expanded: true,
children: [
{
label: 'Bayern Munich'
},
{
label: 'Real Madrid'
}
]
}
]
}];
return (
<OrganizationChart value={data}></OrganizationChart>
)
}
Label of the treenode is displayed inside the node content by default and templating enables further customization.
<OrganizationChart value={data} nodeTemplate={nodeTemplate}></OrganizationChart>
const nodeTemplate = (node) => {
if (node.type === "person") {
return (
<div>
<div className="node-header">{node.label}</div>
<div className="node-content">
<img alt={node.data.avatar} src={`images/organization/${node.data.avatar}`} style={{ width: '32px' }}/>
<div>{node.data.name}</div>
</div>
</div>
);
}
if (node.type === "department") {
return node.label;
}
}
In order to display a treenode as expanded by default, set "expanded" property as true in your model.
OrganizationChart supports two selection methods; single or multiple. Selection is enabled by setting selectionMode property to the corresponding mode, defining selection property along with selectionChange callback.
<OrganizationChart value={data} selectionMode="single" selection={selectedNode} onSelectionChange={event => setSelectedNode(event.data)}></OrganizationChart>
Name | Type | Default | Description |
---|---|---|---|
id | string | null | Unique identifier of the element. |
value | array | null | An array of nested TreeNodes. |
style | string | null | Inline style of the component. |
className | string | null | Style class of the component. |
selectionMode | string | null | Defines the selection mode, valid values "single" and "multiple". |
selection | any | null | A single treenode instance or an array to refer to the selections. |
nodeTemplate | function | null | Template function that gets a node as a parameter and returns a content. |
Name | Parameters | Description |
---|---|---|
onNodeSelect | event.originalEvent: browser event event.node: Selected node instance. | Callback to invoke when a node is selected. |
onNodeUnselect | event.originalEvent: browser event event.node: Unselected node instance. | Callback to invoke when a node is unselected. |
onSelectionChange | event.originalEvent: browser event event.data: New selection. | Callback to invoke when node selection changes. |
Following is the list of structural style classes.
Name | Element |
---|---|
p-organizationchart | Container element. |
p-organizationchart-table | Table container of a node. |
p-organizationchart-lines | Connector lines container. |
p-organizationchart-nodes | Contained of node children. |
p-organizationchart-line-right | Right side line of a node connector. |
p-organizationchart-line-left | Left side line of a node connector. |
p-organizationchart-line-top | Top side line of a node connector. |
This section is under development. After the necessary tests and improvements are made, it will be shared with the users as soon as possible.
None.
Built-in component themes created by the PrimeReact Theme Designer.
Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.
Beautifully crafted premium create-react-app application templates by the PrimeTek design team.