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.
Slots
JET elements can have up to two types of child content:
- Any child element with a
slotattribute will be moved into that named slot, e.g.<span slot='startIcon'>...</span>. All supported named slots are documented below. Child elements with unsupported named slots will be removed from the DOM. - Any child element lacking a
slotattribute will be moved to the default slot, also known as a regular child.
-
contextMenu
-
The contextMenu slot is set on the
oj-menuwithin 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 and demos 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.
Example
Initialize the component with a context menu:
<oj-some-element> <-- use the contextMenu slot to designate this as the context menu for this component --> <oj-menu slot="contextMenu" style="display:none" aria-label="Some element's context menu"> ... </oj-menu> </oj-some-element>
Attributes
-
(readonly) current-item :any
-
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 currentItemProperty change event currentItemChangedProperty change listener attribute (must be of type function) on-current-item-changedExample
Get the current item:
myTreeView.currentItem; -
data :oj.TreeDataSource
-
The data source for the TreeView. Accepts an instance of oj.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 dataProperty change event dataChangedProperty change listener attribute (must be of type function) on-data-changedExample
Initialize the TreeView with an oj.Collection:
myTreeView.data = new oj.CollectionTableDataSource(collection); -
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 dndProperty change event dndChangedProperty change listener attribute (must be of type function) on-dnd-changed -
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 itemsObject If this object is specified, TreeView will initiate drag operation when the user drags on an item. Properties
Name Type Argument Description dataTypesstring | Array.<string> <optional>
(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 oj.Collection, then this would be a oj.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.dragStartfunction(Event, {items: Array.<D>}):void <optional>
(optional) A callback function that receives the "dragstart" event and context information as arguments:
function(event, context)
All of the event payloads listed below can be found under thecontextargument.
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.dragfunction(Event):void <optional>
(optional) A callback function that receives the "drag" event as argument:
function(event)
dragEndfunction(Event):void <optional>
(optional) A callback function that receives the "dragend" event as argument:
function(event)
Names
Item Name Property dnd.dragExample
Initialize the TreeView such that only leaf items are focusable:
myTreeView.setProperty('dnd.drag.items', { 'dataTypes': ['application/ojtreeviewitems+json'], 'dragEnd': handleDragEnd }); -
dnd.drop :Object
-
item: The item being entered.item: The item being dragged over.item: The item that was last entered.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 itemsObject An object that specifies callback functions to handle dropping items
Properties
Name Type Argument Description dataTypesstring | 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.dragEnterfunction(Event, {item: Element}):void <optional>
(optional) A callback function that receives the "dragenter" event and context information as arguments:
function(event, context)
All of the event payloads listed below can be found under thecontextargument.
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.dragOverfunction(Event, {item: Element}):void <optional>
(optional) A callback function that receives the "dragover" event and context information as arguments:
function(event, context)
All of the event payloads listed below can be found under thecontextargument.
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.dragLeavefunction(Event, {item: Element}):void <optional>
(optional) A callback function that receives the "dragleave" event and context information as arguments:
function(event, context)
All of the event payloads listed below can be found under thecontextargument.
dropfunction(Event, oj.ojTreeView.ItemsDropOnDropContext):void (required) A callback function that receives the "drop" event and context information as arguments:
function(event, context)
All of the event payloads listed below can be found under thecontextargument.
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 thegetContextByNodemethod.Names
Item Name Property dnd.dropExample
Initialize the TreeView such that only leaf items are focusable:
myTreeView.setProperty('dnd.drop.items', { 'dataTypes': ['application/ojtreeviewitems+json'], 'drop': handleDrop }); -
expanded :KeySet
-
Specifies the key set containing the keys of the TreeView items that should be expanded. Use the ExpandedKeySet class to specify items to expand. Use the ExpandAllKeySet class to expand all items.
- Default Value:
new ExpandedKeySet()
- Supports writeback:
true
Names
Item Name Property expandedProperty change event expandedChangedProperty change listener attribute (must be of type function) on-expanded-changedExample
Initialize the TreeView with some expanded items:
myTreeView.expanded = new keySet.ExpandedKeySet(['item1', 'item2']); -
item :Object
-
The item attribute contains a subset of attributes for items.
Names
Item Name Property itemProperty change event itemChangedProperty change listener attribute (must be of type function) on-item-changed -
(nullable) item.focusable :((itemContext: oj.ojTreeView.ItemContext
) => 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.
- Default Value:
null
Names
Item Name Property item.focusableExample
Initialize the TreeView such that only leaf items are focusable:
myTreeView.setProperty('item.focusable', function(itemContext) { return itemContext['leaf']; }); -
(nullable) item.renderer :((itemContext: oj.ojTreeView.ItemContext
) => {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.rendererExample
Initialize the TreeView with a renderer:
myTreeView.setProperty('item.renderer', function(itemContext) { return itemContext['data'].get('FIRST_NAME'); }); - An Object with the following property:
-
(nullable) item.selectable :((itemContext: oj.ojTreeView.ItemContext
) => boolean) -
A function that returns whether the item can be selected. If selectionMode is set to "none" this attribute is ignored. 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.selectableExample
Initialize the TreeView such that only leaf items are selectable:
myTreeView.setProperty('item.selectable', function(itemContext) { return itemContext['leaf']; }); -
selection :Array.<any>
-
The current selections in the TreeView. An empty array indicates nothing is selected.
- Default Value:
[]
- Supports writeback:
true
Names
Item Name Property selectionProperty change event selectionChangedProperty change listener attribute (must be of type function) on-selection-changedExample
Initialize the TreeView with specific selection:
myTreeView.selection = ['item1', 'item2']; -
selection-mode :string
-
Specifies whether selection can be made and the cardinality of selection in the TreeView.
- Default Value:
"none"
Supported Values:
Name Type Description "multiple"string Multiple items can be selected at the same time. "none"string Selection is disabled. "single"string Only one item can be selected at a time. Names
Item Name Property selectionModeProperty change event selectionModeChangedProperty change listener attribute (must be of type function) on-selection-mode-changedExample
Initialize the tree view to enable multiple selection:
myTreeView.selectionMode = 'multiple'; -
translations :Object|null
-
A collection of translated resources from the translation bundle, or
nullif 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 translationsProperty change event translationsChangedProperty change listener attribute (must be of type function) on-translations-changedExamples
Initialize the component, overriding some translated resources and leaving the others intact:
<!-- Using dot notation --> <oj-some-element translations.some-key='some value' translations.some-other-key='some other value'></oj-some-element> <!-- Using JSON notation --> <oj-some-element translations='{"someKey":"some value", "someOtherKey":"some other value"}'></oj-some-element>Get or set the
translationsproperty after initialization:// Get one var value = myComponent.translations.someKey; // Set one, leaving the others intact. Always use the setProperty API for // subproperties rather than setting a subproperty directly. myComponent.setProperty('translations.someKey', 'some value'); // Get all var values = myComponent.translations; // Set all. Must list every resource key, as those not listed are lost. myComponent.translations = { someKey: 'some value', someOtherKey: 'some other value' };
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 componentElementElement The TreeView element. dataObject The data object for the item (not available for static content). datasourceoj.TreeDataSource A reference to the data source object (not available for static content). depthnumber The depth of the item. The depth of the first level children under the invisible root is 1. indexnumber The index of the item relative to its parent, where 0 is the index of the first item. keyObject the key of the item. leafboolean Whether the item is a leaf item. parentKeyObject 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.
Properties:
All of the event payloads listed below can be found under
event.detail.Name Type Description action'expand' | 'collapse' The action that started the animation. See animation section for a list of actions. elementElement The target of animation. Examples
Specify an
ojAnimateEndlistener via the DOM attribute:<oj-tree-view on-oj-animate-end='[[listener]]'></oj-tree-view>Specify an
ojAnimateEndlistener via the JavaScript property:myTreeView.onOjAnimateEnd = listener;Add an
ojAnimateEndlistener via theaddEventListenerAPI:myTreeView.addEventListener('ojAnimateEnd', listener); -
ojAnimateStart
-
Triggered when the default animation of a particular action is about to start. The default animation can be cancelled by calling
event.preventDefault().Properties:
All of the event payloads listed below can be found under
event.detail.Name Type Description action'expand' | 'collapse' The action that starts the animation. See animation section for a list of actions. elementElement The target of animation. endCallbackfunction():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.Examples
Specify an
ojAnimateStartlistener via the DOM attribute:<oj-tree-view on-oj-animate-start='[[listener]]'></oj-tree-view>Specify an
ojAnimateStartlistener via the JavaScript property:myTreeView.onOjAnimateStart = listener;Add an
ojAnimateStartlistener via theaddEventListenerAPI:myTreeView.addEventListener('ojAnimateStart', listener); -
ojBeforeCollapse
-
Triggered before an item is collapsed via the
expandedattribute 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.Name Type Description keyany The key of the item to be collapsed. itemElement The item to be collapsed. Examples
Specify an
ojBeforeCollapselistener via the DOM attribute:<oj-tree-view on-oj-before-collapse='[[listener]]'></oj-tree-view>Specify an
ojBeforeCollapselistener via the JavaScript property:myTreeView.onOjBeforeCollapse = listener;Add an
ojBeforeCollapselistener via theaddEventListenerAPI:myTreeView.addEventListener('ojBeforeCollapse', listener); -
ojBeforeCurrentItem
-
Triggered before the current item is changed via the
currentItemattribute 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.Name Type Description previousKeyany The key of the previous item. previousItemElement The previous item. keyany The key of the new current item. itemElement The new current item. Examples
Specify an
ojBeforeCurrentItemlistener via the DOM attribute:<oj-tree-view on-oj-before-current-item='[[listener]]'></oj-tree-view>Specify an
ojBeforeCurrentItemlistener via the JavaScript property:myTreeView.onOjBeforeCurrentItem = listener;Add an
ojBeforeCurrentItemlistener via theaddEventListenerAPI:myTreeView.addEventListener('ojBeforeCurrentItem', listener); -
ojBeforeExpand
-
Triggered before an item is expanded via the
expandedattribute 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.Name Type Description keyany The key of the item to be expanded. itemElement The item to be expanded. Examples
Specify an
ojBeforeExpandlistener via the DOM attribute:<oj-tree-view on-oj-before-expand='[[listener]]'></oj-tree-view>Specify an
ojBeforeExpandlistener via the JavaScript property:myTreeView.onOjBeforeExpand = listener;Add an
ojBeforeExpandlistener via theaddEventListenerAPI:myTreeView.addEventListener('ojBeforeExpand', listener); -
ojCollapse
-
Triggered after an item has been collapsed.
Properties:
All of the event payloads listed below can be found under
event.detail.Name Type Description keyany The key of the item that was just collapsed. itemElement The item that was just collapsed. Examples
Specify an
ojCollapselistener via the DOM attribute:<oj-tree-view on-oj-collapse='[[listener]]'></oj-tree-view>Specify an
ojCollapselistener via the JavaScript property:myTreeView.onOjCollapse = listener;Add an
ojCollapselistener via theaddEventListenerAPI:myTreeView.addEventListener('ojCollapse', listener); -
ojExpand
-
Triggered after an item has been expanded.
Properties:
All of the event payloads listed below can be found under
event.detail.Name Type Description keyany The key of the item that was just expanded. itemElement The item that was just expanded. Examples
Specify an
ojExpandlistener via the DOM attribute:<oj-tree-view on-oj-expand='[[listener]]'></oj-tree-view>Specify an
ojExpandlistener via the JavaScript property:myTreeView.onOjExpand = listener;Add an
ojExpandlistener via theaddEventListenerAPI:myTreeView.addEventListener('ojExpand', listener);
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 nodeElement <not nullable>
The child DOM node Returns:
The context for the DOM node, ornullwhen none is found.- Type
- Object | null
Example
// Returns {'subId': 'oj-some-sub-id', 'componentSpecificProperty': someValue, ...} var context = myComponent.getContextByNode(nodeInsideElement); -
getProperty(property) → {any}
-
Retrieves a value for a property or a single subproperty for complex properties.
Parameters:
Name Type Description propertystring The property name to get. Supports dot notation for subproperty access. - Since:
- 4.0.0
Returns:
- Type
- any
Example
Get a single subproperty of a complex property:
var subpropValue = myComponent.getProperty('complexProperty.subProperty1.subProperty2'); -
refresh() → {void}
-
Refreshes the component.
Returns:
- Type
- void
-
setProperties(properties) → {void}
-
Performs a batch set of properties.
Parameters:
Name Type Description propertiesObject An object containing the property and value pairs to set. - Since:
- 4.0.0
Returns:
- Type
- void
Example
Set a batch of properties:
myComponent.setProperties({"prop1": "value1", "prop2.subprop": "value2", "prop3": "value3"}); -
setProperty(property, value) → {void}
-
Sets a property or a single subproperty for complex properties and notifies the component of the change, triggering a [property]Changed event.
Parameters:
Name Type Description propertystring The property name to set. Supports dot notation for subproperty access. valueany The new value to set the property to. - Since:
- 4.0.0
Returns:
- Type
- void
Example
Set a single subproperty of a complex property:
myComponent.setProperty('complexProperty.subProperty1.subProperty2', "someValue");
Type Definitions
-
ItemContext
-
Properties:
Name Type Argument Description componentElementElement The TreeView element. dataD <optional>
The data object of the item (not available for static content). depthnumber The depth of the item. The depth of the first level children under the invisible root is 1. indexnumber The index of the item relative to its parent, where 0 is the index of the first item. keyK The key of the item. leafboolean Whether the item is a leaf item. parentElementElement The TreeView item element. The renderer can use this to directly append content. parentKeyK <optional>
The key of the parent item (not available for root item). -
ItemsDropOnDropContext
-
Properties:
Name Type Description itemElement The item being dropped on. position'inside' | 'before' | 'after' | 'first' The drop position relative to the item being dropped on.