#Pragma Treeview
The pragma treeview has a number of build in features that make it very performant and flexable.
This document will describe on a high level on how to use the tree view.

```json
<pragma-treeview id="schemaTree" templates.bind="templates" parent-key="parentId" search-fields.bind="['name']"></pragma-treeview>
```

All the above properties must be filled in as they are required for operations inside the treeview.
1. Id of tree must be unique.
1. templates define what HTML to use depending on the model representing a tree view item.
1. parent key is the field on the model that defines what the parent model id is.
1. search fields define what property names should be used for the search operations to filter a selected branch.

#Code
Talking to the tree is done using event aggregation based on the id you gave the tree view.
Lets say that you have define a treeview called "schemaTree", the following are examples of hooking up events for the tree.

```json
    this.schemaTreeRequestEvent = this.eventAggregator.subscribe("schemaTree:get", this.schemaTreeRequestHandler);
    this.getRootEvent = this.eventAggregator.subscribe("schemaTree:getRoot", this.getRootHandler);
    this.selectedEvent = this.eventAggregator.subscribe("schemaTree:selected", this.selectedHandler);
```

1. get: called when you are trying to expand a branch
1. getRoot: called when the tree want's to build the root level of the tree, also fired on refresh of tree.
1. selected: called when a selection is made on the treeview.

sending information to the tree is also done via event aggregation.

### sending root data to the treeview when getRoot was fired
```json
this.eventAggregator.publish("schemaTree:getRootResponse", {
    parentId: -1,
    data: data
});
```

### refresh a branch with a particular dataset
```json
    this.eventAggregator.publish("schemaTree:push", {
        parentId: parentId,
        data: result
    });
```

This an be done at any time and is typically done when responding to the get defined above.
Note that this will remove all the previous children for the parent defined and populated with the new list.

if you do not want to refresh the entire branch but just append to a existing branch, this can be done using append.
```json
this.eventAggregator.publish("schemaTree:append", {
    parentId: 1,
    data: [dataset]
});
```