Questions tagged [ngx-treeview]

ngx-treeview

An Angular treeview component with checkbox

Dependencies

You can customize CSS yourself to break down dependencies to Bootstrap & Font Awesome.

Features:

  • maxCount can select up to a few items
  • isShowTotal Checks the displayed result style type
  • Change the default checked to selected to unchecked
  • Change the default item to checked = true to false
  • Unlimited tree level
  • State: disabled / collapse, expand
  • Filtering
  • Internationalization (i18n) support
  • Template

Installation

After install the above dependencies, install ngx-treeview via:

npm install --save mizi-ngx-treeview

Once installed you need to import our main module in your application module:

import { TreeviewModule } from 'ngx-treeview';

@NgModule({
  declarations: [AppComponent, ...],
  imports: [TreeviewModule.forRoot(), ...],  
  bootstrap: [AppComponent]
})
export class AppModule {
}

Usage

Treeview:

<ngx-treeview
    [config]="config"
    [items]="items"
    (selectedChange)="onSelectedChange($event)">
</ngx-treeview>
Treeview with dropdown:
<ngx-dropdown-treeview
    [config]="config"
    [items]="items"
    (selectedChange)="onSelectedChange($event)">
</ngx-dropdown-treeview>

config is optional. This is the default configuration:

{
   isShowAllCheckBox: true,
   isShowFilter: false,
   isShowCollapseExpand: false,
   maxHeight: 500,
   maxCount: 0,
   isShowTotal: true
}

You can change default configuration easily because TreeviewConfig is injectable.

Pipe ngxTreeview: To map your JSON objects to TreeItem objects.

<ngx-dropdown-treeview
    [config]="config"
    [items]="items | ngxTreeview:'textField'"
    (selectedChange)="onSelectedChange($event)">
</ngx-dropdown-treeview>  

Create a TreeviewItem:

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 }
           ]
       }
   ]
});

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.

Refrence

22 questions
0
votes
2 answers

How do I strip this JSON in Angular?

I have a JSON, from which I need to strip down the name and position values of every subFolder to picture the folder structure from inside the JSON in a ngx-treeview in Angular. I only want to have the subFolders, including the templates in the…
Munchkin
  • 857
  • 5
  • 24
  • 51
0
votes
1 answer

ngx-treeview showing wrong tree structure. Where is wrong?

I am following the same JSON format as given in ngx-treeview. The JSON file: [ { "internalDisabled": false, "internalChecked": false, "internalCollapsed": false, "text": "JOURNEY", "value": 1 }, { "internalDisabled":…
0
votes
0 answers

I want to use my custom filter and not the one in the ngxTreeView

The tree view items were display as it expected but I want to use my own filter and not the filter in ngx-treeview(please see the link below). https://leovo2708.github.io/ngx-treeview/#/advanced I have already mapped the items in tree view display.…
Eduwow
  • 95
  • 1
  • 11
0
votes
1 answer

Check a recursive JSON structure for matchinig numerical values in Set in Typescript Angular

I have a UI where initially a User has to check some checkboxes. The checkboxes have sequential IDs. The JSON Structure for it is as follows: { "categories": [{ "name": "Product", "labels": [{ "id": 1, "name": "I work on an…
Shan-Desai
  • 3,101
  • 3
  • 46
  • 89
0
votes
1 answer

how to make indeterminate checkbox checked in ngx-treeview

I am using this library https://leovo2708.github.io/ngx-treeview/#/components. However I have requirement that i need to show parent node as checked if any child is checked. So instead of indeterminate state, I need to show it as checked.. is it…
josh_boaz
  • 1,963
  • 7
  • 32
  • 69
0
votes
0 answers

Library similar to ngx-treeview that supports anugluar 7?

Just upgraded my project from angular 5 to angular 7, but found out that ngx-treeview does not support angular 7. No errors were shown that could be related to the plugin, but whenever a new plugin is add or remove. Warning about npm WARN…
roger
  • 1,225
  • 2
  • 17
  • 33
-1
votes
1 answer

Checkbox hierarchy with dynamic json using ngx-treeview

I am trying to achieving ngx-treeview kind UI using my dynamic json response. But It gives me error like below: not assignable to type treeitem Below is my json : { "id": "2", "parentId": "0", "value": "banks", "children": [ { …
1
2