Treeview dynamically load subnodes on expand

I have 2 questions:

  1. I’m trying to dynamically load subnodes (from a database through a java servlet request that serves data in json format) on expand event in a treeview.
    How can it be done? The documentation doesnt such a topic or I couldnt find it.

  2. Can I put the expand “+” icon only on nodes that I know they have children?
    I mean how cand I transmit a “haschildren” flag to a node in the json data?

Thanks a lot.


The second point in my 2 points question, I have already found it…


Hi … tions.html - there is a sample of operations in a dynamic tree
I think it is the sample you looked for

Hi Adrian,

dynamic loading is possible in JSON format. You need to include ext/dhtmlxtree_json.js in a page. And here is the example:
js code:

var url = “…”;

There example of the json that should be generated by your server script:

{id:‘0’, item:[
{id:‘1-0’, text:‘item 1’, child:‘1’ },
{id:‘2-0’, text:‘item 2’, child:‘1’ },


“child” property means that children will be loaded dynamically (when an item is opened first time).

The first id property (that is ‘0’ in this example) is the “id” parameter from the request. It means that xml for ‘1-0’ branch should be like so:

{id:‘1-0’, item:[
{id:‘1-1-0’, text:‘item 1-1’, child:‘1’ },
{id:‘2-1-0’, text:‘item 2-1’, child:‘1’ },