ExtJS 4.2 treepanel data from PHP

89 Views Asked by At

I have a treepanel into a tabpanel:

TREE PANEL

var storeTreePanel= Ext.create('App.store.strTreePanel');
var tabpanelsecundario4_1 = new Ext.tab.Panel({
        itemId : 'tabpanelsecundario4_1',
        region : 'center',
        layout : 'fit',
        width : "100%",
        height : "100%",
        border : false,
        activeTab: 1,
        items:[
               {
                   itemId : 'tabDatosEconomicos',
                   title : '<span style="color:#C85E00;font-weight:bold;">Datos Economicos</span>',
                   layout:'fit',
                   items:[
                          {
                              xtype : 'treepanel',
                              itemId : 'gridCriteriosLostes',
                              autoScroll : true,
                              store : storeTreePanel,
                              rootVisible : false,
                              columns : [
                                         {header:'<span style="color:#C85E00;">Column1</span>', dataIndex:'text',       itemId:'',  flex:3.5},
                                         {header:'<span style="color:#C85E00;">Column2</span>', dataIndex:'referencia', itemId:'',  flex:1},
                                         {header:'<span style="color:#C85E00;">Column3</span>', dataIndex:'producto',   itemId:'',  flex:2},
                                         {header:'<span style="color:#C85E00;">Column4</span>', dataIndex:'unidades',   itemId:'',  flex:1},
                                         {header:'<span style="color:#C85E00;">Column5</span>', dataIndex:'ofertado',   itemId:'',  flex:1,     align:'center'},
                                         {header:'<span style="color:#C85E00;">Column6</span>', dataIndex:'importe',    itemId:'',  flex:1,     align:'right'},
                                         {header:'<span style="color:#C85E00;">Column7</span>', dataIndex:'baja',       itemId:'',  flex:0.5,   align:'right'},
                                         {header:'<span style="color:#C85E00;">Column8</span>', dataIndex:'adj',        itemId:'',  flex:0.5,   align:'center'},
                                         {header:'<span style="color:#C85E00;">Column9</span>', dataIndex:'motivos',    itemId:'',  flex:2.5}
                              ]
                          }
                   ]
               }
        ]
    });

TREEPANEL STORE

Ext.define('App.store.strTreePanel', {
    extend: 'Ext.data.TreeStore',
    model:  'App.model.mdlTreePanel',
    autoLoad: false,
    folderSort: true,
    proxy: {
        type: 'ajax', 
        api: {read: './data/php/FillTreePanel.php'},
        reader: {
                    type: 'json',
                    root: 'data',
                    totalProperty: 'total',
                    successProperty: 'success'
        }
    }
});

TREEPANEL MODEL

Ext.define('App.model.mdlTreePanel', {
    extend: 'Ext.data.Model',
    fields:[
            {name:'id',                 type:'string',      mapping:''},
            {name:'text',               type:'string',      mapping:''},
            {name:'referencia',         type:'string',      mapping:''},
            {name:'producto',           type:'string',      mapping:''},
            {name:'unidades',           type:'integer',     mapping:''},
            {name:'ofertado',           type:'boolean',     mapping:''},
            {name:'importe',            type:'float',       mapping:''},
            {name:'baja',               type:'float',       mapping:''},
            {name:'adj',                type:'boolean',     mapping:''},
            {name:'motivos',            type:'text',        mapping:''},
            {name:'leaf',               type:'boolean',     mapping:''}
    ]
});

PHP FILE

<?php
mysqli_query($connection,"SET NAMES 'utf8'");

$sql="some select";

$result=mysqli_query($connection,$sql);
$data = array();

while($row = mysqli_fetch_array($result)){
    array_push($data, array(
            "id"            => $row[data1],
            "text"          => $row[data2],
            "referencia"    => $row[data3],
            "producto"      => $row[data4],
            "unidades"      => $row[data5],
            "ofertado"      => $row[data6],
            "importe"       => $row[data7],
            "baja"          => $row[data8],
            "adj"           => $row[data9],
            "motivos"       => $row[data10]
    ));
    $linea++;
}
echo json_encode(array(
        'success'=>true,
        'total'=>count($data),
        'data'=> $data,
        'sql'=> $sql
));
?>

When I return the data I dont get any parent folder,all the data is shown as leafs.

enter image description here

Am I returning the data in an incorrect format?

Is something wrong in the php creating the returning data?

In the docs of sencha (link), it creates the store from javascript with static data, but my data is dinamic and I haven´t found any guide or information on how to create data from a php file and return it.

1

There are 1 best solutions below

0
SensacionRC On

SOLVED

I forgot a little detail, in my treepanel columns declaration, I forgot to declare the first column as "xtype: 'treecolumn'", with this, the first column is no expandable.

And in the doc (link) doesn´t say nothiong about this