Skip to main content

Organisation unit tree

This component is under development. Advanced functionality is planned. Basic functionality, outlined below, is available now.

An organisation unit tree is used to choose organisation units from a hierarchy.

Demo

Usage

When to use

  • Choosing organisation units: Use when one or more organisation units can be chosen.

Format

  • An organisation unit tree can grow when units are expanded. Make sure the container can handle overflowing content by scrolling.
  • Choosing organisation units can be a complex task when there are a lot to choose from. In complex situations, make sure there is room to look at the tree clearly.

Options

Selection mode: Single

Demo
  • In Single selection mode only one organisation unit can be chosen.
  • Use this mode when choosing more than one organisation unit isn't valid.

API Reference

OrganisationUnitTreeRootError

Usage

To use OrganisationUnitTreeRootError, you can import the component from the @dhis2/ui library

import { OrganisationUnitTreeRootError } from '@dhis2/ui'

Props

NameTypeDefaultRequiredDescription
errorstring*
dataTeststring'dhis2-uiwidgets-orgunittree-error'

OrganisationUnitTreeRootLoading

Usage

To use OrganisationUnitTreeRootLoading, you can import the component from the @dhis2/ui library

import { OrganisationUnitTreeRootLoading } from '@dhis2/ui'

Props

NameTypeDefaultRequiredDescription
dataTeststring'dhis2-uiwidgets-orgunittree-loading'

OrganisationUnitTree

Usage

To use OrganisationUnitTree, you can import the component from the @dhis2/ui library

import { OrganisationUnitTree } from '@dhis2/ui'

Props

NameTypeDefaultRequiredDescription
rootsstring │ arrayOf(string)*Root org unit ID(s)
onChangefunction*Will be called with the following object:
{ id: string, displayName: string, path: string, checked: boolean, selected: string[] }
autoExpandLoadingErrorbooleanWhen set, the error when loading children fails will be shown automatically
dataTeststring'dhis2-uiwidgets-orgunittree'
disableSelectionbooleanWhen set to true, no unit can be selected
expandedcustom(function)
filterarrayOf(custom)[]All organisation units with a path that includes the provided paths will be shown.
All others will not be rendered. When not provided, all org units will be shown.
forceReloadbooleanWhen true, everything will be reloaded. In order to load it again after reloading, forceReload has to be set to false and then to true again
handleCollapsecustom(function)
handleExpandcustom(function)
highlightedarrayOf(custom)[]All units provided to "highlighted" as path will be visually
highlighted.
Note:
The d2-ui component used two props for this:
* searchResults
* highlightSearchResults
initiallyExpandedarrayOf(custom)[]An array of OU paths that will be expanded automatically
as soon as they are encountered.
The path of an OU is the UIDs of the OU
and all its parent OUs separated by slashes (/)
Note: This replaces "openFirstLevel" as that's redundant
isUserDataViewFallbackbooleanWhen provided, the 'isUserDataViewFallback' option will be sent when requesting the org units
renderNodeLabelfunctiondefaultRenderNodeLabelRenders the actual node component for each leaf, can be used to
customize the node. The default function just returns the node's
displayName

Shape of the object passed to the callback:
<br/>{<br/> label: string,<br/> node: {<br/> displayName: string,<br/> id: string,<br/> // Only provided once `loading` is false<br/> path?: string,<br/> // Only provided once `loading` is false<br/> children?: Array.<{<br/> id: string,<br/> path: string,<br/> displayName: string<br/> }><br/> },<br/> loading: boolean,<br/> error: string,<br/> open: boolean,<br/> selected: string[],<br/> singleSelection: boolean,<br/> disableSelection: boolean,<br/>}<br/>
selectedarrayOf(custom)[]An array of paths of selected OUs. The path of an OU is the UIDs of the OU and all its parent OUs separated by slashes (/)
singleSelectionbooleanWhen set, no checkboxes will be displayed and only the first selected path in selected will be highlighted
suppressAlphabeticalSortingbooleanTurns off alphabetical sorting of units
onChildrenLoadedfunctionCalled with the children's data that was loaded
onCollapsefunctionCalled with { path: string } with the path of the parent of the level closed
onExpandfunctionCalled with { path: string } with the path of the parent of the level opened