Create, Rename and Delete Node using JSTree,PHP and MySQL

I got huge response from my previous article Dynamic Tree with JSTree, PHP and MySQL,Most of readers asking about how to add, edit and delete node functionality using JsTree,PHP and mysql.I will explain here how to add/edit dynamically nodes using jstree,php using AJAX.

In This Jstree PHP treemenu tutorial, I am create multi level tree menu and adding add,edit and delete node using jstree context menu.

jstree context menu is a jstree plugin which is used to show context menu on node, I will provide add,edit and delete node option using jstree context menu on each node, based on selected option i ll perform add,edit and delete node using PHP as well as update MySQL tree data.

I am using JSTree jquery plugin,You have read and understand my previous Dynamic Tree with JSTree, PHP and MySQL tutorial.

I will cover following functionality on this PHP treeview Tutorial

  • Create Simple TreeView menu using Jstree, php and mysql
  • Create context menu with add,edit and delete option
  • Add and edit node into tree menu
  • Delete single or multiple node from tree menu

You can also check other tutorial of TreeView Menu,

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

Create,Rename and Delete Node using JSTree,PHP and MySQL

The Following jsTree Plugin will use:

  • state – This jstree plugin will use to save all opened and selected nodes state.
  • contextmenu – This jstree plugin used to show all configuration option like add,edit and delete on right click nodes.
  • wholerow – This plugin help to create each node appear block level which makes selection easier.

You can also check other tutorial of TreeView Menu,

Add,Edit and Delete node using jsTree and Context Menu

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
  3. response.php : This file is use to fetch tree nodes from database and convert them into json object.

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

Step 2: Call jstree method on div container and added context menu plugin.

above code will create context menu on right click of tree menu node.

Step 3: Now I will add context menu option and callback method for add, edit and delete jstree nodes.

We have created context menu and added callback option for each operation like add node,rename node and delete node, Also i have added ajax request for each operation.We have created AJAX PHP request for each operation and save each modification into database using server-side response.php file.

Step 4: Now i will add server side code for update nodes information into mysql database.

I am adding response header json type to send result in json format to jstree. I am getting 'operation' parameters that notify which operation will perform on server side based on selected option on context menu.I am processing data and storing into database and finally send json response.

Conclusion

I have added simple version of jstree with PHP,mysql and Ajax.I have added add,edit and delete node using php,mysql and jQuery AJAX.I leave copy and paste option node for you.

You can download source code and Demo from below link.

33 thoughts on “Create, Rename and Delete Node using JSTree,PHP and MySQL

  1. This post is awesome. Please, help me. How can I show inside a specific form when I click sub-menu with tree menu.

  2. This post is awesome. Please help me. How can I show a specific form inside tree menu when I click sub-menu.

  3. nice example. i have added a field as link which will store the link where the sub menu will take on click . Unable to implement. I am new .Plz help

    • Hi Rajessh,
      I got some time to solve ur problem, You need to add below changes to add href in you all node anchor tag but on-click to ridrect you need to debugging on jstree call back function.
      You can add href attribute and value using below code,
      //already have in you code
      $itemsByReference[$item[‘id’]][‘data’] = new StdClass();

      add below two lines

      $itemsByReference[$item[‘id’]][‘a_attr’] = new StdClass();
      $itemsByReference[$item[‘id’]][‘a_attr’]->href = ‘google.com’;

  4. i have created a database in which i hav also created a table using phpmyadmin, mysql, now i want to add treegrid in each of the column of my field values…… wat can i do isthere anyone to help me out……..

  5. First, thanks for your code.. it’s really great code..
    But i found some error when click create
    Chrome Console: jstree.min.js:3 -> Uncaught TypeError: Cannot read property ‘toString’ of undefined
    Can u help me?
    Thanks..

Leave a Reply

Your email address will not be published. Required fields are marked *