Loading data to Grid,bind Grid to TreeView

Hi DHTMLX Community,

I cant find answer how change my grid content when select any item of my TreeView. I have all data in database. Now i have TreeView with 3 levels. there is code from tree.php:

<?php require '../codebase/connector/treemultitable_connector.php'; $res=mysql_connect("localhost","ggg","fff"); mysql_query("SET NAMES UTF8"); mysql_select_db("fm"); $tree = new TreeMultitableConnector($res); $tree->setMaxLevel(3); $level =$tree->get_level(); $tree->dynamic_loading(true); $tree->enable_log("log.txt",true); switch($level){ case 0: $tree->render_table("Companies","id","company_name","",""); break; case 1: $tree->render_table("Localisations","id","name","","company_id"); break; case 2: $tree->render_table("Groups","Id","Name","","localisation_id"); break; case 3: $tree->render_table("Monitors","Id","Name","","group_id"); break; } ?>

There is my script where I run application:

inside companies.php:

<?php require '../codebase/connector/grid_connector.php'; $res=mysql_connect("localhost","ggg","fff"); mysql_query("SET NAMES UTF8"); mysql_select_db("fm"); $conn= new GridConnector($res); $conn->render_table("Companies","id","company_name,company_address,company_email"); Its load one table and when I click to any item in TreeView, my Grid changes to the blank. How makes this dependent from TreeView and load revelant tables from database? Thanks for advice.

According to your code:
myTree.attachEvent(“onSelect”, function (id) { //id -the id of the selected item
myGrid.filterBy(0, id);
return true;
});
You are filtering your grid by the tree item id, while you need to filter by the “company_name”.
you need to get the value of your selected tree item:
myTree.getItemText(id);

myTree.attachEvent("onSelect", function (id) { //id -the id of the selected item myGrid.filterBy(0, myTree.getItemText(id)); return true; });

Thank you for reply.
That solution working. But, how handle filtering when load new table depending on onSelect function in TreeView?

this code working and showing correct one row from table when select 0 lvl item in TreeView:

 myTree.load("data/tree.php", function () {     ////callback function   
                        myGrid.load("data/companies.php", function(){            //callback function
                            myTree.selectItem('0#1');   
                        })
                   
                }); 

                myTree.attachEvent("onSelect", function (id) { //id -the id of the selected item 
                     myGrid.filterBy(0, myTree.getItemText(id));
  
                    return true;
                });
                               
            });

but when I load new data from another table, and want to filter it, it shows whole rows from table. Not only that one, which I set in filterBy(name of displayed tree item):

myTree.load("data/tree.php", function () {     ////callback function   
                        myGrid.load("data/companies.php", function(){            //callback function
                            myTree.selectItem('0#1');   
                        })
                   
                }); 
//                myTree.loadXML("data/tree.php");

                myTree.attachEvent("onSelect", function (id) { //id -the id of the selected item 
                     myGrid.filterBy(0, myTree.getItemText(id));
                     if(id.startsWith('1')){
                         myGrid.load("data/localisations.php");
                         myGrid.filterBy(0, myTree.getItemText(id));
                     }
                
        
                    return true;
                });
                               
            });

Please, try to use:

if(id.startsWith('1')){ myGrid.load("data/localisations.php",function(){; myGrid.filterBy(0, myTree.getItemText(id)); }) }
instead of:

if(id.startsWith('1')){ myGrid.load("data/localisations.php"); myGrid.filterBy(0, myTree.getItemText(id)); }