PDA

View Full Version : tree grid..



lakshmi priya
16 Feb 2013, 10:36 PM
:-/
I am trying to build a dynamic tree grid. While i was building the dynamic grid i got errors lyk this on my console :
1. XML Http request cannot load :... Cross origin requests are only supported for http.
2.Uncaught type error : object is not a function .

How can i resolv this.. Help me plz...

vicvolk
17 Feb 2013, 8:30 AM
Explore this working code of a "dynamic" tree, as you say.



Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id'},
{name: 'text'}
]
})
var store = Ext.create('Ext.data.TreeStore', {
autoload:true,
model:'MyModel',
proxy:{
type:'ajax',
url:'json/menuTree.php',
node:'id'
},
root: {
text:'Objects',
id:'src',
expanded:true
}
})
var tree = Ext.create('Ext.tree.Panel',{
store:store,
rootVisible: false,
renderTo:'example'
})


On the server side PHP code looks like this:


$parent_id = $_GET['node'];
$q = "SELECT `id`, `text`, CASE WHEN if_folder = 1 THEN false WHEN if_folder = 0 THEN 'true' END AS leaf FROM menu where id_parent='".$parent_id."' order by id_order";
$r = mysql_query($q);
$arr = array();
while($obj = mysql_fetch_object($r)) {
$arr[] = $obj;
}
echo php_json_encode($arr);

You should have some logic to specify leaves and folders. And see that the first time when tree is loaded, it loads only folders of the highest level, because in my case id_parent = 0. When you start clicking on folder-nodes you will pass to the server id of a parent and as e response you will get all children of that particular node.