fancytree
JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading
Top Related Projects
jquery tree plugin
Tree View for Twitter Bootstrap -
jQuery Tree Plugin
Quick Overview
Fancytree is a JavaScript tree view / tree grid plugin for jQuery with support for persistence, keyboard, checkboxes, tables, drag'n'drop, and lazy loading. It's designed to be flexible and customizable, making it suitable for a wide range of tree-based UI applications.
Pros
- Highly customizable with numerous options and events
- Supports lazy loading for efficient handling of large data sets
- Integrates well with jQuery UI for consistent theming and interactions
- Extensive documentation and examples available
Cons
- Requires jQuery, which may not be ideal for modern JavaScript projects
- Learning curve can be steep due to the large number of options and features
- Performance may degrade with very large trees if not properly optimized
- Limited built-in styling options, requiring additional CSS work for complex designs
Code Examples
- Basic tree initialization:
$("#tree").fancytree({
source: [
{ title: "Node 1", children: [
{ title: "Child 1" },
{ title: "Child 2" }
]},
{ title: "Node 2" }
]
});
- Lazy loading with AJAX:
$("#tree").fancytree({
source: {
url: "/api/tree-data",
cache: false
},
lazyLoad: function(event, data) {
data.result = {
url: "/api/tree-data",
data: { key: data.node.key }
};
}
});
- Checkbox tree with select mode:
$("#tree").fancytree({
checkbox: true,
selectMode: 3,
source: [ /* ... */ ],
select: function(event, data) {
console.log(data.node.title, data.node.isSelected());
}
});
Getting Started
- Include the necessary files in your HTML:
<link href="path/to/ui.fancytree.css" rel="stylesheet">
<script src="path/to/jquery.js"></script>
<script src="path/to/jquery-ui.js"></script>
<script src="path/to/jquery.fancytree-all-deps.js"></script>
- Create a container element and initialize Fancytree:
<div id="tree"></div>
<script>
$(function() {
$("#tree").fancytree({
source: [
{ title: "Node 1" },
{ title: "Node 2" }
]
});
});
</script>
This will create a basic tree with two nodes. You can further customize the tree by adding more options and event handlers as needed.
Competitor Comparisons
jquery tree plugin
Pros of jstree
- More extensive documentation and examples
- Larger community and more frequent updates
- Better support for drag-and-drop functionality
Cons of jstree
- Slightly steeper learning curve for beginners
- Less flexible theming options out of the box
- Heavier file size compared to Fancytree
Code Comparison
jstree:
$('#tree').jstree({
'core' : {
'data' : [
{ "id" : "1", "parent" : "#", "text" : "Node 1" },
{ "id" : "2", "parent" : "1", "text" : "Child 1" }
]
}
});
Fancytree:
$("#tree").fancytree({
source: [
{title: "Node 1", key: "1",
children: [{title: "Child 1", key: "2"}]
}
]
});
Both libraries offer similar functionality for creating tree structures, but jstree uses a more nested approach for defining child nodes, while Fancytree uses a flatter structure with a dedicated "children" property. jstree also explicitly defines the parent-child relationship using "parent" keys, whereas Fancytree infers this relationship from the structure of the data array.
Tree View for Twitter Bootstrap -
Pros of bootstrap-treeview
- Lightweight and simple to use, with minimal setup required
- Seamless integration with Bootstrap, making it ideal for Bootstrap-based projects
- Built-in search functionality for easy node filtering
Cons of bootstrap-treeview
- Limited customization options compared to fancytree's extensive feature set
- Less active development and community support
- Fewer advanced features like drag-and-drop, lazy loading, or keyboard navigation
Code Comparison
bootstrap-treeview:
$('#tree').treeview({
data: treeData,
levels: 2,
expandIcon: 'glyphicon glyphicon-plus',
collapseIcon: 'glyphicon glyphicon-minus',
showTags: true
});
fancytree:
$("#tree").fancytree({
source: treeData,
extensions: ["filter", "edit"],
filter: {
mode: "hide"
},
edit: {
triggerStart: ["f2", "dblclick", "shift+click", "mac+enter"]
}
});
The code comparison demonstrates that bootstrap-treeview has a simpler initialization process, while fancytree offers more advanced configuration options and extensions. fancytree's code shows built-in support for filtering and editing, which are not available in the basic bootstrap-treeview setup.
jQuery Tree Plugin
Pros of zTree
- More extensive documentation and examples
- Supports a wider range of customization options
- Larger community and longer development history
Cons of zTree
- Less frequent updates and maintenance
- Heavier file size and potentially slower performance
- More complex API, which may have a steeper learning curve
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);
Fancytree
$("#tree").fancytree({
source: [
{title: "Parent Node 1", key: "1", children: [
{title: "Child Node 1", key: "11"},
{title: "Child Node 2", key: "12"}
]}
]
});
Both libraries offer similar functionality for creating tree structures, but zTree provides more detailed configuration options, while Fancytree offers a simpler API. zTree uses a flat array structure with parent-child relationships defined by IDs, whereas Fancytree uses a nested object structure. The initialization process is also slightly different, with zTree requiring separate setting and node data objects.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Fancytree
Fancytree (sequel of DynaTree 1.x) is a JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading.
NOTE:
Fancytree is considered feature-complete.
The code is still maintained and bugfixes will be commited. However do not expect new major features.For a modernized and more capable alternative, have a look at the designated successor Wunderbaum.
Get Started
- Try the live demo.
- Read the documentation.
- Check the Q&A forum or Stackoverflow if you have questions.
- Play with jsFiddle, CodePen, or Plunker.
- Contribute
ES6 Quickstart
import $ from "jquery";
import 'jquery.fancytree/dist/skin-lion/ui.fancytree.less'; // CSS or LESS
import {createTree} from 'jquery.fancytree';
import 'jquery.fancytree/dist/modules/jquery.fancytree.edit';
import 'jquery.fancytree/dist/modules/jquery.fancytree.filter';
const tree = createTree('#tree', {
extensions: ['edit', 'filter'],
source: {...},
...
});
// Note: Loading and initialization may be asynchronous, so the nodes may not be accessible yet.
See module loader support and API docs.
Credits
Thanks to all contributors.
Top Related Projects
jquery tree plugin
Tree View for Twitter Bootstrap -
jQuery Tree Plugin
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot