Git Product home page Git Product logo

circlongroup / angular-tree-component Goto Github PK

View Code? Open in Web Editor NEW
1.1K 39.0 482.0 32.95 MB

A simple yet powerful tree component for Angular (>=2)

Home Page: https://angular2-tree.readme.io/docs

License: MIT License

TypeScript 70.15% HTML 13.69% JavaScript 6.98% CSS 3.48% SCSS 5.71%
angular angular5 angular2 angular4 tree-component frontend frontend-components treeview tree typescript

angular-tree-component's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-tree-component's Issues

Unexpected value 'TreeModule' imported by the module 'X'

I have downloaded the code from the master branch, built the code and tried to then use it in my application....

Now for some reason i get the error above?

In my module, i am doing this

import { NgModule }           from '@angular/core';
import { CommonModule }       from '@angular/common';
import { FormsModule }        from '@angular/forms';
import { SharedModule } from '../shared/shared.module';
import { TreeModule } from 'angular2-tree-component/dist/angular2-tree-component';

import { PageComponent }   from './page.component';

import { routing } from './page.routing';

@NgModule({
    imports:        [ CommonModule, FormsModule, routing, SharedModule, TreeModule ],
    declarations:   [ PageComponent ]
})

export class PageModule {
}

I dont see anything wrong with what i have done?? Can someone help at all.

I have tried this with angular rc6 and rc7

option for auto-expanding a field

It would be nice to be able to say "this is expanded by default" - perhaps by doing expanded: true on the object. I don't want my tree to always be collapsed by default.

Rebuilding a tree after changing of some nodes

Suppose I have the following model which I pass to the tree component:

nodes = [{
    name: 'test',
    children: [{
        name: 'test-child'
    }]
}];

Now, if I do the following

    nodes[0].name = 'test changed';

the displaying text will be changed.

But, if I perform this code

    nodes[0].children.push({name: 'test-child-2'});

or even this one,

    nodes[0].children = [{name: 'test-child-2'}];

nothing will be changed in the tree. It will display only the "test-child" node.

Is there any way to track these changes and rebuild the corresponding part of the tree? If no, is it possible to implement it?

RC.2 Support

Please update dependencies to support Angular 2 RC.2.

Upgraded to 1.2.1 still can't bind

I still get this:

