Class: TreeDataSource

Oracle® JavaScript Extension Toolkit (JET)
4.2.0

E91398-01

QuickNav

oj. TreeDataSource extends oj.DataSource

Version:
  • 4.2.0
Abstract class representing hierarchical (tree) data that can be used by different components such as Indexer, ListView, NavigationList, and TreeView.

This class is not used directly and is used as the base to implement other subclasses. Implementations of TreeDataSource must implement all of the methods documented here.

JET provides the following implementations:

Subclass When to Use Use with
oj.CollectionTreeDataSource When the data is available from an oj.Collection object, such as an external data source. ListView
NavigationList
TreeView
oj.IndexerModelTreeDataSource When the data has a tree-like structure that is displayed in a ListView with Indexer. ListView (with Indexer)
oj.JsonTreeDataSource When the data is available from an array of JSON objects that represent tree nodes. ListView
NavigationList
TreeView

Refer to the documentation and demos of individual components for more information on how to use them with the TreeDataSource subclasses.

In case specialized behavior is needed, new subclass can be created by using oj.Object.createSubclass. New subclass can be based on TreeDataSource, in which case all methods must be implemented, or it can be based on an existing subclass, in which case only methods that require different behavior need to be overridden.

Constructor

new TreeDataSource(data)

Parameters:
Name Type Description
data Object data supported by the component

Methods

fetchChildren(parent, range, callbacks, options) → {Object}

Fetch the children
Parameters:
Name Type Argument Description
parent Object the parent key. Specify null if fetching children from the root.
range Object information about the range, it must contain the following properties: start, count.

start: the start index of the range in which the children are fetched.
count: the size of the range in which the children are fetched.

callbacks Object the callbacks to be invoke when fetch children operation is completed. The valid callback types are "success" and "error".

success: the callback to invoke when fetch completed successfully.
error: the callback to invoke when fetch children failed.

options Object <optional>
optional parameters for this operation.

queueOnly: true if this fetch request is to be queued and not execute yet. The implementation must maintain the order of the fetch operations. When queueOnly is false/null/undefined, any queued fetch operations are then flushed and executed in the order they are queued. This flag is ignored if the datasource does not support batching.

Returns:
children
Type
Object

fetchDescendants(parent, callbacks, options) → {Object}

Fetch all children and their children recursively from a specified parent.
Parameters:
Name Type Argument Description
parent Object the parent key. Specify null to fetch everything from the root (i.e. expand all)
callbacks Object the callbacks to be invoke when fetch children operation is completed. The valid callback types are "success" and "error".

success: the callback to invoke when fetch completed successfully.
error: the callback to invoke when fetch children failed.

options Object <optional>
optional parameters for this operation.

start: the index related to parent in which to begin fetching descendants from. If this is not specified, then value zero will be used.
maxCount: the maximum number of children to fetch. If a non-positive number is specified, then the value is ignored and there is no maximum fetch count.

Returns:
descendants
Type
Object

getCapability(feature) → {string|null}

Determines whether this TreeDataSource supports the specified feature.
Parameters:
Name Type Description
feature string the feature in which its capabilities is inquired. Currently the valid features "sort", "move", "fetchDescendants", "batchFetch"
Returns:
the name of the feature. Returns null if the feature is not recognized. For "sort", the valid return values are: "default", "none". For "fetchDescendants", the valid return values are: "enable", "disable", "suboptimal". For "move", the valid return values are: "default", "none". For "batchFetch", the valid return values are: "enable", "disable".
Type
string | null

getChildCount(parent) → {number}

Returns the number of children for a specified parent. If the value returned is not >= 0 then it is automatically assumed that the child count is unknown.
Parameters:
Name Type Description
parent Object the parent key. Specify null if inquiring child count of the root.
Returns:
the number of children for the specified parent.
Type
number

getSortCriteria() → {Object}

Returns the current sort criteria of the tree data.
Returns:
the current sort criteria. It should contain the following properties: key, direction where criteria.key the key identifying the attribute (column) to sort on. Value is null if it's not sorted. criteria.direction the sort direction, valid values are "ascending", "descending", "none" (default)
Type
Object

handleEvent(eventType, event) → {boolean}

Handle the event
Parameters:
Name Type Description
eventType string event type
event Object event
Inherited From:
Returns:
Returns false if event is cancelled
Type
boolean

Init() → {undefined}

Initializes the instance.
Inherited From:
Returns:
Type
undefined

move(rowToMove, referenceRow, position, callbacks) → {undefined}

Moves a row from one location to another (different position within the same parent or a completely different parent)
Parameters:
Name Type Description
rowToMove Object the key of the row to move
referenceRow Object the key of the reference row which combined with position are used to determine the destination of where the row should moved to.
position number | string The position of the moved row relative to the reference row. This can be a string: "before", "after", "inside", "first", "last", or the zero based index to position the element at a specific point among the reference row's current children.
callbacks Object the callbacks for the move function

success: the callback to invoke when the move completed successfully.
error: the callback to invoke when move failed.

Returns:
Type
undefined

moveOK(rowToMove, referenceRow, position) → {string}

Checks whether a move operation is valid.
Parameters:
Name Type Description
rowToMove Object the key of the row to move
referenceRow Object the key of the reference row which combined with position are used to determine the destination of where the row should moved to.
position number | string The position of the moved row relative to the reference row. This can be a string: "before", "after", "inside", "first", "last", or the zero based index to position the element at a specific point among the reference row's current children.
Returns:
returns "valid" if the move is valid, "invalid" otherwise.
Type
string

off(eventType, eventHandler)

Detach an event handler.

Application can call this if it no longer wants to be notified of an event that it has attached an handler to using the on method.

Parameters:
Name Type Description
eventType string eventType
eventHandler function(Object) event handler function
Inherited From:

on(eventType, eventHandler)

Attach an event handler.

Application can call this if it wants to be notified of an event. It can call the off method to detach the handler when it no longer wants to be notified.

Parameters:
Name Type Description
eventType string eventType
eventHandler function(Object) event handler function
Inherited From:

sort(criteria, callbacks) → {undefined}

Performs a sort operation on the tree data.
Parameters:
Name Type Description
criteria Object the sort criteria. It must contain the following properties: key, direction.

key: the key identifying the attribute (column) to sort on.
direction: the sort direction, valid values are "ascending", "descending", "none" (default)

callbacks Object callbacks for the sort operation

success: the callback to invoke when the sort completed successfully.
error: the callback to invoke when sort failed.

Returns:
Type
undefined