Giter Site home page Giter Site logo

zlyzly / ng2-dropdown-treeview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leovo2708/ng2-dropdown-treeview

1.0 2.0 0.0 86 KB

An Angular 2 tree component with checkbox and multiple level

License: MIT License

JavaScript 11.32% TypeScript 88.68%

ng2-dropdown-treeview's Introduction

ng2-dropdown-treeview Build Status npm version

An Angular 2 tree component with checkbox and multiple level.

This component is discontinued anymore. It's compatible with both Angular 2 & 4.
But if you are using Angular 4, should switch to my new component ngx-treeview


Dependencies

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

Features

  • Unlimited tree levels
  • Item state: checked, disabled
  • Collapse / Expand
  • Text filtering
  • Internationalization (i18n) support
  • Template

Demo

https://embed.plnkr.co/1kcbUvNze8HAJ0tN0wsX/

Installation

After install the above dependencies, install ng2-dropdown-treeview via:

npm install --save ng2-dropdown-treeview

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

import {DropdownTreeviewModule} from 'ng2-dropdown-treeview';

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

Usage

Treeview dropdown:

<leo-dropdown-treeview
    [config]="config"
    [items]="items"
    (selectedChange)="onSelectedChange($event)">
</leo-dropdown-treeview>

Treeview without dropdown:

<leo-treeview
    [config]="config"
    [items]="items"
    (selectedChange)="onSelectedChange($event)">
</leo-treeview>

config is optional. This is the default configuration:

{
   isShowAllCheckBox: true,
   isShowFilter: false,
   isShowCollapseExpand: false,
   maxHeight: 500
}

You can change default configuration easily because TreeviewConfig is injectable.

Pipe leoTreeview:

To map your JSON objects to TreeItem objects.

<leo-dropdown-treeview
    [config]="config"
    [items]="items | leoTreeview:'textField'"
    (selectedChange)="onSelectedChange($event)">
</leo-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 }
           ]
       }
   ]
});

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.

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.

TreeviewItem Template:

See example 4.

Contributing

I am very appreciate for your ideas, proposals and found bugs which you can leave in github issues. Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.