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 index of child in a children array. |
| numChildren() | Returns a length of roots array. |
| removeChild() | Removes data item's child. |
| removeChildAt() | Removes child at specified position. |
| removeChildren() | Removes children. |
| search() | Performs a data search. |
| searchItems() | Performs a items search. |
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 | 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:
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.TREE);
var mapping = treeData.mapAs({"name": "id"};
// Creates traverser
mapping.getTraverser();indexOfChild
Gets 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 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.
Detailed description
Returns null of nothing is found, tree data item if here's a single result and array of
tree data items if here are multiple matches.
Params:
| Name | Type | Description |
|---|---|---|
| soughtField | string | Field for search. Literally means the name of field of data item. |
| value | string | number | boolean | Sought value. |
| comparisonFn | function | Object | Custom comparison function. Optional comparison function by which the array is ordered. Should take 2 arguments to compare, and return a negative number, zero, or a positive number depending on whether the first argument is less than, equal to, or greater than the second. |
Returns:
anychart.data.TreeView.DataItem | Array.<anychart.data.TreeView.DataItem> | null - Found tree data item or null or array of found tree data items.Try it:
searchItems
Performs a data item search.
Detailed description
Performs a data search. Actually does the same as (anychart.data.TreeView#search) but result is always an array.
Params:
| Name | Type | Description |
|---|---|---|
| soughtField | string | Field for search. Literally means the name of field of data item. |
| value | string | number | boolean | Sought value. |
| comparisonFn | function | Object | Custom comparison function. |
Returns:
Array.<anychart.data.TreeView.DataItem> - Array of found tree data items.Try it:
