Code Monkey home page Code Monkey logo

ng.tree's Introduction

rename from angular4-tree to ng.tree!

document

live demo

screenshot

screenshot screenshot screenshot screenshot

NPM

npm install ng.tree

Release notes

  • 2017/4/23——rename from angular4-tree to ng.tree!
  • 2017/4/23——publish to npm

#TODO

  • search
  • drag and drop

Classes & Api

NgTree

ngTree component. useage : <ngTree [treeData]="TreeData[]" [treeConfig]="TreeConfig">

  • public searchNodes(nodes:any[], condition:string|{[key:string]:any}, ignoreCase?:boolean):any[],only work for tree root instance
  • public findNodeSiblings(node:any):any[],only work for tree root instance
  • public findNodeParent(node:any):any,only work for tree root instance, if node belongs to root, return an empty object, otherwise return null

TreeData

data for creating tree

  • name?:string,tree node name
  • isOpen?:boolean,collapse or not(node has subtree)
  • iconClass?:string|boolean,a class selector add to icon element, false to disable node icon
  • nameClass?:string,a class selector add to name element
  • children?:TreeData[],sub tree data
  • isChecked?:boolean,is checked
  • tools?: {name:string, iconClass:string, title?:string}[],customized edit button

TreeConfig

  • onFold? : (node?:any) => boolean;,execute before treenode collapse or uncollapse, returns false to disable the default action
  • onClick? : (node?:any) => void;,trigger on icon or name click
  • onDragstart? : (event:MouseEvent , node?:any, parent?:any, siblings?:any, index?:number) => boolean;
  • onDrop? : (event:MouseEvent , node?:any, parent?:any, sibliings?:any, index?:number, position?:string) => void;
  • onDragend? : (event:MouseEvent , node?:any, parent?:any, sibliings?:any, index?:number, position?:string) => void;
  • onDragover? : (event:Event, node?:any, parent?:any, sibliing?:any, index?:number) => boolean;,return true to enable drop
  • onToolClick? : (node?:any, toolname?:string) => void;trigger on tool button click
  • dataFilter?: (nodeData?:any) => any,format customized data to TreeData. effect on tree init
  • tools?: {name:string, iconClass:string, title?:string}[],customized edit button
  • enableTools?:boolean,enable toolbar or not
  • dataMap?any,format customized data to TreeData
    • dataMap.name?:string,default to "name"
    • dataMap.isOpen?:string,deafult to 'isOpen'
    • dataMap.iconClass?:string,default to "iconClass"
    • dataMap.nameClass?:string,default to "nameClass"
    • dataMap.children?:string,default to "children"
    • dataMap.isChecked?:string,default to "isChecked"
    • dataMap.tools?:string,default to "tools"
    • dataMap.enableTools? : string,default to "enableTools"

#Usage & demo talk is cheape, show you my code

##step 1 import css

<link rel="stylesheet" href="../node_modules/ng-tree/style/tree.css">

##step 2 use it

import {Component, NgModule} from '@angular/core';
import {BrowserModule} from "@angular/platform-browser";
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {NgTree} from "ng.tree";

@Component({
	selector: 'app',
	template: `<ngTree [treeData]="treeData" [treeConfig]="treeConfig"></ngTree>`
})
export class App {
	public treeData: any[] = [{
		name: "folder",
		isOpen:true,
		iconSelector:"computer",
		nameSelector:"warning",
		nodes: [{
			name: 'file'
		}]
	},{
		name: 'another folder',
		nodes:[{
			name: 'another file'
		}]
	}];
	
	public treeConfig : any = {
		dataMap:{
			children:"nodes"
		}
	}
}

@NgModule({
	imports: [BrowserModule],
	entryComponents:[NgTree],
	declarations: [NgTree, App],
	bootstrap: [App]
})
export class AppModule {}
platformBrowserDynamic().bootstrapModule(AppModule);

ng.tree's People

Contributors

1inus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ng.tree's Issues

Template Node

Hi,
I just want to know if we can use template nodes like i want and div with contenteditable true for each node.

on angular4 erro

NgTree.html:1 ERROR TypeError: Cannot read property 'tools' of undefined

at Object.View_NgTree_1.co [as updateDirectives] (NgTree.html:1)

......
thank

How to custom edit tools?

Q1:
In your code,the tools is required iconClass
image
but,in your doc,
image
only need name and title....

Q2:
Finally,i added the edit tools,but....the style is strange..
image
en...that's not important..

Q3:
When i click the tool, can not console the expect result..
and my code is like this..
image
the result is like this..
image

Add angular 5 support.

Hi, I recently upgraded my angular-cli project from v4.4 to v5 and using

@NgModule({
	imports: [BrowserModule],
	entryComponents:[NgTree],
	declarations: [NgTree, App],
	bootstrap: [App]
})

npm start leads to: ERROR in Error: NgTree cannot be used as an entry component. and ng serve --aot leads to: ERROR in Error: Unexpected value 'NgTree in ../node_modules/ng.tree/ng.tree.d.ts' declared by the module 'PagesModule in pages.module.ts'. Please add a @Pipe/@Directive/@Component annotation.

Hope you can fix this soon.

No icon?

Apologize for a newbie question: I'm not seeing icons being loaded and no indentation of the listed tree items. What am I missing?

issue compiling project

Hello I'm having this when compiling my project
Unexpected value 'NgTree in .../node_modules/ng.tree/ng.tree.d.ts' declared by the module 'AppModule in app.module.ts'. Please add a @Pipe/@Directive/@component annotation.

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.