Skip to content

pavloo/ember-cli-tree

Repository files navigation

Ember-cli-tree

simple tree UI component for Ember. No JQuery. Pure handlebars and recursion.

npm version Build Status

Installation

ember install ember-cli-tree

Usage

The only thing you need to care of is how your single tree node looks like. Here is an example tree object:

const treeHead = {
  label: '1',
  children: [
    {
      label: '2'
    },
    {
      label: '2',
      children: [
        {
          label: 3
        }
      ]
    }
  ]
}

Simple usage:

{{#ember-tree node=treeHead as |node isExpanded|}}
  {{#ember-tree/trigger-expand}}
    {{#if isExpanded}}
      -
    {{else}}
      +
    {{/if}}
  {{/ember-tree/trigger-expand}}
  {{node.label}}
{{/ember-tree}}

Component's API

  • eagerCreate - boolean, determines, how tree is rendered:
    1. if set to true, the whole tree is placed into DOM upon component's insertion (show/hide is implemented via display: none)
    2. if set to false, every node is inserted individually lazily upon parent's node expansion (show/hide is implemented via if helper) (Default: true)
  • childrenKey - String, the key of children attribute in tree node object (Default: 'children')
  • expandEvent - String, event, which causes expanding of node when triggered on ember-tree/trigger-expand component (Default: 'click')
  • showOnly - Number, the number of node's children shown by default (Default: undefined)
  • showOtherTextFmt - String (format string, see Ember.String.fmt for details), if showOnly is set, the value of this property is the value of link text, clicking on which makes hidden children to be shown, where 1st format parameter - # of children left (Default: 'Show Other %@')
  • expandAction - String, name of an action, which handles expansion of sub trees on top level. If defined, node.isExpanded have to be manually set, e. g.

See tests for more.

...
expandActionHander(node, isExpanded){
  // some custom handling, then
  Ember.set(node, 'isExpanded', isExpanded);
}
...

TODO list:

  • add drag and drop

Contribution

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.