Can't bind to 'nodes' since it isn't a known property of 'Tree'. ("

                <Tree #tree 
                      [ERROR ->][nodes]="nodes" 
                      >

<page-header [title]="'Coaching Planner'">

<div class="row">
    <div class="col-md-3">
        <div class="panel panel-default">
            <div class="panel-heading">User Selection</div>
            <div class="panel-body tree-container" style="overflow-y:auto;">

                <Tree #tree 
                      [nodes]="nodes" 
                      >

                </Tree>
                <button (click)="tree.treeModel.filterNodes('Derek');">next node</button>
                <div class="form-group" id="select-preset">
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-9">
        <div class="panel panel-default">
            <div class="panel-heading">Pre-defined Reports</div>
            <div class="panel-body">
                <div class="form-group" id="select-preset">
                    Select Preset Reports (optional)
                    <select class="form-control" id="selectpreset">
                        <option value="" disabled selected>Select your report preset</option>
                        <option aria-label="All Stars">All Stars</option>
                        <option>Business By Section</option>
                        <option>Business By Product</option>
                        <option>Advisor Pass or Fail</option>
                        <option>Staff Listing</option>
                    </select>
                </div>
            </div>
        </div>
    </div>

import { Component, NgModule } from '@angular/core';
import { Router } from '@angular/router';
import { TreeComponent } from 'angular2-tree-component';

@component({
selector: 'coaching-planner',

templateUrl: 'app/coaching-planner/coaching-planner.component.html',
styleUrls: ['app/coaching-planner/coaching-planner.component.css']

})

@NgModule({
imports: [TreeComponent]
})

export class CoachingPlannerComponent{
data = "[{"name":"Jared Gould","...............

nodes: any = [];


constructor(private router: Router) {

}

ngOnInit(): void {


    this.nodes = JSON.parse(this.data);


}
myFilterNodes(): void  {
    TreeComponent
    console.log("hey!!!!!!!!!!!");

}
gotoDetail(): void {

}

}

Documentation incorrect

Under configuration, the new context option, this part includes an option called template, which should actually be treeNodeTemplate

MyComponent {
  treeOptions = {
    template: '{{ node.data.name }} <button ng-click="context.doSomething()">Go!</button>'
    context: this
  }

  doSomething() {
  }
}

should be

MyComponent {
  treeOptions = {
    treeNodeTemplate: '{{ node.data.name }} <button ng-click="context.doSomething()">Go!</button>'
    context: this
  }

  doSomething() {
  }
}

SystemJS & Lodash

Currently we must load lodash manually into the project when using systemJS.
This should be solved.

I suspect it's got something to do with lodash being defined as ambient dependency.

Issue with event.preventDefault

In my case I have a form inside a tree node and I want to use the SPACE key but preventDefault() is preventing me of adding white spaces in my input fields. Can you give me a suggestion how can I resolve that or maybe you plan to refactor that in the future?

tree.treeModel.roots returns []

I want to collapse, expand roots after initialization.

I have initialized a tree with 1 root, which has several children.
I have defined the tree as a ViewChild, and after console.logging the tree I can see in the console, that roots in treeModel is an array of length 1. But after console.logging tree.treeModel.roots I get empty array.

RC7

Hello
The package.json is still referencing RC7. Can you update it to use 2.0.0 instead ?

Cheers

Upgraded to Angular 2.0.0, binding problems now

Hi

I'm getting this error after upgrading to Angular 2.0.0.

[email protected]?main=browser:344 Unhandled Promise rejection: Template parse errors:
Can't bind to 'nodes' since it isn't a known property of 'Tree'. ("<Tree #tree
[ERROR ->][nodes]="nodes"
[focused]="true"
[options]="o"): CoachingPlannerComponent@9:26

This used to work before I upgrade, and I haven't changed anything else.

This is my template code.
<Tree #tree [nodes]="nodes" [focused]="true" [options]="options"> </Tree>

`import { Component, NgModule } from '@angular/core';
import { Router } from '@angular/router';
import { TreeComponent } from 'angular2-tree-component';

@component({
selector: 'coaching-planner',

templateUrl: 'app/coaching-planner/coaching-planner.component.html',
styleUrls: ['app/coaching-planner/coaching-planner.component.css']

})

@NgModule({
declarations: [TreeComponent]
})

export class CoachingPlannerComponent{

data: any = "DELETE FOR EXAMPLE THIS WORK BEFORE THOUGH"
nodes: any = [];


constructor(private router: Router) {

}

ngOnInit(): void {


    this.nodes = JSON.parse(this.data);


}
myFilterNodes(): void  {
    TreeComponent
    console.log("hey!!!!!!!!!!!");

}
gotoDetail(): void {

}

}
`

Thanks,
Carmen

onDeactivate event doesn't fire when another node is activated

If you activate a node and then activate a different node without multiselect, there is no onDeactivate event fired for the first node. This basically forces you to maintain your own list of selected nodes instead of relying on the tree to handle it for you.

I'd submit a PR, but I want to wait until you decide what to do with #43.

Template parse errors in RC6

With RC6 all components and pipes must now be declared via an NgModule. Unfortunately the following error message pops up since updating:

Can't bind to 'node' since it isn't a known property of 'TreeNode'. ("
      <TreeNode
        *ngFor="let node of treeModel.roots"
        [ERROR ->][node]="node">
      </TreeNode>
    </div>
"): TreeComponent@4:8

Any clue on this?

Feature - allow configuring indentation

Need to support these options:

  • children padding - default
    • allow to supply a method that returns the children padding for each node
  • per node padding
    • calculated by default as X * node.level
    • allow to override X
    • allow to supply a method that returns the padding for each node

tree ready

How to event tree ready?
@ViewChild('treeProcessi') private tree:TreeComponent;

onInizialized tree is undefined.

ngAfterViewChecked is called many times for tree variable.

Thanks

Move from "typings" to "@types/XXX"

The current setup will error when the local system does not have the typings global module.

There is a post install script that runs typings.

Since typings is fading away and @types is the de facto solution for type definition, maintained by MS I suggest moving to it.

Reliability, and `toggle() is deprecated, please use toggleExpanded()`

I notice the expansion of nodes can be rather unreliable (sometimes clicking does nothing), and this warning pops up in the console when it actually does expand:
toggle() is deprecated, please use toggleExpanded()

Your demo does not have the reliability issue, but does still throw that warning up in the console.

I am using System.js if that makes a difference for this issue.

Using custom template, how can i call function that the tree component is on?

I have a tree that displays nodes. On each node i have a custom template, which offers the options Edit, Copy and Delete. When one of these options is pressed, i would like to open a modal window (using ng2-bootstrap) and ask the user to confirm their action.

Now i can do this, if I create a modal window in the custom template, but that seems like a lot of HTML to repeat for each node, so instead i would like to have my ModalComponent on the same component as my tree, and somehow raise an event when a button in a template is pressed....

How can i do this? Here is what i have so far

pages.component.html

<Tree #tree [nodes]="nodes" [options]="options"></Tree>

<div *ngIf="tree.activeNode">
   <!-- got modal here instead of within each node template!! //-->
    <page-copy-modal #copyModal="copyModal" [page]="tree.activeNode.data"></page-copy-modal>
</div>

pages.component.ts

import { Component, OnInit } from '@angular/core';
import { TreeComponent } from 'angular2-tree-component';
import { PagesTreeNodeComponent } from './pages-tree-node.component';
import { PageCopyModalComponent } from './page-copy-modal.component';

@Component({
    selector: 'pages',
    templateUrl: 'app/admin/page/pages.component.html',
    directives: [ TreeComponent, RouterLink, PageCopyModalComponent ]
})

export class PagesComponent implements OnInit {

    nodes: Page[];
    options: Object = {
        treeNodeTemplate: PagesTreeNodeComponent
    };

    ngOnInit() {
        // nodes loaded here
    }

   // need these functions to be called from pages-tree-node-component.ts
   onEdit () { }
   onCopy () { }
   onDelete () { }
}

pages-tree-node.component.html

{{ node.displayField }}
<div class="pull-sm-right options">
    <a (click)="onEdit()">Edit</a> |
    <a (click)="onCopy()">Copy</a> |
    <a (click)="onDelete()">Delete</a>
</div>

pages-tree-node.component.ts

import { Component, Input } from '@angular/core';
import { Router } from '@angular/router-deprecated';
import { TreeNode } from 'angular2-tree-component';

@Component({
    selector: 'pages-tree-node',
    templateUrl: 'app/admin/page/pages-tree-node.component.html'
})

export class PagesTreeNodeComponent {

    @Input()
    node: TreeNode;

    // on editing a page
    onEdit() {
        // call event on PagesComponent for edit??
    }

    onCopy() {
        // call event on PagesComponent for copy??
    }

    onDelete() {
        // call event on PagesComponent for delete??
    }
}

page-copy-modal.component.html

<div bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Copy page</h4>
            </div>
            <div class="modal-body">
                Are you sure you want to copy this page, all its contents and all of it's child pages?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-outline-primary" (click)="onCopy()" aria-label="Copy">
                    Copy
                </button>
                <button type="button" class="btn btn-outline-secondary" (click)="lgModal.hide()" aria-label="Cancel">
                    Cancel
                </button>
            </div>
        </div>
    </div>
</div>

page-copy-modal.component.ts

import { Component, Input, ViewChild} from '@angular/core'
import { CORE_DIRECTIVES } from '@angular/common'
import { MODAL_DIRECTIVES } from 'ng2-bootstrap/components/modal';
import { ComponentsHelper } from 'ng2-bootstrap/components/utils/components-helper.service';

@Component({
    selector: 'page-copy-modal',
    directives: [ MODAL_DIRECTIVES, CORE_DIRECTIVES ],
    viewProviders: [ ComponentsHelper ],
    templateUrl: 'app/admin/page/page-copy-modal.component.html',
    exportAs: 'copyModal'
})

export class PageCopyModalComponent {

    @ViewChild('lgModal') 
    lgModal;

    @Input: any
    page;

    show(){
        this.lgModal.show();
    }

    onCopy() {

    }
}

Clicking on Parent node does not change the icon to down arrow

I am using angular2-tree-component with webpack and all the functionality works just fine. The only issue I see is that if I click on a parent node that has one or more children, the icon of the parent node does not change to the down arrow when the parent node is in expanded state.
From what I can see I dont need to add any CSS files, it should just work. What am I missing?
Thanks.

Js files?

The npm package does not contain the js file(s) of this component. This means the component can't be loaded with system.js. Do you have any plans to fix this (or am I missing something here)?

Thanks.

isExpanded = true does not expand

As the title says, I have some nodes with isExpanded: true, but the treeview is collapsed on startup.

var nodes =
    [
        {
            name: 'a',
            isExpanded: true,
            children: [
                {
                    name: 'b',
                    isExpanded: true,
                    children: [
                        { name: c', }
                    ]
                },
            ]
        },
        {
            name: 'b',
            isExpanded: true,
            children: [
                {
                    name: 'a',
                    children: [
                        { name: 'c' },
                    ]
                }
            ]
        }
    ];

No errors are displayed.

Angular 2 RC4, angular-cli and system-js

fails to install unless typings is installed globally

I'm not using Typescript so I don't have nor use typings. It fails to install in the postinstall step as a result. I saw that the path is node_modules/.bin/typings install - you should just be able to say typings install and it should install based on the depended-on install of typings - no need to specify the full path.

Possibility to select one node from the id.

Would be good to have the possibility to select an node by the id. I did not find this possibility in the API. In this case should fire an event informing that the node has been selected.

One great tree component that i use is the jsTree (https://www.jstree.com) but it has the disadvantage of use jquery.

Follow my suggestion:
<Tree #tree [nodes]="nodes"></Tree>
<button (click)="tree.treeModel.selectNode(2)">next node</button>
nodes = [
{
id: 1,
name: 'root1',
isExpanded: true,
children: [
{
id: 2,
name: 'child1'
}, {
id: 3,
name: 'child2'
}
]
}
]

1.2.0 version not in npmjs

npm install 1.2.0 version ,I got error:

`npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install"
npm ERR! node v6.3.1
npm ERR! npm v3.10.3

npm ERR! No compatible version found: angular2-tree-component@^1.2.0
npm ERR! Valid install targets:
npm ERR! 1.1.18, 1.1.17, 1.1.16, 1.1.14, 1.1.13, 1.1.12, 1.1.11, 1.1.10, 1.1.9, 1.1.8, 1.1.6, 1.1.5, 1.1.4, 1.1.4-dev3, 1.1.4-dev2, 1.1.4-dev
, 1.1.3, 1.1.2, 1.1.1, 1.0.2, 1.0.1, 1.0.0
npm ERR!
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! https://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request:
npm ERR! d:\frontEnd\angular2\npm-debug.log `

Remove the lodash dependency

Since this is a library, forcing the user to use lodash is a problem.

In here there is a direct import of the whole lodash library.

It should be either removed and functionality should be manually written,.
Or, only required functions from lodash should be imported.

DisplayField

Hi. I wanna display more than 1 field. Is it possible to display more than 1 field?

Activate node using ngOnInit

I have the tree in a component, but want to activate the first node in the tree by default.

How can this be done?

Tree doesn't expand on loading when expanded is true

Any idea why the tree doesn't expand on page loading? Below is my configuration:

In the view inside the Tree element:
[nodes]="tree" [focused]="true" [options] = "treeOptions"

In the component:
treeOptions = {
isExpanded: 'expanded',
treeNodeTemplate: MyTreeNodeTemplate,
loadingComponent: MyTreeLoadingTemplate,
context: this
}

Json returned from the server contains "expanded":true

[{"id":"8365a4e2-698e-11e6-b73e-0242ac12000e","name":"Tom Swift","expanded":true,"children":[{"id":"836da3e3-698e-11e6-b73e-0242ac12000e","name":"[G] User","expanded":true,"children":[{"id":"838d876a-698e-11e6-b73e-0242ac12000e","name":"[S] Launch_Default","expanded":true,"children":[{"id":"83ae0fec-698e-11e6-b73e-0242ac12000e","name":"[P] Launch.refcodes.Put","expanded":true,"children":[]},{"id":"83adf800-698e-11e6-b73e-0242ac12000e","name":"[P] Launch.refcodes.Post","expanded":true,"children":[]},{"id":"83addc0c-698e-11e6-b73e-0242ac12000e","name":"[P] Launch.refcodes.Get","expanded":true,"children":[]},{"id":"83ae25ec-698e-11e6-b73e-0242ac12000e","name":"[P] Launch.refcodes.Delete","expanded":true,"children":[]}]}]},{"id":"836d72ed-698e-11e6-b73e-0242ac12000e","name":"[G] Admin","expanded":true,"children":[{"id":"838c74c5-698e-11e6-b73e-0242ac12000e","name":"[S] IDP_Default","expanded":true,"children":[]},{"id":"838d708a-698e-11e6-b73e-0242ac12000e","name":"[S] Gateway_Default","expanded":true,"children":[]},{"id":"838d876a-698e-11e6-b73e-0242ac12000e","name":"[S] Launch_Default","expanded":true,"children":[{"id":"83ae0fec-698e-11e6-b73e-0242ac12000e","name":"[P] Launch.refcodes.Put","expanded":true,"children":[]},{"id":"83adf800-698e-11e6-b73e-0242ac12000e","name":"[P] Launch.refcodes.Post","expanded":true,"children":[]},{"id":"83addc0c-698e-11e6-b73e-0242ac12000e","name":"[P] Launch.refcodes.Get","expanded":true,"children":[]},{"id":"83ae25ec-698e-11e6-b73e-0242ac12000e","name":"[P] Launch.refcodes.Delete","expanded":true,"children":[]}]},{"id":"838d5849-698e-11e6-b73e-0242ac12000e","name":"[S] OAuth2_Default","expanded":true,"children":[{"id":"ca4e7d44-2a47-4136-a796-04b660299f21","name":"[P] OAuth2.ui.Get","expanded":true,"children":[]}]}]}]}]

Ability to configure keyboard navigation keys

Hi,

In the current implementation of the tree it is possible to select/deselect a node with keyboard, pressing on enter/space. I have a requirement to implement tree node template with text input that allows spaces. Default behavior of enter/space is prevented, so it is impossible to use space inside node template.

I suggest to allow configuration of keyboard navigation keys through options object.

Thanks

Title is displayed twice

I encountered the problem, that the title field (displayField) is rendered twice. Same behaviour can be seen in your demo:
image

Bug or Feature? ๐Ÿ˜„

Tempalate Url

I've two questions

Can I give tree custom template ?
is it compatible with angular rc 3 ?

thanks

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.