Usage
Signature:
interface TreeViewElement<K, D>
Generic Parameters
Parameter Description K Type of key of the dataprovider D Type of data from the dataprovider
Typescript Import Format
//To typecheck the element APIs, import as below.
import { TreeViewElement } from "ojs/ojtreeview";
//For the transpiled javascript to load the element's module, import as below
import "ojs/ojtreeview";
For additional information visit:
Note: Application logic should not interact with the component's properties or invoke its methods until the BusyContext indicates that the component is ready for interaction.
Styling Classes
-
.oj-treeview-item-content-icon
-
Use this class on any additional icons included in treeview's items to assist with vertical alignment and size.
-
.oj-treeview-item-icon
-
Use this class on the span providing the item icon in the static markup or the item renderer or template slot.
-
.oj-treeview-item-text
-
Use this class on the span providing the item text in the static markup or the item renderer or template slot.
-
CSS Variables
Name | Type | Description |
---|---|---|
--oj-tree-view-row-height |
<length> | Tree view row height |
--oj-tree-view-text-color |
<color> | Tree view text color |
--oj-tree-view-indent-width |
<length> | Tree view indent width |
Slots
JET components that allow child content support slots. Please see the slots section of the JET component overview doc for more information on allowed slot content and slot types.
-
contextMenu
-
The contextMenu slot is set on the
oj-menu
within this element. This is used to designate the JET Menu that this component should launch as a context menu on right-click, Shift-F10, Press & Hold, or component-specific gesture. If specified, the browser's native context menu will be replaced by the JET Menu specified in this slot.The application can register a listener for the Menu's ojBeforeOpen event. The listener can cancel the launch via event.preventDefault(), or it can customize the menu contents by editing the menu DOM directly, and then calling refresh() on the Menu.
To help determine whether it's appropriate to cancel the launch or customize the menu, the ojBeforeOpen listener can use component API's to determine which table cell, chart item, etc., is the target of the context menu. See the JSDoc of the individual components for details.
Keep in mind that any such logic must work whether the context menu was launched via right-click, Shift-F10, Press & Hold, or component-specific touch gesture.
-
itemTemplate
-
The
itemTemplate
slot is used to specify the template for rendering each item in the list. The slot content must be a <template> element. The content of the template could either include the <li> element, in which case that will be used as the root of the item. Or it can be just the content which excludes the <li> element.When the template is executed for each item, it will have access to the binding context containing the following properties:
- $current - an object that contains information for the current item. (See oj.ojTreeView.ItemTemplateContext or the table below for a list of properties available on $current)
- alias - if as attribute was specified, the value will be used to provide an application-named alias for $current.
Properties of $current:
Name Type Description componentElement
Element The <oj-tree-view> custom element. data
D The data for the current item being rendered. depth
number The depth of the current item being rendered. The depth of the first level children under the invisible root is 1. index
number The zero-based index of the current item. key
K The key of the current item being rendered. leaf
boolean True if the current item is a leaf node. metadata
ItemMetadata.<K> The metadata of the item. parentkey
K The key of the parent item. The parent key is null for root nodes.
Attributes
-
(readonly) current-item :K
-
The key of the item that has the browser focus. This is a read-only attribute so page authors cannot set or change it directly.
- Supports writeback:
true
Names
Item Name Property currentItem
Property change event currentItemChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-current-item-changed
-
data :TreeDataProvider.<K, D>
-
The data source for the TreeView. Accepts an instance of TreeDataProvider or TreeDataSource. See the data source section in the introduction for out of the box data source types. If the data attribute is not specified, the child elements are used as content. If there's no content specified, then an empty list is rendered.
- Default Value:
null
Names
Item Name Property data
Property change event dataChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-data-changed
-
dnd :Object
-
Enable drag and drop functionality.
JET provides support for HTML5 Drag and Drop events. Please refer to third party documentation on HTML5 Drag and Drop to learn how to use it.Names
Item Name Property dnd
Property change event dndChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-dnd-changed
-
(nullable) dnd.drag :Object
-
items
: An array of objects, with each object representing the data of one selected item.- Default Value:
null
Properties:
Name Type Description items
Object If this object is specified, TreeView will initiate drag operation when the user drags on an item. Properties
Name Type Argument Description dataTypes
string | Array.<string> <optional>
The MIME types to use for the dragged data in the dataTransfer object. This can be a string if there is only one type, or an array of strings if multiple types are needed.
For example, if selected items of employee data are being dragged, dataTypes could be "application/employees+json". Drop targets can examine the data types and decide whether to accept the data. A text input may only accept "text" data type, while a chart for displaying employee data may be configured to accept the "application/employees+json" type.
For each type in the array, dataTransfer.setData will be called with the specified type and the JSON version of the selected item data as the value. The selected item data is an array of objects, with each object representing a model object from the underlying data source. For example, if the underlying data is an Collection, then this would be a Model object. Note that when static HTML is used, then the value would be the HTML string of the selected item.
This property is required unless the application calls setData itself in a dragStart callback function.drag
function(Event):void <optional>
A callback function that receives the "drag" event as its argument.
dragEnd
function(Event):void <optional>
A callback function that receives the "dragend" event as its argument.
dragStart
?((event: Event, context: {items: Array<D>}) => void) <optional>
A callback function that receives the "dragstart" event and context information as its arguments.
function(event, context)
All of the event payloads listed below can be found under thecontext
argument.
This function can set its own data and drag image as needed. If dataTypes is specified, event.dataTransfer is already populated with the default data when this function is invoked. If dataTypes is not specified, this function must call event.dataTransfer.setData to set the data or else the drag operation will be cancelled. In either case, the drag image is set to an image of the dragged items on the TreeView.Names
Item Name Property dnd.drag
-
(nullable) dnd.drop :Object
-
item
: The item being entered.item
: The item that was last entered.item
: The item being dragged over.item
: The item being dropped on.position
: The drop position relative to the item being dropped on. Valid values are "inside", "before", "after", and "first" (the first child of the item being dropped on).- Default Value:
null
Properties:
Name Type Description items
Object An object that specifies callback functions to handle dropping items
Properties
Name Type Argument Description dataTypes
string | Array.<string> <optional>
A data type or an array of data types this component can accept.
This property is required unless dragEnter, dragOver, and drop callback functions are specified to handle the corresponding events.dragEnter
?((event: Event, context: {item: Element}) => void) <optional>
A callback function that receives the "dragenter" event and context information as its arguments.
function(event, context)
All of the event payloads listed below can be found under thecontext
argument.
This function should callevent.preventDefault()
to indicate the dragged data can be accepted. Otherwise, dataTypes will be matched against the drag dataTypes to determine if the data is acceptable. If there is a match,event.preventDefault()
will be called to indicate that the data can be accepted.dragLeave
?((event: Event, context: {item: Element}) => void) <optional>
A callback function that receives the "dragleave" event and context information as its arguments.
function(event, context)
All of the event payloads listed below can be found under thecontext
argument.
dragOver
?((event: Event, context: {item: Element}) => void) <optional>
A callback function that receives the "dragover" event and context information as its arguments.
function(event, context)
All of the event payloads listed below can be found under thecontext
argument.
This function should callevent.preventDefault()
to indicate the dragged data can be accepted. Otherwise, dataTypes will be matched against the drag dataTypes to determine if the data is acceptable. If there is a match,event.preventDefault()
will be called to indicate that the data can be accepted.drop
function(Event, ojTreeView.ItemsDropOnDropContext):void A required callback function that receives the "drop" event and context information as its arguments.
function(event, context)
All of the event payloads listed below can be found under thecontext
argument.
This function should callevent.preventDefault()
to indicate the dragged data can be accepted.
If the application needs to look at the data for the item being dropped on, it can use theContext.getContextByNode
method.Names
Item Name Property dnd.drop
-
expanded :KeySet.<K>
-
Specifies the key set containing the keys of the TreeView items that should be expanded. Use the KeySetImpl class to specify items to expand. Use the AllKeySetImpl class to expand all items.
- Default Value:
new KeySet()
- Supports writeback:
true
Names
Item Name Property expanded
Property change event expandedChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-expanded-changed
-
item :Object
-
The item attribute contains a subset of attributes for items.
Names
Item Name Property item
Property change event itemChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-item-changed
-
(nullable) item.focusable :((itemContext: ojTreeView.ItemContext<K,D>) => boolean)
-
A function that returns whether the item is focusable. A item that is not focusable cannot be clicked on or navigated to. See itemContext in the introduction to see the object passed into the focusable function. If no function is specified, then all the items will be focusable.
- Deprecated:
-
Since Description 13.0.0
Not accessible by screen reader.
- Default Value:
null
Names
Item Name Property item.focusable
-
(nullable) item.renderer :((itemContext: ojTreeView.ItemContext<K,D>) => {insert: Element|string}|void)|null
-
The renderer function that renders the contents of the item. See itemContext in the introduction to see the object passed into the renderer function. The function should return one of the following:
- An Object with the following property:
- insert: HTMLElement | string - A string or a DOM element of the content inside the item.
- Nothing: If the developer chooses to manipulate the item element directly, the function should return nothing.
- Default Value:
null
Names
Item Name Property item.renderer
- An Object with the following property:
-
(nullable) item.selectable :((itemContext: ojTreeView.ItemContext<K,D>) => boolean)
-
A function that returns whether the item can be selected. If selectionMode is set to "none" this attribute is ignored. In addition, if focusable is set to false, then the selectable option is automatically overridden and set to false also. See itemContext in the introduction to see the object passed into the selectable function. If no function is specified, then all the items will be selectable.
- Default Value:
null
Names
Item Name Property item.selectable
-
scroll-policy-options :Object.<number>|null
-
scrollPolicy options.
The following options are supported:
- maxCount: Maximum rows which will be displayed before fetching more rows will be stopped.
Names
Item Name Property scrollPolicyOptions
Property change event scrollPolicyOptionsChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-scroll-policy-options-changed
-
scroll-policy-options.max-count :number
-
The maximum number of rows which will be displayed before fetching more rows will be stopped.
See the scroll-policy-options attribute for usage examples.
- Default Value:
500
Names
Item Name Property scrollPolicyOptions.maxCount
-
selected :KeySet.<K>
-
The KeySet of the current selected items in the TreeView. An empty KeySet indicates nothing is selected. Note that property change event for the deprecated selection property will still be fired when selected property has changed. In addition, AllKeySetImpl set can be used to represent an select all state. In this case, the value for selection would have an 'inverted' property set to true, and would contain the keys of the items that are not selected.
- Default Value:
new KeySetImpl();
- Supports writeback:
true
Names
Item Name Property selected
Property change event selectedChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-selected-changed
-
selection :Array<K>
-
The current selections in the TreeView. An empty array indicates nothing is selected.
- Deprecated:
-
Since Description 8.0.0
Use selected attribute instead.
- Default Value:
[]
- Supports writeback:
true
Names
Item Name Property selection
Property change event selectionChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-selection-changed
-
selection-mode :"none"|"single"|"multiple"|"leafOnly"
-
The type of selection behavior that is enabled on the TreeView. This attribute controls the number of selections that can be made via selection gestures at any given time.
If
single
ormultiple
is specified, selection gestures will be enabled, and the TreeView's selection styling will be applied to all items specified by the selection and selected attributes. Ifmultiple
is specified oj-selectors will also be rendered by default. Ifnone
is specified, selection gestures will be disabled, and the TreeView's selection styling will not be applied to any items specified by the selection and selected attributes. IfleafOnly
is specified, the selection consists only of leaves, from which parent selection states are derived.oj-selectors will be rendered by default and the selection states of the items will be cascaded, which means that:- If a parent item is selected, then all the descendants will be selected automatically.
- If a parent item is unselected, then all the descendants will be unselected automatically.
- If a parent item has a mixture of selected and unselected descendants, and redwood is enabled then it will display a partially selected state.
Note: In order to compute the selection, in selectionMode
leafOnly
the treeview will trigger continuous fetches until it has the complete data set. We do not recommend using this mode with large data sets and currently mutations are not supported in this mode.Changing the value of this attribute will not affect the value of the selection or selected attributes.
- Default Value:
"none"
Supported Values:
Value Description leafOnly
Multiple items can be selected but children items control the parent's selection state. multiple
Multiple items can be selected at the same time. none
Selection is disabled. single
Only a single item can be selected at a time. Names
Item Name Property selectionMode
Property change event selectionModeChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-selection-mode-changed
-
translations :object|null
-
A collection of translated resources from the translation bundle, or
null
if this component has no resources. Resources may be accessed and overridden individually or collectively, as seen in the examples.If the component does not contain any translatable resource, the default value of this attribute will be
null
. If not, an object containing all resources relevant to the component.If this component has translations, their documentation immediately follows this doc entry.
Names
Item Name Property translations
Property change event translationsChanged
Property change listener attribute (must be of type function, see Events and Listeners for additional information.) on-translations-changed
-
translations.received-data-aria :string
-
Aria Label for when parent node's data has been received.
See the translations attribute for usage examples.
- Default Value:
"Received data for node: {nodeText}"
- Since:
- 12.0.0
Names
Item Name Property translations.receivedDataAria
-
translations.retrieving-data-aria :string
-
Aria Label for when parent node's data is being retrieved.
See the translations attribute for usage examples.
- Default Value:
"Retrieving data for node: {nodeText}"
- Since:
- 12.0.0
Names
Item Name Property translations.retrievingDataAria
-
translations.tree-view-selector-aria :string
-
Aria Label for each treeview row selector
See the translations attribute for usage examples.
- Deprecated:
-
Since Description 15.0.0
This is deprecated because this was a workaround for a JAWS issue that since has been fixed and is no longer used by TreeView.
- Default Value:
"TreeView Selector {rowKey}"
- Since:
- 15.0.0
Names
Item Name Property translations.treeViewSelectorAria
Context Objects
Each context object contains, at minimum, a subId
property,
whose value is a string that identifies a particular DOM node in this element. It can have additional properties to further specify the desired node. See getContextByNode for more details.
Properties:
Name | Type | Description |
---|---|---|
subId |
string | Sub-id string to identify a particular dom node. |
Following are the valid subIds:
-
oj-treeview-item
-
Context for TreeView items.
Properties:
Name Type Description componentElement
Element The TreeView element. data
Object The data object for the item (not available for static content). datasource
oj.TreeDataProvider | oj.TreeDataSource oj.TreeDataProvider A reference to the data source object (not available for static content). depth
number The depth of the item. The depth of the first level children under the invisible root is 1. index
number The index of the item relative to its parent, where 0 is the index of the first item. key
Object The key of the item. leaf
boolean Whether the item is a leaf item. metadata
ItemMetadata.<K> The metadata of the item (not available for static content). parentKey
Object The key of the parent item. The parent key is null for root item.
Events
-
ojAnimateEnd
-
Triggered when the default animation of a particular action has ended. Note this event will not be triggered if application cancelled the default animation on animateStart.
- Deprecated:
-
Since Description 12.1.0
This web component no longer supports this event.
Properties:
All of the event payloads listed below can be found under
event.detail
. See Events and Listeners for additional information. -
ojAnimateStart
-
Triggered when the default animation of a particular action is about to start. The default animation can be cancelled by calling
event.preventDefault()
.- Deprecated:
-
Since Description 12.1.0
This web component no longer supports this event.
Properties:
All of the event payloads listed below can be found under
event.detail
. See Events and Listeners for additional information.Name Type Description action
'expand' | 'collapse' The action that triggered the animation.
See animation section for a list of actions.element
Element The target of animation. endCallback
function():void If the event listener calls event.preventDefault()
to cancel the default animation, it must call the endCallback function when it finishes its own animation handling and when any custom animation ends. -
ojBeforeCollapse
-
Triggered before an item is collapsed via the
expanded
attribute or via the UI. Callevent.preventDefault()
to veto the event, which prevents collapsing the item.Properties:
All of the event payloads listed below can be found under
event.detail
. See Events and Listeners for additional information.Name Type Description item
Element The item to be collapsed. key
K The key of the item to be collapsed. -
ojBeforeCurrentItem
-
Triggered before the current item is changed via the
currentItem
attribute or via the UI. Callevent.preventDefault()
to veto the event, which prevents changing the current item.Properties:
All of the event payloads listed below can be found under
event.detail
. See Events and Listeners for additional information. -
ojBeforeExpand
-
Triggered before an item is expanded via the
expanded
attribute or via the UI. Callevent.preventDefault()
to veto the event, which prevents expanding the item.Properties:
All of the event payloads listed below can be found under
event.detail
. See Events and Listeners for additional information.Name Type Description item
Element The item to be expanded. key
K The key of the item to be expanded. -
ojCollapse
-
Triggered after an item has been collapsed.
Properties:
All of the event payloads listed below can be found under
event.detail
. See Events and Listeners for additional information.Name Type Description item
Element The item that was just collapsed. key
K The key of the item that was just collapsed. -
ojExpand
-
Triggered after an item has been expanded.
Properties:
All of the event payloads listed below can be found under
event.detail
. See Events and Listeners for additional information.Name Type Description item
Element The item that was just expanded. key
K The key of the item that was just expanded.
Methods
-
getContextByNode(node) : {Object|null}
-
Returns an object with context for the given child DOM node. This will always contain the subid for the node, defined as the 'subId' property on the context object. Additional component specific information may also be included. For more details on returned objects, see context objects.
Parameters:
Name Type Argument Description node
Element <not nullable>
The child DOM node Returns:
The context for the DOM node, or
null
when none is found.- Type
- Object | null
-
getProperty(property) : {any}
-
Retrieves the value of a property or a subproperty. The return type will be the same as the type of the property as specified in this API document. If the method is invoked with an incorrect property/subproperty name, it returns undefined.
Parameters:
Name Type Description property
string The property name to get. Supports dot notation for subproperty access. - Since:
- 4.0.0
Returns:
- Type
- any
Example
let subpropValue = myComponent.getProperty('complexProperty.subProperty1.subProperty2');
-
refresh : {void}
-
Refreshes the component.
Returns:
- Type
- void
-
setProperties(properties) : {void}
-
Performs a batch set of properties. The type of value for each property being set must match the type of the property as specified in this API document.
Parameters:
Name Type Description properties
Object An object containing the property and value pairs to set. - Since:
- 4.0.0
Returns:
- Type
- void
Example
myComponent.setProperties({"prop1": "value1", "prop2.subprop": "value2", "prop3": "value3"});
-
setProperty(property, value) : {void}
-
Sets a property or a subproperty (of a complex property) and notifies the component of the change, triggering a [property]Changed event. The value should be of the same type as the type of the attribute mentioned in this API document.
Parameters:
Name Type Description property
string The property name to set. Supports dot notation for subproperty access. value
any The new value to set the property to. - Since:
- 4.0.0
Returns:
- Type
- void
Example
myComponent.setProperty('complexProperty.subProperty1.subProperty2', "someValue");
Type Definitions
-
ItemContext<K,D>
-
Properties:
Name Type Argument Description componentElement
Element The TreeView element. data
D <optional>
The data object of the item (not available for static content). datasource
TreeDataProvider.<K, D> | Object A reference to the data source object (not available for static content). depth
number The depth of the item. The depth of the first level children under the invisible root is 1. index
number The index of the item relative to its parent, where 0 is the index of the first item. key
K The key of the item. leaf
boolean Whether the item is a leaf item. metadata
ItemMetadata.<K> The metadata of the item (not available for static content). parentElement
Element The TreeView item element. The renderer can use this to directly append content. parentKey
K <optional>
The key of the parent item (not available for root item). -
ItemsDropOnDropContext
-
Properties:
Name Type Description item
Element The item being dropped on. position
'inside' | 'before' | 'after' | 'first' The drop position relative to the item being dropped on. -
ItemTemplateContext<K = any,D = any>
-
Properties:
Name Type Description componentElement
Element The <oj-tree-view> custom element. data
D The data for the current item being rendered. depth
number The depth of the current item being rendered. The depth of the first level children under the invisible root is 1. index
number The zero-based index of the current item. key
K The key of the current item being rendered. leaf
boolean True if the current item is a leaf node. metadata
ItemMetadata.<K> The metadata of the item. parentkey
K The key of the parent item. The parent key is null for root nodes.