PDA

View Full Version : Extjs 4 TreePanel data + json help!



bacuvalen
3 Nov 2016, 3:36 AM
Hello guyz,

Im searching for 1 week about this and i didnt find something..
The problem is cuz i need to create a treeGrid/treePanel what needs to get data from my mmsql database and then each site from the database needs to have same 4 static rows. And i really dont know how to do that.. i really need your help..

Here is my js file:

Ext.require([ 'Ext.data.*',
'Ext.grid.*',
'Ext.tree.*'
]);


Ext.onReady(function() {


// LOG OUT //
var LogOut = new Ext.Action({
text: 'Log Out',
icon:'assets/img/logout.png',
handler: function(){
location.href = 'login.php?logout=yes';
}
//iconCls: 'blist'
});


// MODEL //
Ext.define('mygrid', {
extend: 'Ext.data.Model',
fields: [
{name: 'MSD_Site_ID', type: 'string'},
{name: 'Region', type: 'string'},
{name: 'Site_Type', type: 'string'},
{name: 'Site_Category', type: 'string'},
{name: 'Update_RFR', type: 'string'},
{name: 'MSD_Name', type: 'string'},
{name: 'MPS_POS_Switch_Name', type: 'string'},
{name: 'MPS_POS_Site_ID', type: 'string'},
{name: 'Planning', type: 'string'},
{name: 'Scheduling', type: 'string'},
{name: 'Deployment', type: 'string'},
{name: 'Migration', type: 'string'}
]
});


// STORE //
var storeTree = Ext.create('Ext.data.TreeStore', {
pageSize: 50,
remoteSort: true,
model: mygrid,
proxy: {
type: 'ajax',
url: 'php/vdf_read.php',
reader: {
type: 'json',
root: 'data'
//totalProperty: 'totalCount'
},
},
autoLoad: true,
});


// TREE GRID //
var tree = Ext.create('Ext.tree.Panel', {
title: 'Testing DE',
//layout: 'border',
width: 1000,
height: 800,
renderTo: Ext.getBody(),
collapsible: true,
useArrows: true,
rootVisible: false,
multiSelect: true,
store: storeTree,
//root: rootNode,
singleExpand: true,
tbar: ['->', LogOut],
region: 'center',
columns:[
{text: 'MSD Site ID', xtype: 'treecolumn', flex: 2, dataIndex: 'MSD_Site_ID', sortable: true, expanded : true,
children : [{
"MSD_Site_ID": "1.Planning Completeness %",
"leaf": true,
xtype: 'templatecolumn',
dataIndex: 'Planning'
}, {
"MSD_Site_ID": "2. Scheduling",
"leaf": true,
"done": true,
xtype: 'templatecolumn',
dataIndex: 'Scheduling'
}, {
"MSD_Site_ID": "3. Deployment on field",
"leaf": true,
xtype: 'templatecolumn',
dataIndex: 'Deployment'
}, {
"MSD_Site_ID": "4. Migration",
"leaf": true,
xtype: 'templatecolumn',
dataIndex: 'Migration'
}
]},
{text: 'Region', dataIndex: 'Region', sortable: true},
{text: 'Site Type', dataIndex: 'Site_Type', sortable: true},
{text: 'Site Category', dataIndex: 'Site_Category', sortable: true},
{text: 'Update RFR', dataIndex: 'Update_RFR', sortable: true},
{text: 'MSD Name', dataIndex: 'MSD_Name', sortable: true},
{text: 'MPS POS Switch', dataIndex: 'MPS_POS_Switch_Name', sortable: true},
{text: 'MPS POS Site ID', dataIndex: 'MPS_POS_Site_ID', sortable: true}
]/*,
bbar:[
Ext.create('Ext.PagingToolbar', {
store: storeTree,
displayInfo: true,
displayMsg: 'Displaying records {0} - {1} of {2}',
emptyMsg: "No records"
})
]*/
});
});
Here is my php file:

<?php



$start = isset($_GET['start']) ? $_GET['start'] : 0 ;
$limit = isset($_GET['limit']) ? $_GET['limit'] : 50 ;




$sql = "Select a.* from
( select count(*) over() RECCOUNT, ROW_NUMBER() OVER(ORDER BY MSD_Site_ID) as [Row],
* from (
select
CAST (MSD_Site_ID as nvarchar (200)) as MSD_Site_ID,
CAST (Region as nvarchar (200)) as Region,
CAST (Site_Type as nvarchar (200)) as Site_Type,
CAST (Site_Category as nvarchar (200)) as Site_Category,
CAST (Update_RFR as nvarchar (200)) as Update_RFR,
CAST (MSD_Name as nvarchar (200)) as MSD_Name,
CAST (MPS_POS_Switch_Name as nvarchar (200)) as MPS_POS_Switch_Name,
CAST (MPS_POS_Site_ID as nvarchar (200)) as MPS_POS_Site_ID
from [database].[dbo].[testingtable]) subcolumns
) a where [ROW] > $start and [ROW] <= ($start+$limit)
";


//echo($sql);die();


$rs=mssql_query($sql);
if (!$rs)
{
exit('MSSQL error: ' . mssql_get_last_message());
}


$result = array();


while($row = mssql_fetch_assoc($rs)){
foreach ($row as $column => $value) {
$row[$column] = $value;
}
$arr[] = $row;
}
//print_r($arr);die();
$totalRecords = (count($arr) > 0) ? $arr[count($arr) - 1]['RECCOUNT'] : 0;
//echo '{"data":'.json_encode($arr).'}';
echo json_encode(array("totalCount" => $totalRecords, "data" => $arr));




?>
The result is this>>

55405

The problem is cuz the query its looping when i open the parent site. I dont want to loop.. i want to show me the 4 childrens:

children : [{ "MSD_Site_ID": "1.Planning Completeness %",
"leaf": true,
xtype: 'templatecolumn',
dataIndex: 'Planning'
}, {
"MSD_Site_ID": "2. Scheduling",
"leaf": true,
"done": true,
xtype: 'templatecolumn',
dataIndex: 'Scheduling'
}, {
"MSD_Site_ID": "3. Deployment on field",
"leaf": true,
xtype: 'templatecolumn',
dataIndex: 'Deployment'
}, {
"MSD_Site_ID": "4. Migration",
"leaf": true,
xtype: 'templatecolumn',
dataIndex: 'Migration'
}
]},

Can please someone help me with this..?

Thank you in Advance!

bacuvalen
4 Nov 2016, 7:03 AM
Someone?

bacuvalen
14 Nov 2016, 4:29 AM
I found the problem. The problem waz that i needed to find the level of the leaf. After that i made an Index Table with the buttons what i want to drop from the MSD Site ID. And after that i made querys with each level to expand.