Dynamic Tree with JSTree, PHP and MySQL

I got huge response from my previous article How to Create Dynamic Tree View Menu,Most of readers asking about how to use checkbox with this and drag and drop features,so In this article i am creating dynamic tree menu with check box using jstree jquery tree view plugin,php and mysql. Dynamic means all nodes of tree menu is depend upon server side processing.

I am using same database structure like previous tutorial How to Create Dynamic Tree View Menu,


Why Choose JStree:

jsTree is very popular jQuery tree plugin to create awesome multi-level menu. jsTress is free, open source jquery treeview plugin, that help to create interactive tree menu using HTML & JSON data sources and AJAX loading. jsTree is easily extendable, them-able and configurable.It has a built in mobile theme for responsive design and various callback methods.

jsTree jQuery Tree Plugin main Features are:

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

You can also check other tutorial of TreeView Menu,

How To create Dynamic Tree using PHP, MySQL and jquery

So we are using below files to create dynamic treeview using jstree jquery tree plugin,php and mysql. Its very easy and simple,The project structure are follows:

  1. dist folder : This folder will contains all js/css and images files.
  2. index.php : This file is use to display tree menu.
  3. response.php : This file is use to fetch tree nodes from database and convert them into json object.

Step 1: Create Table structure to stored tree menu nodes.we need to create ‘test’ database(if you have then don’t need) and created below 'treeview_items' table into this database.

Step 2: Created connection with MySQL into (response.php) file.

Step 3: Created PHP array of all tree nodes and encode into json(response.php) file.

Step 4: Included all js/css files of jsTree into index.php file.

Step 5: Created tree menu container in index.php.

Step 6: Call jstree method on div container.

You can see here, we are using "checkbox" plugin to create check-box against each node.We are passing json data to jstree method.

You can download source code and Demo from below link.