Convert Figma logo to code with AI

mbraak logojqTree

Tree widget for jQuery

1,019
176
1,019
3

Top Related Projects

5,124

jquery tree plugin

JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading

Tree View for Twitter Bootstrap -

jQuery Tree Plugin

Quick Overview

jqTree is a jQuery plugin for displaying interactive trees. It provides a simple way to create and manipulate tree structures in web applications, with features like drag-and-drop, lazy loading, and customizable node rendering.

Pros

  • Easy to set up and use with jQuery
  • Supports drag-and-drop functionality for tree nodes
  • Allows lazy loading of tree data for improved performance
  • Highly customizable with various options and events

Cons

  • Depends on jQuery, which may not be ideal for modern web applications
  • Limited built-in styling options, requiring additional CSS for advanced customization
  • Documentation could be more comprehensive for advanced use cases
  • May have performance issues with very large trees

Code Examples

  1. Basic tree initialization:
$('#tree').tree({
    data: [
        { name: 'Node 1', children: [
            { name: 'Child 1' },
            { name: 'Child 2' }
        ]},
        { name: 'Node 2' }
    ]
});
  1. Adding a node programmatically:
var $tree = $('#tree');
var node = $tree.tree('getNodeById', 1);
$tree.tree('addNodeAfter', { name: 'New Node' }, node);
  1. Handling node selection:
$('#tree').on('tree.select', function(event) {
    if (event.node) {
        var node = event.node;
        alert('Selected: ' + node.name);
    }
});

Getting Started

  1. Include jQuery and jqTree in your HTML:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="jqtree.css">
<script src="tree.jquery.js"></script>
  1. Create a container element and initialize the tree:
<div id="tree"></div>
<script>
    $(function() {
        $('#tree').tree({
            data: [
                { name: 'Node 1', id: 1 },
                { name: 'Node 2', id: 2 }
            ]
        });
    });
</script>

This will create a basic tree with two nodes. You can further customize the tree by adding more options and handling events as needed.

Competitor Comparisons

5,124

jquery tree plugin

Pros of jsTree

  • More feature-rich with built-in support for checkboxes, drag-and-drop, and contextual menus
  • Larger community and more extensive documentation
  • Supports theming and comes with pre-built themes

Cons of jsTree

  • Larger file size and potentially heavier performance impact
  • Steeper learning curve due to more complex API
  • Less frequent updates and maintenance compared to jqTree

Code Comparison

jsTree initialization:

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

jqTree initialization:

$('#tree').tree({
  data: [
    {
      name: 'Node 1',
      children: [
        { name: 'Child 1' },
        { name: 'Child 2' }
      ]
    }
  ]
});

Both libraries offer tree functionality, but jsTree provides more out-of-the-box features at the cost of complexity, while jqTree focuses on simplicity and ease of use. The choice between them depends on the specific requirements of your project and the level of customization needed.

JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading

Pros of Fancytree

  • More extensive documentation and examples
  • Wider range of features, including drag-and-drop, checkboxes, and filtering
  • Active development with frequent updates and bug fixes

Cons of Fancytree

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve due to more complex API and configuration options

Code Comparison

Fancytree:

$("#tree").fancytree({
  source: [
    {title: "Node 1", children: [
      {title: "Child 1"},
      {title: "Child 2"}
    ]},
    {title: "Node 2"}
  ]
});

jqTree:

$('#tree').tree({
  data: [
    {name: 'Node 1', children: [
      {name: 'Child 1'},
      {name: 'Child 2'}
    ]},
    {name: 'Node 2'}
  ]
});

Both libraries offer similar basic functionality for creating tree structures, but Fancytree provides more advanced features and customization options. jqTree, on the other hand, offers a simpler API and lighter footprint, which may be preferable for projects with basic tree requirements. The choice between the two depends on the specific needs of your project and the level of complexity you're willing to manage.

Tree View for Twitter Bootstrap -

Pros of bootstrap-treeview

  • Built specifically for Bootstrap, ensuring seamless integration with Bootstrap-based projects
  • Simpler API and easier to set up for basic tree structures
  • Includes built-in search functionality

Cons of bootstrap-treeview

  • Less flexible for complex tree structures and advanced customization
  • Limited event handling options compared to jqTree
  • Less frequent updates and maintenance

Code Comparison

bootstrap-treeview:

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

jqTree:

$('#tree').tree({
  data: treeData,
  autoOpen: 2,
  dragAndDrop: true,
  onCreateLi: function(node, $li) {
    $li.find('.jqtree-title').addClass('custom-class');
  }
});

The code examples demonstrate that bootstrap-treeview has a more straightforward setup, while jqTree offers more advanced features like drag-and-drop and custom node rendering. jqTree provides greater flexibility for complex tree structures and interactions, making it suitable for more advanced use cases. However, bootstrap-treeview's simplicity and Bootstrap integration make it an attractive option for simpler projects or those already using Bootstrap.

jQuery Tree Plugin

Pros of zTree

  • More feature-rich with advanced functionalities like drag-and-drop, checkboxes, and dynamic loading
  • Extensive documentation and examples available
  • Supports both jQuery and native JavaScript implementations

Cons of zTree

  • Larger file size and potentially heavier performance impact
  • Less modern UI design out-of-the-box
  • Steeper learning curve due to more complex API

Code Comparison

zTree example:

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" }
];
$(document).ready(function(){
    $.fn.zTree.init($("#treeDemo"), setting, zNodes);
});

jqTree example:

var data = [
    {
        name: 'Parent Node 1',
        children: [
            { name: 'Child Node 1' },
            { name: 'Child Node 2' }
        ]
    }
];
$('#tree1').tree({
    data: data
});

Both libraries offer tree functionality, but zTree provides more built-in features at the cost of complexity, while jqTree focuses on simplicity and ease of use. The choice between them depends on the specific requirements of your project.

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

Build codecov

NPM version

jqTree

JqTree is a tree widget. Read more in the documentation.

screenshot

Features

  • Create a tree from JSON data
  • Drag and drop
  • Works on all modern browsers
  • Written in Typescript

The project is hosted on github, has a test suite.

Examples

Example with ajax data:

<div id="tree1" data-url="/example_data/"></div>
$("#tree1").tree();

Example with static data:

var data = [
    {
        label: "node1",
        id: 1,
        children: [
            { label: "child1", id: 2 },
            { label: "child2", id: 3 },
        ],
    },
    {
        label: "node2",
        id: 4,
        children: [{ label: "child3", id: 5 }],
    },
];
$("#tree1").tree({
    data: data,
    autoOpen: true,
    dragAndDrop: true,
});

Documentation

The documentation is on http://mbraak.github.io/jqTree/.

Thanks

The code for the mouse widget is heavily inspired by the mouse widget from jquery ui.

NPM DownloadsLast 30 Days