# @joniras/ngx-treeview

> An Angular 8+ treeview component with checkbox

Latest version **6.1.1** (published 2020-03-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @joniras/ngx-treeview
pnpm add @joniras/ngx-treeview
yarn add @joniras/ngx-treeview
bun add @joniras/ngx-treeview
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.1.1 |
| Published | 2020-03-25 |
| First published | 2019-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 681.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Leo Vo |
| Maintainers | joniras |
| Keywords | ng, ngx, angular, ngx-treeview, tree, treeview, tree-view, checkbox, dropdown, recursive, angular tree component |

## Links

- npm: https://www.npmjs.com/package/@joniras/ngx-treeview
- Repository: https://github.com/Firmstep/ngx-treeview
- Homepage: https://github.com/Firmstep/ngx-treeview#readme
- Issues: https://github.com/Firmstep/ngx-treeview/issues
- npm.io page: https://npm.io/package/@joniras/ngx-treeview

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.9.0

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 6.1.1 (latest) — 2020-03-25
- 6.1.0 — 2019-12-12

## README

# ngx-treeview

An Angular 8+ treeview component with checkbox

## Dependencies

* [Angular](https://angular.io)
* [Lodash](https://lodash.com)


## Features

* Unlimited tree level
* State: disabled / collapse, expand
* Filtering
* Internationalization (i18n) support
* Template
* Checkbox with tri-state

## Demo

NOT MINE: [https://leovo2708.github.io/ngx-treeview/](https://leovo2708.github.io/ngx-treeview/)
([Source code](https://github.com/Joniras/ngx-treeview/tree/master/src/demo))

## Installation

After install the above dependencies, install `ngx-treeview` via:
```shell
npm install @joniras/ngx-treeview --save
```
Once installed you need to import our main module in your application module:
```js
import { TreeviewModule } from 'ngx-treeview';

@NgModule({
  declarations: [AppComponent, ...],
  imports: [TreeviewModule.forRoot(), ...],  
  bootstrap: [AppComponent]
})
export class AppModule {
}
```

## Usage

#### Treeview:
```html
<ngx-treeview
    [config]="config"
    [items]="items"
    (selectedChange)="onSelectedChange($event)"
    (filterChange)="onFilterChange($event)">
</ngx-treeview>
```

#### Treeview with dropdown:
```html
<ngx-dropdown-treeview
    [buttonClass]="buttonClass"
    [config]="config"
    [items]="items"
    (selectedChange)="onSelectedChange($event)"
    (filterChange)="onFilterChange($event)">
</ngx-dropdown-treeview>
```

 `config` is optional. This is the default configuration:
 ```js
 {
    hasAllCheckBox: true,
    hasFilter: false,
    hasCollapseExpand: false,
    decoupleChildFromParent: false,
    maxHeight: 500
}
```
You can change default configuration easily because TreeviewConfig is injectable.

#### Pipe `ngxTreeview`:
To map your JSON objects to TreeItem objects.
```html
<ngx-dropdown-treeview
    [config]="config"
    [items]="items | ngxTreeview:'textField'"
    (selectedChange)="onSelectedChange($event)">
</ngx-dropdown-treeview>
```

#### Create a TreeviewItem:
 ```js
 const itCategory = new TreeviewItem({
    text: 'IT', value: 9, children: [
        {
            text: 'Programming', value: 91, children: [{
                text: 'Frontend', value: 911, children: [
                    { text: 'Angular 1', value: 9111 },
                    { text: 'Angular 2', value: 9112 },
                    { text: 'ReactJS', value: 9113 }
                ]
            }, {
                text: 'Backend', value: 912, children: [
                    { text: 'C#', value: 9121 },
                    { text: 'Java', value: 9122 },
                    { text: 'Python', value: 9123, checked: false }
                ]
            }]
        },
        {
            text: 'Networking', value: 92, children: [
                { text: 'Internet', value: 921 },
                { text: 'Security', value: 922 }
            ]
        }
    ]
});
```

You can pass the second paramater 'autoCorrectChecked' with value=true (default is false) in constructor of TreeviewItem to correct checked value of it and all of its descendants. In some cases, you need to push or pop children flexibly, checked of parent may be not correct. Then you need to call function correctChecked() to help to correct from root to its descendants.
 ```js
const vegetableCategory = new TreeviewItem({
    text: 'Vegetable', value: 2, children: [
        { text: 'Salad', value: 21 },
        { text: 'Potato', value: 22 }
    ]
});
vegetableCategory.children.push(new TreeviewItem({ text: 'Mushroom', value: 23, checked: false }));
vegetableCategory.correctChecked(); // need this to make 'Vegetable' node to change checked value from true to false
 ```

#### TreeviewEventParser:
Extract data from list of checked TreeviewItem and send it in parameter of event selectedChange. Some built-in TreeviewEventParser:
* DefaultTreeviewEventParser: return values of checked items.
* DownlineTreeviewEventParser: return list of checked items in orginal order with their ancestors.
* OrderDownlineTreeviewEventParser: return list of checked items in checked order with their ancestors. Note that: value of a leaf must be different from value of other leaves.

#### Templating:
See example 4 & 5.

## Contributing

I am very appreciate for your ideas, proposals and found bugs which you can leave in github issues. Thanks in advance!

---
_Source: https://npm.io/package/@joniras/ngx-treeview · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
