Implementing jQuery DynaTree in Grails Application

Posted By : Shiv Kumar | 08-Jan-2014
Introduction to DynaTree :
 
DynaTree is used to represent dynamic JavaScript tree view control along with the 
support of checkboxes,Keyboard, drag'n'drop and lazy loading.
 
Options to perform operation with dynatree:
1. title: "Node"      // used for name of the node.
2. children: null     // To initialize tree structure or children nodes from this object array.
3. keyboard: true,    // used to support keyboard navigation.
4. persist: false,    // used to persist expand-status to a cookie.
5. onActivate: null,  // event is used when a node is activated.
etc.
 
The root node object is obtained as follow:
        var rootNode = $("#tree").dynatree("getRoot");
        
Here is an example to initialize dynatree using JSON:
From the controller jsonResponse(JSONObject) rendered is :
  [ 
  {title: "Node 1"},
  {title: "Node 2", isFolder: true, //isFolder : true is used to represent node as Folder
    children: [
               {title: "Child-node 2.1"},
               {title: "Child-node 2.2"}
              ]
   },
   {title: "Node 3"}
]
                
The Dynatree is initialized during the onload event of the document. 
In jQuery this is usually done by passing a function to $(document) :
                         
 

// div attached with dynatree

Sometimes our requirement is to reload the dynatree after some event and reflect the changes immediately.
In that case we have to destroy and re-initialize the dynatree as follow:
$("#tree").dynatree("destroy");
$("#tree").dynatree({
     […]
});
                                
Thanks
Shiv Kumar

 

About Author

Author Image
Shiv Kumar

Shiv is an experienced Java Developer with a strong background in multiple technologies. He specializes in defining system architectures to ensure reliable and resilient solutions. He possesses a comprehensive understanding of the latest technologies and has hands-on experience in Core Java, Spring Boot, Hibernate, Apache Kafka messaging queue, Redis, as well as relational databases like MySQL and PostgreSQL, and non-relational databases like MongoDB. He excels in API implementations, Microservices, Web Services development, testing, and deployments. Shiv actively contributes to code enhancements and consistently delivers valuable contributions to various client projects, including Fabtrack, Pando, Pandojo, Digikam, WhatsApp Integration, Croniz, Punchin Application, Script TV, Bhaasha, and more. He demonstrates strong analytical skills and a creative mindset. In addition, he has a passion for reading books and exploring new technologies and innovations.

Request for Proposal

Name is required

Comment is required

Sending message..