class anychart.data.TreeView Improve this Doc
Extends: anychart.core.Base
TreeView. Class of mapped tree.
Methods Overview
Data | |
addChild() | Adds a child. |
addChildAt() | Inserts a child into a specified position. |
addData() | Adds a data. |
getChildAt() | Gets the child by index. |
getChildren() | Returns a roots array. |
getTraverser() | Creates tree view data traverser. |
indexOfChild() | Gets the index of child in a children array. |
numChildren() | Returns a length of roots array. |
removeChild() | Removes data item's child. |
removeChildAt() | Removes child at the specified position. |
removeChildren() | Removes children. |
search() | Performs a data search. |
searchItems() | Performs an items search and returns an array of data items. |
Miscellaneous | |
filter() | Filters the tree data items using the filter-function. |
Methods Description
addChild
Adds a child.
Params:
Name | Type | Description |
---|---|---|
child | Object | anychart.data.Tree.DataItem | anychart.data.TreeView.DataItem | Child to set. |
Returns:
anychart.data.TreeView.DataItem - An instance of the class for method chaining.Try it:
addChildAt
Inserts a child into a specified position.
Detailed description
Please make sure that child has not inner cycles to avoid stack overflow exception.
Params:
Name | Type | Description |
---|---|---|
child | Object | anychart.data.Tree.DataItem | anychart.data.TreeView.DataItem | Child to set. |
index | number | Position. |
Returns:
anychart.data.TreeView.DataItem - An instance of the class for method chaining.Try it:
addData
Adds a data.
Params:
Name | Type | Description |
---|---|---|
data | Array.<Object> | string | Raw data or CSV-string. If string is passed, second parameter will be interpreted as fields mapping. |
fillMethodOrCsvMapping | anychart.enums.TreeFillingMethod | string | Object | Fill method or CSV mapping object.
This parameter is interpreted as mapping object if first parameter is string. Mapping object should have structure
like
//'nameOfField': index_of_column mapping = { 'id': 0, 'name': 1, 'value': 15 }; |
csvSettingsOrDeps | Object | Array.<anychart.data.Tree.Dependency> | CSV settings object or dependencies data.
If is CSV settings object, should fields like
rowsSeparator - string or undefined, if it is undefined, it will not be set.
columnsSeparator - string or undefined, if it is undefined, it will not be set.
ignoreTrailingSpaces - boolean or undefined, if it is undefined, it will not be set.
ignoreFirstRow - boolean or undefined, if it is undefined, it will not be set. If is dependencies data, should take an array like this: var dependencies = [ {from: 0, to: 3}, //ids {from: 0, to: 4}, {from: 1, to: 2}, {from: 4, to: 5} ]; |
Returns:
anychart.data.TreeView - Self instance for method chaining.Try it:
filter
Filters the tree data items using the filter-function.
Detailed description
The filter function accepts a data item as a parameter. After the action with the data item, the function must return a value of "true"
or "false", specifying whether to include this data item in the result of the filtering or not.
Note: the filter performs a full data passage.
Note: the filter performs a full data passage.
Params:
Name | Type | Description |
---|---|---|
filterFunction | function(item:anychart.data.Tree.DataItem|anychart.data.TreeView.DataItem) | Filter function. |
Returns:
Array.<(anychart.data.Tree.DataItem|anychart.data.TreeView.DataItem)> - An array of data items.Try it:
getChildAt
Gets the child by index.
Params:
Name | Type | Description |
---|---|---|
index | number | Index of child to find. |
Returns:
anychart.data.TreeView.DataItem | undefined - Child into a specified position.Try it:
getChildren
getTraverser
Creates tree view data traverser.
Returns:
anychart.data.Traverser - An instance of the class for method chaining. See listing.
var rawdata = [ {id: 1, children: [ {id: 2, children: [ {id: 3}, {id: 4, children: [ {id: 5}, {id: 6} ]} ]}, {id: 7, children: [ {id: 8} ]} ]} ]; var treeData = anychart.data.tree(rawdata, anychart.enums.TreeFillingMethod|string.TREE); var mapping = treeData.mapAs({"name": "id"}; // Creates traverser mapping.getTraverser();
indexOfChild
Gets the index of child in a children array.
Params:
Name | Type | Description |
---|---|---|
child | anychart.data.Tree.DataItem | anychart.data.TreeView.DataItem | Child for getting of index. |
Returns:
number - Index of child.Try it:
numChildren
removeChild
Removes data item's child.
Params:
Name | Type | Description |
---|---|---|
child | anychart.data.Tree.DataItem | anychart.data.TreeView.DataItem | Child for removal. |
Returns:
anychart.data.TreeView.DataItem - An instance of the class for method chaining.Try it:
removeChildAt
Removes child at the specified position.
Params:
Name | Type | Description |
---|---|---|
index | number | Index of item to be removed. |
Returns:
anychart.data.TreeView.DataItem - Removed item or null if item is not found.Try it:
removeChildren
search
Performs a data search.
Learn more about searching.
Detailed description
Returns null if nothing is found, tree data item if there's a single result and an array of tree data items if there are multiple matches.
The search method is used to find the exact value.
The difference between the search method and the anychart.data.Tree#filter method:
- search is much faster when there is an index on a field
- this method is based on the binary search
Params:
Name | Type | Description |
---|---|---|
field | string | Search field name. |
value | * | Value to be found. |
comparisonFn | function(value1:*, value2:*) | An optional comparison function by which the array is ordered. Should take 2 arguments to compare and return a negative number, zero, or positive number depending on whether the first argument is less than, equal to or greater than the second. |
Returns:
anychart.data.Tree.DataItem | Array.<anychart.data.Tree.DataItem> | null - The found tree data item or null or array of found tree data items.Try it:
searchItems
Performs a data search.
Learn more about searching.
Detailed description
Actually does the same as (anychart.data.TreeView#search) but result is always an array.
The searchItems method is used to find the exact value.
The difference between the searchItems method and the anychart.data.Tree#filter method:
- search is much faster when there is an index on a field
- this method is based on the binary search
Params:
Name | Type | Description |
---|---|---|
field | string | Search field name. |
value | * | Value to be found. |
comparisonFn | function(value1:*, value2:*) | An optional comparison function by which the array is ordered. Should take 2 arguments to compare and return a negative number, zero, or positive number depending on whether the first argument is less than, equal to or greater than the second. |
Returns:
Array.<anychart.data.Tree.DataItem> - An array of found tree data items. If nothing is found, the array is returned empty.Try it: