Tree.Sortable Class
yui3/src/tree/js/extensions/tree-sortable.js:11
Parent Module: tree
Extension for Tree
that makes nodes sortable.
Constructor
Tree.Sortable
-
[config]
Parameters:
-
[config]
Object optionalConfiguration options.
-
[sortComparator]
Function optionalDefault comparator function to use when sorting a node's children if the node itself doesn't have a custom comparator function. If not specified, insertion order will be used by default.
-
[sortReverse=false]
Boolean optionalIf
true
, node children will be sorted in reverse (descending) order by default. Otherwise they'll be sorted in ascending order.
-
Index
Methods
Properties
Events
Methods
_compare
-
a
-
b
Compares value a to value b for sorting purposes.
Values are assumed to be the result of calling a sortComparator function.
Parameters:
-
a
MixedFirst value to compare.
-
b
MixedSecond value to compare.
Returns:
-1
if a should come before b, 0
if they're
equivalent, 1
if a should come after b.
_compareReverse
-
a
-
b
Compares value a to value b for sorting purposes, but sorts them in reverse (descending) order.
Values are assumed to be the result of calling a sortComparator function.
Parameters:
-
a
MixedFirst value to compare.
-
b
MixedSecond value to compare.
Returns:
-1
if a should come before b, 0
if they're
equivalent, 1
if a should come after b.
_getDefaultNodeIndex
-
parent
-
node
-
[options]
Overrides Tree#_getDefaultNodeIndex()
to provide insertion-time sorting
for nodes inserted without an explicit index.
Parameters:
Returns:
Index at which node should be inserted into parent's
children
array.
_getSortComparator
-
node
-
[options]
Returns a sort comparator function derived from the given node and
options, and bound to the correct thisObj
based on where it was found.
Parameters:
-
node
Tree.NodeNode on which to look for a
sortComparator
function. -
[options]
Object optionalOptions object on which to look for a
sortComparator
function.
Returns:
Properly bound sort comparator function.
_sort
-
a
-
b
-
comparator
-
[reverse=false]
Array sort function used by sortNode()
to re-sort a node's children.
Parameters:
Returns:
-1
if a is less than b, 0
if equal, 1
if greater.
sort
-
[options]
Sorts the children of every node in this tree.
A sort
event will be fired for each node whose children are sorted, which
can get very noisy. If this is a large tree, you may want to set the
silent
option to true
to suppress these events.
Parameters:
-
[options]
Object optionalOptions.
-
[silent]
Boolean optionalIf
true
, nosort
events will be fired. -
[sortComparator]
Function optionalCustom comparator function to use. If specified, this will become the new comparator function for each node, overwriting any previous comparator function that was set for the node.
-
[sortReverse]
Boolean optionalIf
true
, children will be sorted in reverse (descending) order. Otherwise they'll be sorted in ascending order. This will become each node's new sort order, overwriting any previous sort order that was set for the node. -
[src]
String optionalSource of the sort operation. Will be passed along to the
sort
event facade.
-
sortComparator
-
node
Default comparator function to use when sorting a node's children if the node itself doesn't have a custom comparator function.
If not specified, insertion order will be used by default.
Parameters:
-
node
Tree.NodeNode being sorted.
Returns:
Value by which the node should be sorted relative to its siblings.
sortNode
-
node
-
[options]
Sorts the children of the specified node.
By default, only the node's direct children are sorted. To sort all nodes in
the hierarchy (children, children's children, etc.), set the deep
option
to true
. If this is a very deep hierarchy, you may also want to set
silent
to true to avoid generating a flood of sort
events.
Parameters:
-
node
Tree.NodeNode whose children should be sorted.
-
[options]
Object optionalOptions.
-
[deep=false]
Boolean optionalIf
true
, all of this node's children (and their children, and so on) will be traversed and re-sorted as well. -
[silent]
Boolean optionalIf
true
, nosort
event will be fired. -
[sortComparator]
Function optionalCustom comparator function to use. If specified, this will become the node's new comparator function, overwriting any previous comparator function that was set for the node.
-
[sortReverse]
Boolean optionalIf
true
, children will be sorted in reverse (descending) order. Otherwise they'll be sorted in ascending order. This will become the node's new sort order, overwriting any previous sort order that was set for the node. -
[src]
String optionalSource of the sort operation. Will be passed along to the
sort
event facade.
-
Properties
sortReverse
Boolean
If true
, node children will be sorted in reverse (descending) order by
default. Otherwise they'll be sorted in ascending order.
Default: false
Events
sort
Fired after a node's children are re-sorted.
Event Payload:
-
node
Tree.NodeNode whose children were sorted.
-
reverse
Booleantrue
if the children were sorted in reverse (descending) order,false
otherwise. -
src
StringSource of the event.