TreeGrid is flattened when using Connector

Hi,

I am trying to render the TreeGrid, and I read this:

$conn->render_sql($sql,$id,$text,$extra,$relation);

Parameters:

  • $sql - any sql code, which will be used as a base for data selection;
  • $id - name of id field;
  • $text - comma separated list of data fields;
  • $extra - comma separated list of extra fields, optional;
  • $relation_id - used for building hierarchy in case of Tree and TreeGrid.

So I wrote it like this, but my TreeGrid comes out flat. There are no folders and no leafs:

$treeGrid->render_sql("Select * from my_table","node_id","node_name,node_parent","","node_parent");

Can you advise please?
Thanks!

Also I have some trouble with the SQL for it… my tree and grid are in separate tables. Do I need to put them in the same table to work for TreeGrid?

For example a tree of colors:

node_id 	node_name 	node_parent
1			Blue			0
2			Red			1
3			Green		1
4			Purple		2
5			Pink			2
5			Yellow		3	
7			Orange		3
8			Brown		5
9			Grey			5

A table that lists all Grid items and the “parent” which is node_id.

grid_id 	node_id 	grid_name 			grid_itemtype 
	
1 		2 		Spiderman 			Book	
2		3 		Batman			 		Book 	
3 		5 		Ironman 			Book
4 		6 		Mighty Mouse		Calendar 		
5 		4 		Cookie					Good
6 		2 		Coffee					Good	
7 		22 		Disco				DVD
8 		3 		Country Music		DVD
9 		5 		Video Game			DVD 			
11 		16 		Blues				DVD

How to output this in treeGrid, where the colors are the Tree Leafs:

Blue
	Red
						Spiderman	 	Book
						Coffee				Good
		Purple
						Cookie				Good	
		Pink		
						Video Game		DVD
	Green
						Batman				Book	
						Country Music	DVD

(etc)

It needs to list multiple Grid items for one leaf.

There are no folders and no leafs:
On client side, during grid’s construction, have you defined any column in it as “tree” ?
Without it , grid will render self as plain structure

Also, be sure to use TreeGridConnector object on the server side.

Maybe that type of connector will work better in your case.
It was designed to use data from different tables on different levels of hierarchy.

docs.dhtmlx.com/doku.php?id=dhtm … table_tree

Hi,
My html was working when I loaded from XML file, but I will paste, in case I made some new error.

var treegrid = dhxLayout.cells("a").attachGrid();
	treegrid.setImagePath("codebase/imgs/tree_blue/");
	treegrid.setSkin("light");
	treegrid.setHeader("a,b,c,d,e,f,g");
	treegrid.setInitWidths("*,220,80,80,80,80,*");
	treegrid.setColAlign("left,left,left,left,left,left,left");
	treegrid.setColTypes("tree,ed,ro,ed,ed,ed,ed");
	treegrid.setColSorting("str,str,str,str,str,str,str");
	treegrid.enableDragAndDrop(true, true);
	treegrid.setDragBehavior("complex", true);
	treegrid.enableContextMenu(contextmenu);
	treegrid.init();
	//treegrid.loadXML("SampleTreeGrid.xml");
	treegrid.loadXML("connect/get_treegrid.php");

When I switch to load from MySql, using grid_connector.php and “new GridConnector($res);”, my tree became flat.

When I switched to treegrid_connector.php and “new TreeGridConnector($res)”, I have now only one row, the parent level 0.

<?php
require_once('../connect/config.php');
require_once("../codebase/treegrid_connector.php");

$res=mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db("isti_ab");
	
$treeGrid = new TreeGridConnector($res);
$treeGrid->dynamic_loading(100);
$treeGrid->render_sql("Select * from my_table","node_id","node_name,node_parent","","node_parent");

?>

When I switched to treegridmultitable_connector.php and “new TreeMultitableConnector($res)”, I got an error popup with XML in it:

<?xml version='1.0' encoding='utf-8' ?><tree id='0'><item id='0#1' text='First Tree Leaf' child='1' ></item>...

This looks like the XML for a Tree and not for a TreeGrid?

Is there somewhere an example of the PHP used for TreeGrid with Connector? And the html to match with it. Is $relation_id supposed to be id of the parent item?

Thanks.

The render command which you are using is definitely correct.
The same code locally produces hierarchical xml bassed on node_parent value.

TreeMultitableConnector
It must be TreeGridMultitableConnector

docs.dhtmlx.com/doku.php?id=dhtm … table_tree

If the render command is correct, then why does it display only node 0?
Thanks.

In php code you have
$treeGrid->dynamic_loading(100);

which enables dynamical branch loading.
Comment this code in the php file, or use correcty syntax for dynamical branch loading in js code