Follow me [@wesnolte](http://twitter.com/wesnolte)
jQuery OrgChart is a plugin that allows you to render structures with nested elements in a easy-to-read tree structure. To build the tree all you need is to make a single line call to the plugin and supply the HTML element Id for a nested unordered list element that is representative of the data you'd like to display. If drag-and-drop is enabled you'll be able to reorder the tree which will also change the underlying list structure.
* Very easy to use given a nested unordered list element.
* Drag-and-drop functionality allows reordering of the tree and underlying `
* Showing/hiding a particular branch of the tree by clicking on the respective node.
* Nodes can contain any amount of HTML except `
` and `
* Easy to style.
* You can specify that sub-trees should start collapsed, which is useful for very large trees
![jQuery OrgChart](http://i.imgur.com/T8kKA.png "jQuery OrgChart")
##Expected Markup & Example Usage
To get up and running you'll need a few things.
You need to include the jQuery as well as the jOrgChart libraries. For example:
If you want to use the drag-and-drop functionality you'll need to include jQuery UI too:
The core CSS is necessary to perform some of the basic styling i.e.
You'll need to construct a nest unordered list that represents your node nesting. For example:
If you want a sub-tree to start off hidden, just add `class="collapsed"` to a list item (`
`). That list item will appear, but everything below it won't. For example:
This plugin works by generating the tree as a series of nested tables. Each node in the tree is represented with `
`. You can include any amount of HTML markup in your `
` **except** for other `
` or `
` elements. Your markup will be used within the node's `
` element. Any classes you attach to the `
` elements will be copied to the associated node, allowing you to highlight particular parts of the tree. The special `collapsed` class described above doesn't get copied to the node.
###The jQuery Call
And the cherry on the top is the usual call, often but not always on document load. You'll need to specify the Id of the list in this call. For example:
This call will append the markup for the OrgChart to the `` element by default, but you can specify this as part of the options.
You can view a demo of this [here](http://bit.ly/u1XhTf "jQuery OrgChart").
Source code with an example is available [here](https://github.com/wesnolte/jOrgChart/tree/master/example "Example & Source").
There are only 3 configuration options:
1. **chartElement** - used to specify which HTML element you'd like to append the OrgChart markup to. *[default='body']*
2. **depth** - tells the code what depth to parse to. The default value of "-1" instructs it to parse like it's 1999. *[default=-1]*
3. **chartClass** - the name of the style class that is assigned to the generated markup. *[default='jOrgChart']*
4. **dragAndDrop** - determines whether the drag-and-drop feature of tree node elements is enabled. *[default=false]*