Convert Figma logo to code with AI

vakata logojstree

jquery tree plugin

5,124
1,384
5,124
3

Top Related Projects

Tree View for Twitter Bootstrap -

jQuery Tree Plugin

Quick Overview

jsTree is a jQuery plugin that provides interactive trees. It's a feature-rich library that allows for creating and manipulating tree structures in web applications, supporting various data formats, themes, and customization options.

Pros

  • Highly customizable with numerous configuration options
  • Supports various data sources (HTML, JSON, AJAX)
  • Extensive API for programmatic control and interaction
  • Active development and community support

Cons

  • Requires jQuery, which may not be ideal for modern JavaScript frameworks
  • Can be resource-intensive for very large trees
  • Learning curve for advanced features and customization

Code Examples

Creating a basic tree:

$('#tree').jstree({
  'core' : {
    'data' : [
      { "text" : "Root node", "children" : [
        { "text" : "Child node 1" },
        { "text" : "Child node 2" }
      ]}
    ]
  }
});

Handling node selection:

$('#tree').on('changed.jstree', function (e, data) {
  var selectedNode = data.instance.get_node(data.selected[0]);
  console.log('Selected: ' + selectedNode.text);
});

Loading data via AJAX:

$('#tree').jstree({
  'core' : {
    'data' : {
      'url' : 'ajax_nodes.json',
      'data' : function (node) {
        return { 'id' : node.id };
      }
    }
  }
});

Getting Started

  1. Include jQuery and jsTree in your HTML:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/themes/default/style.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/jstree.min.js"></script>
  1. Create a container element:
<div id="tree"></div>
  1. Initialize jsTree:
$(function() {
  $('#tree').jstree({
    'core' : {
      'data' : [
        { "text" : "Root node", "children" : [
          { "text" : "Child node 1" },
          { "text" : "Child node 2" }
        ]}
      ]
    }
  });
});

This will create a basic tree structure. You can further customize the tree by adding plugins, changing themes, or modifying the data structure to suit your needs.

Competitor Comparisons

Tree View for Twitter Bootstrap -

Pros of bootstrap-treeview

  • Lightweight and simple to use, with a focus on Bootstrap integration
  • Easy customization through Bootstrap classes and themes
  • Built-in search functionality

Cons of bootstrap-treeview

  • Less feature-rich compared to jstree
  • Limited support for advanced tree operations (e.g., drag-and-drop)
  • Smaller community and fewer updates

Code Comparison

bootstrap-treeview:

$('#tree').treeview({
  data: treeData,
  levels: 2,
  expandIcon: 'glyphicon glyphicon-plus',
  collapseIcon: 'glyphicon glyphicon-minus',
  nodeIcon: 'glyphicon glyphicon-folder-close'
});

jstree:

$('#tree').jstree({
  'core': {
    'data': treeData,
    'themes': {
      'name': 'proton',
      'responsive': true
    }
  },
  'plugins': ['state', 'dnd', 'types']
});

Both libraries offer straightforward initialization, but jstree provides more advanced configuration options and plugin support out of the box. bootstrap-treeview focuses on simplicity and Bootstrap integration, while jstree offers a more comprehensive set of features for complex tree structures and interactions.

jQuery Tree Plugin

Pros of zTree

  • Supports more advanced features like drag-and-drop between multiple trees
  • Offers a wider range of built-in node types and customization options
  • Provides better performance for large datasets

Cons of zTree

  • Less active development and community support
  • Documentation is not as comprehensive and may be outdated
  • Steeper learning curve due to more complex API

Code Comparison

zTree:

var setting = {
    data: {
        simpleData: {
            enable: true
        }
    }
};
var zNodes = [
    { id:1, pId:0, name:"Parent Node 1" },
    { id:11, pId:1, name:"Child Node 1" },
    { id:12, pId:1, name:"Child Node 2" }
];
$.fn.zTree.init($("#treeDemo"), setting, zNodes);

jsTree:

$('#jstree').jstree({
    'core' : {
        'data' : [
            { "text" : "Parent Node 1", "children" : [
                { "text" : "Child Node 1" },
                { "text" : "Child Node 2" }
            ]}
        ]
    }
});

Both libraries offer similar functionality for creating tree structures, but zTree provides more advanced features out of the box. jsTree has a simpler API and better documentation, making it easier to get started with. The choice between the two depends on the specific requirements of your project and the level of complexity you need.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

jstree

jsTree is jquery plugin, that provides interactive trees. It is absolutely free, open source and distributed under the MIT license.

jsTree is easily extendable, themable and configurable, it supports HTML & JSON data sources, AJAX & async callback loading.

jsTree functions properly in either box-model (content-box or border-box), can be loaded as an AMD module, and has a built in mobile theme for responsive design, that can easily be customized. It uses jQuery's event system, so binding callbacks on various events in the tree is familiar and easy.

You also get:

  • drag & drop support
  • keyboard navigation
  • inline edit, create and delete
  • tri-state checkboxes
  • fuzzy searching
  • customizable node types

For more information, examples and API docs head on over to the wiki page and jstree.com. Feel free to ask any questions on the discussions board. The PHP demos are now in a separate repository.

License & Contributing

Please do NOT edit files in the "dist" subdirectory as they are generated via grunt. You'll find source code in the "src" subdirectory!

If you want to you can always sponsor me or donate a small amount to help the development of jstree.

Copyright (c) 2020 Ivan Bozhanov (http://vakata.com)

Licensed under the MIT license.

NPM DownloadsLast 30 Days