Pure Javascript TreeView Component – aimaraJS

Category: Javascript | September 1, 2015
Author: rafaelthca
Views Total: 9,305 views
Official Page: Go to website
Last Update: September 1, 2015
License: MIT

Preview:

Pure Javascript TreeView Component – aimaraJS

Description:

aimaraJS is a robust and effective JavaScript library for rendering an editable, expandable, collapsible tree structure that features custom events, context menu and node icons.

Basic usage:

Link to Aimara.css and Aimara.js.

<link rel="stylesheet" href="css/Aimara.css">
<script src="lib/Aimara.js"></script>

Create an Html DIV element for your tree structure.

<div id="div_tree"></div>

Create the context menu for your tree nodes.

var contex_menu = {
  'context1' : {
    elements : [
      {
        text : 'Node Actions',
        icon: 'images/blue_key.png',
        action : function(node) {

        },
        submenu: {
          elements : [
            {
              text : 'Toggle Node',
              icon: 'images/leaf.png',
              action : function(node) {
                node.toggleNode();
              }
            },
            {
              text : 'Expand Node',
              icon: 'images/leaf.png',
              action : function(node) {
                node.expandNode();
              }
            },
            {
              text : 'Collapse Node',
              icon: 'images/leaf.png',
              action : function(node) {
                node.collapseNode();
              }
            },
            {
              text : 'Expand Subtree',
              icon: 'images/tree.png',
              action : function(node) {
                node.expandSubtree();
              }
            },
            {
              text : 'Collapse Subtree',
              icon: 'images/tree.png',
              action : function(node) {
                node.collapseSubtree();
              }
            },
            {
              text : 'Delete Node',
              icon: 'images/delete.png',
              action : function(node) {
                node.removeNode();
              }
            },
          ]
        }
      },
      {
        text : 'Child Actions',
        icon: 'images/blue_key.png',
        action : function(node) {

        },
        submenu: {
          elements : [
            {
              text : 'Create Child Node',
              icon: 'images/add1.png',
              action : function(node) {
                node.createChildNode('Created',false,'images/folder.png',null,'context1');
              }
            },
            {
              text : 'Create 1000 Child Nodes',
              icon: 'images/add1.png',
              action : function(node) {
                for (var i=0; i<1000; i++)
                  node.createChildNode('Created -' + i,false,'images/folder.png',null,'context1');
              }
            },
            {
              text : 'Delete Child Nodes',
              icon: 'images/delete.png',
              action : function(node) {
                node.removeChildNodes();
              }
            }
          ]
        }
      }
    ]
  }
};

Create the tree structure.

tree = createTree('div_tree','white',contex_menu);

Render the tree.

tree.drawTree();

Add node after tree is already rendered.

tree.createNode('Real Time',false,'images/leaf.png',null,null,'context1');

 

You Might Be Interested In:


Leave a Reply