DESCRIPTION
An Angular 6/7/8+ TREE COMPONENT with checkbox and search. Just send a nested JSON as input, bn-ng-tree component will render the nested JSON as a tree view in your Angular app.
Note: Install font-awesome 4.7 to display icons in tree.
INSTALLATION
npm install bn-ng-tree-lib
BN NG TREE - FEATURES
USAGE
Import the bn-ng-tree in the module
;......imports: ... BnNgTreeModule
bn-ng-tree
selector in the component html
Add the
It accepts [items]
as input which should be a nested array of objects for the tree. Every object in the items array must have name
and children
property.
Get the Selected Node in the Tree Component
bn-ng-tree
component outputs the onChange
event whenever the user clicks the select arrow button of the node. In the $event
you will get the selected Object of the node in the tree.
Show Select Button
You can show / hide the select arrow button using show-select-btn
input property. By default, It's false.
Search Tree Component
The tree component search will be triggered onChange
and keypress.enter
events.
You can enable / disable search option by using show-search
input in bn-ng-tree. It accepts boolean. By default search option is enabled.
Enable Search
Disable Search
Show Child Nodes Count
You can show the number of child nodes beside the node using show-counts
input property. By default it's false.
Change Tree Theme
Bn Ng Tree has built in themes.
- primary
- secondary
- tertiary
Custom CSS
You can add your css class to the bn-ng-tree
using style-class
input property. It accepts the class name as string.
Show Checkbox
To show checkbox, add the [show-checkbox]
to true
in the bn-ng-tree
Enable auto checkbox selection in child nodes
On parent node check, all the child nodes will gets checked if you use [auto-check-child]
property binding.
Disable Checkbox
You can disable all checkbox in the tree using [disable-checkbox]='true'
property. By default it's false
Get Checked/Unchecked nodes from Tree
To get the checked and unchecked items from the bn-ng-tree, Use onChecked output event which emits an event everytime a user checks/unchecks a node in the bn-ng-tree. It returns an object with checked
and unchecked
properties which are array of checked/unchecked items.
{ console; console;} // console output sample // CHECKED ITEMS "name":"Tanzania" "children": "name":"Area one" "children": "checked":true "name":"Area Two" "children": "checked":true "expanded":true "checked":true "name":"Area one" "children": "checked":true "name":"Area Two" "children": "checked":true // UNCHECKED ITEMS "name":"South Africa" "children": "name":"Johnesberg" "children": "checked":false "name":"Area three" "children": "checked":false "expanded":true "checked":false "name":"Johnesberg" "children": "checked":false "name":"Area three" "children": "checked":false
Sample Code
app.module.ts
;;;;
app.component.html
Angular 6 Tree Component Selected Item Name: {{ currentItem.name }}
app.component.ts
;
VERSIONING
1.6.3 - Disable All Checkbox.
1.6.2 - Highlight selected node.
1.6.0 - Show Child Counts. Custom CSS. Theme Designs Changed. Checkbox Selection Bug Fixed.
1.5.0 - Checkbox auto child selection. Search feature is case insensitive now.
1.4.1 - Bug Fixes, Documentation Updated.
1.4.0 - Checkbox option for Angular Tree
1.3.0 - Theme option for tree
1.2.2 - Enable / Disable Search Option
1.1.0 - Search Added for the recursive tree.