Parameters:
Name | Type | Description |
---|---|---|
options |
Object | A map of option-value pairs to set on the widget. |
- Since:
- 5.0
Examples
var treeData = {
label: "Root",
children: [
{
label: "Child 1",
children: [
{
label: "Grandchild"
}
]
},
{
label: "Child 2",
children: []
}
]
};
var myAdapter = $.apex.treeView.makeDefaultNodeAdapter( treeData );
$( "#simpleTree" ).treeView( {
getNodeAdapter: function() { return myAdapter; },
expandRoot: false
} );
Markup:
<div id="markupTree">
<ul style="display:none;">
<li><a href="#toc">Table of Contents</a>
<ul>
<li><a href="#chapter1">Chapter 1</a>
<li><a href="#chapter2">Chapter 2</a>
</ul>
</li>
</ul>
</div>
JavaScript:
$( "#markupTree" ).treeView( {
navigation: true
} );
actionsContext :actions
The actions context that this treeView is associated with. This option is only applicable when treeView#navigation option is true and one or more node link URLs have an action binding.
Type:
- Default Value:
- apex.actions (the global actions context)
Examples
$( ".selector" ).treeView( {
actionsContext: myContext
} );
// get
var value = $( ".selector" ).treeView( "option", "actionsContext" );
// set
$( ".selector" ).treeView( "option", "actionsContext", myContext );
Only used when treeView#getNodeAdapter is null (when initializing the treeView from markup)
The value is passed to treeView.makeDefaultNodeAdapter as
pTypes
parameter.
Type:
- Object
If true the selection can be copied to the clipboard using the browsers copy event. Can only be set at initialization time.
Type:
- boolean
- Default Value:
- true
Example
$( ".selector" ).treeView( {
allowCopy: false
} );
If true only one sibling node can be expanded at a time.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
autoCollapse: true
} );
// get
var value = $( ".selector" ).treeView( "option", "autoCollapse" );
// set
$( ".selector" ).treeView( "option", "autoCollapse", true );
If true allow nodes to be renamed in-place by clicking on a selected node subject to data model approval via treeNodeAdapter#allowRename.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
clickToRename: true
} );
// get
var value = $( ".selector" ).treeView( "option", "clickToRename" );
// set
$( ".selector" ).treeView( "option", "clickToRename", true );
If false the root node cannot be collapsed (has no toggle area) otherwise the root can be collapsed. Can only be set at initialization time.
Type:
- boolean
- Default Value:
- true
Example
$( ".selector" ).treeView( {
collapsibleRoot: false
} );
A menu widget options object use to create the context menu.
Only specify one of contextMenu
or contextMenuId
and contextMenuAction
.
If none of contextMenu
, contextMenuId
or contextMenuAction
are specified there is no context menu.
This option cannot be set or changed after the widget is initialized.
Type:
- object
- Default Value:
- null
Example
$( ".selector" ).treeView( {
contextMenu: {
items:[
{ type:"action", label: "Action 1", action: function() { alert("Action 1"); } },
{ type:"action", label: "Action 2", action: function() { alert("Action 2"); } }
]
}
} );
A callback function that is called when it is time to display a context menu.
function( event )
The function is responsible for showing the
context menu. It is given the event that caused this callback to be called.
In most cases it is simpler and more consistent to use the
contextMenu
option.
Only specify one of contextMenu
or contextMenuId
and
contextMenuAction
.
If none of contextMenu
, contextMenuId
or contextMenuAction
are specified there is no context menu.
Type:
- function
- Default Value:
- null
Example
$( ".selector" ).treeView( {
contextMenuAction: function( event ) {
// do something to display a context menu
}
} );
If option contextMenu
is given then this is the element id
to give the context menu created.
This allows other code to interact with the created context menu widget.
If option contextMenu
is not given then this is the
element id of an existing menu widget.
This option cannot be set or changed after the widget is initialized.
Type:
- string
- Default Value:
- null
Example
$( ".selector" ).treeView( {
contextMenuId: "myContextMenu"
} );
Determines the behavior of double clicking on a node. One of:
- false: does nothing.
- "activate": the node is activated.
- "toggle": the node is collapsed if expanded and expanded if collapsed.
Type:
- false | string
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
doubleClick: "toggle"
} );
// get
var value = $( ".selector" ).treeView( "option", "doubleClick" );
// set
$( ".selector" ).treeView( "option", "doubleClick", "toggle" );
If true drag and drop is supported. The treeNodeAdapter must also support drag and drop.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
dragAndDrop: true
} );
// get
var value = $( ".selector" ).treeView( "option", "dragAndDrop" );
// set
$( ".selector" ).treeView( "option", "dragAndDrop", true );
Which element the draggable helper should be appended to while dragging.
See jQuery UI draggable appendTo
option for details.
Type:
- string
- Default Value:
- "parent"
Constrains dragging to within the bounds of the specified element or region.
See jQuery UI draggable containment
option for details.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
dragContainment: true
} );
// get
var value = $( ".selector" ).treeView( "option", "dragContainment" );
// set
$( ".selector" ).treeView( "option", "dragContainment", true );
The CSS cursor during the drag operation.
See jQuery UI draggable cursor
option for details.
Type:
- string
- Default Value:
- "auto"
Sets the offset of the dragging helper relative to the mouse cursor.
See jQuery UI draggable cursorAt
option for details.
Type:
- false | Object
- Default Value:
- false
When dragging and hover over a collapsed node how long (in milliseconds) to wait until it expands -1 means don't expand.
Type:
- number
- Default Value:
- 1200
Examples
$( ".selector" ).treeView( {
dragExpandDelay: 1000
} );
// get
var value = $( ".selector" ).treeView( "option", "dragExpandDelay" );
// set
$( ".selector" ).treeView( "option", "dragExpandDelay", 1000 );
Allows for a helper element to be used for dragging display.
See jQuery UI draggable helper
option for details.
Type:
- string | function
- Default Value:
- true
This only applies if treeView#multiple and treeView#dragAndDrop options are true.
If this option is true then multiple nodes can be dragged.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
dragMultiple: true
} );
// get
var value = $( ".selector" ).treeView( "option", "dragMultiple" );
// set
$( ".selector" ).treeView( "option", "dragMultiple", true );
Opacity for the helper while being dragged.
See jQuery UI draggable opacity
option for details.
Type:
- false | number
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
dragOpacity: 0.4
} );
// get
var value = $( ".selector" ).treeView( "option", "dragOpacity" );
// set
$( ".selector" ).treeView( "option", "dragOpacity", 0.4 );
If true the nodes can be reordered using drag and drop. If false drag and drop just moves (or copies) nodes from one parent node to another.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
dragReorder: true
} );
// get
var value = $( ".selector" ).treeView( "option", "dragReorder" );
// set
$( ".selector" ).treeView( "option", "dragReorder", true );
If set to true, container auto-scrolls while dragging.
See jQuery UI draggable scroll
option for details.
Type:
- boolean
- Default Value:
- true
Examples
$( ".selector" ).treeView( {
dragScroll: false
} );
// get
var value = $( ".selector" ).treeView( "option", "dragScroll" );
// set
$( ".selector" ).treeView( "option", "dragScroll", false );
Distance in pixels from the edge of the viewport after which the viewport should scroll.
Distance is relative to pointer, not the draggable.
See jQuery UI draggable scrollSensitivity
option for details.
Type:
- number
- Default Value:
- 20
Examples
$( ".selector" ).treeView( {
dragScrollSensitivity: 30
} );
// get
var value = $( ".selector" ).treeView( "option", "dragScrollSensitivity" );
// set
$( ".selector" ).treeView( "option", "dragScrollSensitivity", 30 );
The speed at which the viewport should scroll.
See jQuery UI draggable scrollSpeed
option for details.
Type:
- number
- Default Value:
- 10
Examples
$( ".selector" ).treeView( {
dragScrollSpeed: 8
} );
// get
var value = $( ".selector" ).treeView( "option", "dragScrollSpeed" );
// set
$( ".selector" ).treeView( "option", "dragScrollSpeed", 8 );
Z-index for the helper while being dragged.
See jQuery UI draggable zIndex
option for details.
Type:
- number
- Default Value:
- 1000
Examples
$( ".selector" ).treeView( {
dragZIndex: 1001
} );
// get
var value = $( ".selector" ).treeView( "option", "dragZIndex" );
// set
$( ".selector" ).treeView( "option", "dragZIndex", 1001 );
If true the root node is initially expanded otherwise it is collapsed. Option expandRoot cannot be false when treeView#collapsibleRoot is false
Type:
- boolean
- Default Value:
- true
Examples
$( ".selector" ).treeView( {
expandRoot: false
} );
// get
var value = $( ".selector" ).treeView( "option", "expandRoot" );
// set
$( ".selector" ).treeView( "option", "expandRoot", false );
A no argument function returning an object that implements the treeNodeAdapter interface. The node adapter provides access to the data behind the treeView. This option is required unless the tree data is supplied by markup.
Type:
- function
- Default Value:
- null
Example
$( ".selector" ).treeView( {
getNodeAdapter: function() { return myAdapter; }
} );
Icon type CSS class name. The iconType along with the value returned by treeNodeAdapter#getIcon make up the classes used for the tree node icon.
Type:
- string
- Default Value:
- "a-Icon"
Examples
$( ".selector" ).treeView( {
iconType: "fa"
} );
// get
var value = $( ".selector" ).treeView( "option", "iconType" );
// set
$( ".selector" ).treeView( "option", "iconType", "fa" );
Optional id prefix used to generate unique DOM ids. If not given the prefix is based on
the id
attribute of the treeView widget root element or if there
is no id the prefix is "tree".
Type:
- string
- Default Value:
- treeView element id or "tree" if id is null
Example
$( ".selector" ).treeView( {
idPrefix: "tree7"
} );
If true allow a new child node to be added in-place with Insert key subject to model approval via treeNodeAdapter#allowAdd.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
keyboardAdd: true
} );
// get
var value = $( ".selector" ).treeView( "option", "keyboardAdd" );
// set
$( ".selector" ).treeView( "option", "keyboardAdd", true );
If true allow nodes to be deleted with the Delete key subject to model approval via treeNodeAdapter#allowDelete.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
keyboardDelete: true
} );
// get
var value = $( ".selector" ).treeView( "option", "keyboardDelete" );
// set
$( ".selector" ).treeView( "option", "keyboardDelete", true );
If true allow nodes to be renamed in-place by pressing the F2 key subject to data model approval via treeNodeAdapter#allowRename.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
keyboardRename: true
} );
// get
var value = $( ".selector" ).treeView( "option", "keyboardRename" );
// set
$( ".selector" ).treeView( "option", "keyboardRename", true );
The CSS class name to use on the focusable node content element. This should only be changed if the node adapter implements treeNodeAdapter#renderNodeContent.
Type:
- string
- Default Value:
- "a-TreeView-label"
If true multiple nodes can be selected otherwise only single selection is supported.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
multiple: true
} );
// get
var value = $( ".selector" ).treeView( "option", "multiple" );
// set
$( ".selector" ).treeView( "option", "multiple", true );
If true then single click causes activation (unless treeView#doubleClick value is "activate")
and if the node adapter supports treeNodeAdapter#getLink and
getLink
returns a value the default behavior is to navigate to that link.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
navigation: true
} );
// get
var value = $( ".selector" ).treeView( "option", "navigation" );
// set
$( ".selector" ).treeView( "option", "navigation", true );
If true a selector control is added before the node icon and label. The selector is a checkbox if multiple is true and a radio button if multiple is false.
Type:
- boolean
- Default Value:
- false
Examples
$( ".selector" ).treeView( {
nodeSelector: true
} );
// get
var value = $( ".selector" ).treeView( "option", "nodeSelector" );
// set
$( ".selector" ).treeView( "option", "nodeSelector", true );
Only used with jQuery UI droppable for drag and drop.
Used to group sets of draggable and droppable items.
See jQuery UI droppable scope
option for details.
Type:
- string
- Default Value:
- "default"
Examples
$( ".selector" ).treeView( {
scope: "parts"
} );
// get
var value = $( ".selector" ).treeView( "option", "scope" );
// set
$( ".selector" ).treeView( "option", "scope", "parts" );
Determines if the tree is shown with a single root or with multiple "roots" which are really the first level nodes in the data model. If false the tree appears like a forest (multi-rooted). If true there is a single root node.
Type:
- boolean
- Default Value:
- true
Examples
$( ".selector" ).treeView( {
showRoot: false
} );
// get
var value = $( ".selector" ).treeView( "option", "showRoot" );
// set
$( ".selector" ).treeView( "option", "showRoot", false );
A tooltip options object suitable for the jQuery UI tooltip widget except that the items property is not needed (it is supplied by the treeView) and the content callback function receives a second argument that is the treeNodeAdapter.node the tooltip applies to. If not given there is no tooltip.
See the jQuery UI documentation for details on the tooltip widget.
Type:
- Object
- Default Value:
- null
Example
$( ".selector" ).treeView( {
tooltip: {
show: { delay: 1000, effect: "show", duration: 500 },
content: function ( callback, node ) {
if ( !node ) {
return null;
}
return node.tooltip;
}
}
} );
If true nodes with links are rendered as anchor elements. Nodes that have a link can be navigated to on activation regardless of this option value. By using an anchor element the built in browser behavior for opening links in new windows or tabs is available. Beware if combined with context menu options.
Type:
- boolean
- Default Value:
- true
Examples
$( ".selector" ).treeView( {
useLinks: false
} );
// get
var value = $( ".selector" ).treeView( "option", "useLinks" );
// set
$( ".selector" ).treeView( "option", "useLinks", false );
Triggered when an accepted draggable starts dragging. Only applies when a connected draggable is being dragged. See jQuery UI droppable and sortable for details.
Properties:
Name | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
||||||||||||||||||
ui |
Object |
Properties
|
Triggered when when nodes are activated with the Enter key or double click if treeView#doubleClick option set to "activate" or single click if treeView#navigation option is true and treeView#doubleClick is not "activate". Handler can call the event's preventDefault method to stop navigation.
Properties:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
||||||
ui |
Object |
Properties
|
Examples
$( ".selector" ).treeView({
activateNode: function( event, ui ) {}
});
$( ".selector" ).on( "treeviewactivatenode", function( event, ui ) {} );
Triggered when dragging stops, but when the placeholder/helper is still available. See jQuery UI sortable for details.
Properties:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
|||||||||||||||||||||||||||
ui |
Object |
Properties
|
Triggered when when in-place add or rename begins.
Properties:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
||||||||||||
ui |
Object |
Properties
|
Examples
$( ".selector" ).treeView({
beginEdit: function( event, ui ) {}
});
$( ".selector" ).on( "treeviewbeginedit", function( event, ui ) {} );
Triggered when an accepted draggable stops dragging. Only applies when a connected draggable is being dragged. See jQuery UI droppable and sortable for details.
Properties:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
|||||||||||||||||||||||||||
ui |
Object |
Properties
|
Triggered while the mouse is moved during the dragging, immediately before the current move happens. See jQuery UI draggable for details.
Properties:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
|||||||||||||||||||||||||||
ui |
Object |
Properties
|
Triggered when when in-place add or rename ends.
Properties:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
|||||||||
ui |
Object |
Properties
|
Examples
$( ".selector" ).treeView({
endEdit: function( event, ui ) {}
});
$( ".selector" ).on( "treeviewendedit", function( event, ui ) {} );
Triggered when nodes are expanded or collapsed.
Properties:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
||||||||||||
ui |
Object |
Properties
|
Examples
$( ".selector" ).treeView({
expansionStateChange: function( event, ui ) {}
});
$( ".selector" ).on( "treeviewexpansionstatechange", function( event, ui ) {} );
Triggered when an accepted draggable is dragged out of the droppable. Only applies when a connected draggable is being dragged. See jQuery UI droppable and sortable for details.
Properties:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
|||||||||||||||||||||||||||
ui |
Object |
Properties
|
Triggered when an accepted draggable is dragged over the droppable. Only applies when a connected draggable is being dragged. See jQuery UI droppable and sortable for details.
Properties:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
|||||||||||||||||||||||||||
ui |
Object |
Properties
|
Triggered when the selection state changes. It has no additional data. When the selection changes the handler will generally want to get the current selection using the treeView#getSelection or treeView#getSelectedNodes methods.
Properties:
Name | Type | Description |
---|---|---|
event |
Event | jQuery event object. |
Examples
$( ".selector" ).treeView({
selectionChange: function( event ) {}
});
$( ".selector" ).on( "treeviewselectionchange", function( event ) {} );
Triggered when dragging a node starts. See jQuery UI draggable and sortable for details.
Properties:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
|||||||||||||||||||||||||||
ui |
Object |
Properties
|
Triggered when dragging a node stops. See jQuery UI draggable and sortable for details.
Properties:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event | jQuery event object. |
|||||||||||||||||||||||||||
ui |
Object |
Properties
|
Adds the given node to the adapter's data model and the treeView under the given parent tree node
and at the given index.
If pNode
is null or omitted then the adapter should create
and add a new default node.
The treeNodeAdapter must implement the addNode
and allowAdd
methods and treeNodeAdapter#allowAdd must return
true for the given node and parent.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pToParentNodeContent$ |
jQuery | null | The parent tree node to add a child to. If null or an empty jQuery object then the node is added to the root (this can only happen when the root node is not shown in the treeView). | |
pIndex |
integer | The index in the array of children to add the new node. | |
pNode |
treeNodeAdapter.node |
<optional> |
(optional) New node to add. |
Throws:
Adds a new tree node in the treeView and also adds it to the adapter's data model via the treeNodeAdapter#addNode method. First checks if the model allows add for the parent node by calling treeNodeAdapter#allowAdd. The label of the new node is entered by the user in-place. The tree node label is replaced by a text input field. Pressing the Escape key will cancel the add, blur or Enter key will complete the add. The order of the new node among its siblings is determined by the adapter after the node is added.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pParentNodeContent$ |
jQuery | The parent tree node to add the new node under. Must be a jQuery object representing exactly one tree node element. | |
pInitialLabel |
string | The initial label for the new node which is then edited. | |
pContext |
Object |
<optional> |
Optional arbitrary object to pass into the adapter allowAdd and addNode methods. This is an object containing information needed by the treeNodeAdapter#addNode method to create the new node. In the typical simple case it is exactly the model node. |
Throws:
Collapse the given tree node(s) or if no node is given collapse the root node(s). Collapsing a node makes all of its children hidden. See also treeView#collapseAll and treeView#expand.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pNodeContent$ |
jQuery |
<optional> |
One or more tree nodes to collapse or null or omit to collapse the root(s). |
Example
var tree$ = $( ".selector" );
tree$.treeView( "collapse", tree$.treeView( "getSelection" ) );
Collapse the given tree node(s) or if no node is given the root node(s) and recursively collapse all its children. See also treeView#expandAll.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pNodeContent$ |
jQuery |
<optional> |
One or more tree nodes to collapseALl from or null or omit to collapseAll from the root(s). |
Example
$( ".selector" ).treeView( "collapseAll" );
Copies the given tree nodes to be children of the given parent tree node starting at the given index. The adapter must allow each of the nodes to be added to the new parent.
Parameters:
Name | Type | Description |
---|---|---|
pToParentNodeContent$ |
jQuery | parent tree node to copy nodes to. If null or an empty jQuery object then the node is copied to the root (this can only happen when the root node is not shown in the treeView). |
pIndex |
integer | The index in the array of children to copy the nodes to. |
pNodeContent$ |
jQuery | The tree nodes to be copied. |
Throws:
Deletes nodes from the adapter's data model and treeView. First checks that the model allows delete with treeNodeAdapter#allowDelete then deletes the node using treeNodeAdapter#deleteNode (a potentially async operation). If the deletes are allowed and successful then the tree nodes are removed from the treeView DOM.
Parameters:
Name | Type | Description |
---|---|---|
pNodeContent$ |
jQuery | One or more tree nodes to delete. |
Throws:
Deletes tree nodes that have already been deleted from the adapter's data model.
Parameters:
Name | Type | Description |
---|---|---|
pNodeContent$ |
jQuery | One or more tree nodes to delete. |
Expand the given tree node(s) or if no node is given expand the root node(s). Expanding a node makes all of its children visible. See also treeView#expandAll and treeView#collapse.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pNodeContent$ |
jQuery |
<optional> |
One or more tree nodes to expand or null or omit to expand the root(s). |
Example
var tree$ = $( ".selector" );
tree$.treeView( "expand", tree$.treeView( "getSelection" ) );
Expand the given tree node(s) or if no node is given the root node(s) and recursively expand all its children. See also treeView#collapseAll.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pNodeContent$ |
jQuery |
<optional> |
One or more tree nodes to expand all from or null or omit to expand all from the root(s). |
Example
$( ".selector" ).treeView( "expandAll" );
Search through the tree starting at the root or the given parent tree node for one or more matching nodes
(the parent tree node is not included in the search). The set of matched tree nodes is returned as a
jQuery
object.
The match criteria is determined by the match
function that is called
for each node. The search can be limited
to a specified depth (from the starting node). Find can return either all the nodes matched or just the first
one.
This is a synchronous API so it can only search tree nodes that have been loaded. If the data model is loaded asynchronously only those tree nodes that have already been loaded into the model can be searched. The tree nodes don't need to be expanded to be searched, but searching will cause them to be rendered to the DOM if they aren't already.
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pOptions |
Object | The properties control how the search is done.
Properties
|
Returns:
- Type
- jQuery
Example
$( ".selector" ).treeView( "find", {
depth: -1,
findAll: true,
match: function(n) {
return n.label.indexOf( "ton" ) >= 0;
}
} ).find( ".a-TreeView-label" ).addClass( "findMatch" );
Set focus to the tree node that last had focus.
Example
$( ".selector" ).treeView( "focus" );
Get the ids of expanded nodes. The treeNodeAdapter must implement view state methods.
Throws:
Returns:
Examples
var expandedIds = apex.region( "myTree" ).call( "getExpandedNodeIds" );
$s( "P1_EXPANDED_IDS", expandedIds.join( ":" ) );
function( options ) {
options.makeNodeAdapter = function( data, types, hasIdentity ) {
var adapter;
adapter = $.apex.treeView.makeDefaultNodeAdapter( data, types, hasIdentity, $v("P1_EXPANDED_IDS").split(":") );
return adapter;
}
return options;
}
Get a map from node id to Boolean where true = expanded and false = collapsed
Note It is not guaranteed that the map contain all nodes! It may only contain nodes that have been explicitly expanded or collapsed by the user. This is up to the tree node adapter. The treeNodeAdapter must implement view state methods.
Throws:
Returns:
- Type
- Object
getNodeAdapter() → {treeNodeAdapter}
Returns the treeNodeAdapter that the treeView is using.
Returns:
- Type
- treeNodeAdapter
Example
var i, count,
selectedNode = $( ".selector" ).treeView( "getSelectedNodes" )[0],
adapter = $( ".selector" ).treeView( "getNodeAdapter" );
if ( selectedNode ) {
count = adapter.childCount( selectedNode );
for ( i = 0; i < count; i++ ) {
console.log( "Label: " + adapter.child( selectedNode, i ).label );
}
}
getNodes(pNodeContent$) → {Array.<treeNodeAdapter.node>}
Given a jQuery object with a set of treeView nodes return an array of adapter data model nodes that
corresponds to each treeView node in the set.
The tree nodes passed in must be the ones this treeView instance rendered
with class a-TreeView-content
.
This is for mapping from DOM elements to model node objects.
Parameters:
Name | Type | Description |
---|---|---|
pNodeContent$ |
jQuery | jQuery Object holding a set of tree nodes. |
Returns:
- Type
- Array.<treeNodeAdapter.node>
Example
var tree$ = $( ".selector" ),
selection$ = tree$.treeView( "getSelection" ),
nodes = tree$.treeView( "getNodes", selection$ );
nodes.forEach( function( n, i ) {
n.label = n.label.toLowerCase();
tree$.treeView( "update", selection$.eq(i) )
} );
getSelectedNodes() → {Array.<treeNodeAdapter.node>}
Returns the adapter's data model nodes corresponding to the currently selected treeView nodes. See also treeView#getSelection and treeView#getNodes.
Returns:
- Type
- Array.<treeNodeAdapter.node>
Example
var selectedNodes = $( ".selector" ).treeView( "getSelectedNodes" );
Returns the set of treeView nodes currently selected. If there is no selection the empty set is returned.
The elements returned have the class a-TreeView-content
.
Returns:
- Type
- jQuery
Example
var selection$ = $( ".selector" ).treeView( "getSelection" );
Given a treeNodeAdapter node return a jQuery object with the treeView element corresponding
to that node. The element returned has the class a-TreeView-content
.
The treeNodeAdapter must implement view state methods.
This is for mapping from a data model node object to a DOM element.
Parameters:
Name | Type | Description |
---|---|---|
pNode |
treeNodeAdapter.node | The model node to get the corresponding treeView node DOM element for. |
Throws:
Returns:
- Type
- jQuery
Moves the given tree nodes to be children of the given parent tree node starting at the given index. The adapter must allow each of the nodes to be added to the new parent and must allow all the nodes to be deleted.
Parameters:
Name | Type | Description |
---|---|---|
pToParentNodeContent$ |
jQuery | The parent tree node to move node to. If null or an empty jQuery object then the node is moved to the root (this can only happen when the root node is not shown in the treeView) |
pIndex |
integer | The index in the array of children to move the nodes to. |
pNodeContent$ |
jQuery | The tree nodes to be moved. |
Throws:
Call to render the whole tree or sub trees whenever the adapter's data model changes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pNodeContent$ |
jQuery |
<optional> |
The treeView node(s) to refresh from. If not given or null start from the root of the tree. |
Example
$( ".selector" ).treeView( "refresh" );
Renames a tree node in the treeView and updates the model via the node adapter treeNodeAdapter#renameNode method. First checks it the model allows the node to be renamed. The rename is done by the user in-place. The tree node label is replaced by a text input field. Escape will cancel, Enter key or loosing focus will complete the rename. The order of the renamed node among its siblings is determined by the model after the node is renamed.
Parameters:
Name | Type | Description |
---|---|---|
nodeContent$ |
the tree node to rename. Must be a jQuery object representing exactly one tree node element. |
Throws:
Sets the current tree selection. Given an array of nodes from the treeNodeAdapter data model, find the corresponding treeView node elements and set the selection to those nodes. The treeNodeAdapter must implement view state methods. Depending on the treeNodeAdapter implementation it may be possible to supply an array of objects with just the node's identity property filled in. See also treeView#getSelectedNodes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pNodes |
Array.<treeNodeAdapter.node> | An array of model nodes. | |
pFocus |
boolean |
<optional> |
If true the tree node corresponding to the first node in
pNodes will be focused. |
pNoNotify |
boolean |
<optional> |
If true the treeView#event:selectionChange event will be suppressed. |
Throws:
Example
$( ".selector" ).treeView( "setSelectedNodes", [theNode], true);
Sets the current tree selection. The treeView nodes passed in must be the ones this treeView instance rendered
with class a-TreeView-content
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pNodeContent$ |
jQuery | A jQuery object with the treeView nodes to select. An empty jQuery set will clear the selection. | |
pFocus |
boolean |
<optional> |
If true the first tree node in pNodeContent$ will be focused. |
pNoNotify |
boolean |
<optional> |
If true the treeView#event:selectionChange event will be suppressed. |
Examples
$( ".selector" ).treeView( "setSelection", $( "[aria-level='3']" ).parent() );
var tree$ = $( ".selector" ),
selection$ = tree$.treeView( "getSelection" );
tree$.treeView( "expandAll", selection$ )
.treeView( "setSelection", selection$.parent().find( ".a-TreeView-content" ), false, true );
$( ".selector" ).treeView( "setSelection", $() );
Call this method if the model node changes in a way that would affect its display in the tree. For example if the label or icon changes. If a node's children have changed then call treeView#refresh instead. If a nodes position has changed then call refresh on the nodes parent node.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pNodeContent$ |
jQuery | The treeView node for which the underlying data model node has changed. | |
pRender |
boolean |
<optional> |
The default is true. Set this to false to avoid rendering the tree node content if only the hidden state or css classes have changed. |
Example
(static) makeDefaultNodeAdapter(pData, pTypesopt, pHasIdentityopt, pInitialExpandedNodeIdsopt) → {treeNodeAdapter}
Returns a default node adapter. See treeNodeAdapter for details.
This returns an adapter for the default data model. See treeNodeAdapter.defaultNode for details on the node object properties. Use it if you don't already have a prescribed data model. This supports all the treeView features except for asynchronous (lazy) loading of child nodes and custom node rendering. Although it supports editing there is no built-in support for persisting the edits. Editing through the default tree node adapter should be considered an experimental feature subject to change.
You can augment the adapter returned from this function to change its behavior. For example by adding a treeNodeAdapter#fetchChildNodes method to lazy load child nodes or a custom node rendering function as shown in the examples below.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pData |
treeNodeAdapter.defaultNode | This object is the root node of the tree. | |
pTypes |
treeNodeTypes |
<optional> |
A treeNodeAdapter.typeInfo structure with metadata about the node types. |
pHasIdentity |
boolean |
<optional> |
Set to true if the tree model nodes have identity
(id property). Set to false if nodes do not have identity.
The default is true. This argument can be omitted if the pInitialExpandedNodeIds
argument is given. |
pInitialExpandedNodeIds |
Array |
<optional> |
An array of node ids for all the nodes that should be initially expanded. |
Returns:
- Type
- treeNodeAdapter
Examples
var treeData = {
label: "Root",
children: [
{
label: "Child 1",
children: [
{
label: "Grandchild"
}
]
},
{
label: "Child 2",
children: []
}
]
};
var adapter = $.apex.treeView.makeDefaultNodeAdapter( treeData, null, false );
var treeData = {
id: "0001",
label: "Root",
children: [
{
id: "0009",
label: "Child 1",
children: [
...
]
},
...
]
};
var adapter = $.apex.treeView.makeDefaultNodeAdapter( treeData );
// the following has the same effect
// var adapter = $.apex.treeView.makeDefaultNodeAdapter( treeData, null, true );
var treeData = {
id: "0001",
label: "Root",
children: [
{
id: "0009",
label: "Child 1",
children: null // this means lazy load the children
},
...
]
};
var adapter = $.apex.treeView.makeDefaultNodeAdapter( treeData );
// Replace these functions to be aware of nodes that need lazy loading
// no children property or children = [] means there are no children
// children = null means the server has or may have more children
adapter.childCount = function( n ) {
if ( n.children === null ) {
return null;
} // else
return n.children ? n.children.length : 0;
};
adapter.hasChildren = function( n ) {
if ( n.children === null ) {
return null;
} // else
return n.children ? n.children.length > 0 : false;
};
// add this method to fetch children when node is first expanded
adapter.fetchChildNodes = function( n, callback ) {
// Simulate adding lazy loaded nodes
// This would normally be an ajax call such as apex.server.process
// Typically send something like n.id to the server so it knows which children to return
setTimeout(function() {
// when the ajax call returns add the children to the parent (n).
var c = n.children = [];
// this example just adds dummy data
c.push( {
id: n.id + "_l1",
label: "Lazy Child 1",
children: [] // no children we're sure
});
c.push( {
id: n.id + "_l2",
label: "Lazy Child 2",
children: null // there could be more lazy loaded children
});
// when the model data is updated let the treeView know
callback( true );
}, 800 );
};
...
var adapter = $.apex.treeView.makeDefaultNodeAdapter( treeData );
adapter.renderNodeContent = function( node, out, options, state ) {
var label;
if ( options.nodeSelector > 0 ) {
// simulate a checkbox or radio button depending on single/multiple selection
cls = "u-selector";
if ( options.nodeSelector === 1 ) {
cls += " u-selector--single";
}
out.markup('<span class="' + cls + '"></span>');
}
if ( adapter.getIcon ) {
icon = adapter.getIcon( node );
if ( icon !== null ) {
out.markup( "<span" ).attr( "class", options.iconType + " " + icon ).markup( "></span>" );
}
}
// format label
label = apex.util.escapeHTML( adapter.getLabel( node ) );
label = "<b>" + label.substring(0,1) + "</b>" + label.substring(1);
// assume the node is not a link
out.markup( "<span tabIndex='-1' role='treeitem'" )
.attr( "class", options.labelClass )
.attr( "aria-level", state.level )
.attr( "aria-selected", state.selected ? "true" : "false" )
.optionalAttr( "area-disabled", state.disabled ? "true" : null )
.optionalAttr( "aria-expanded", state.hasChildren === false ? null : state.expanded ? "true" : "false" )
.markup( ">" )
.markup( label )
.markup( "</span>" );
}