PDA

View Full Version : TreeStore, TreeGrid, MVC & loading ajax/json from php file...



Allan Stark
26 Jul 2012, 6:45 AM
MVC application, ExtJS 4.1.1, latest Chrome (IE, FF, Opera, etc...).

Controller:

Ext.define('ECS2.controller.controller_invoices', {
extend: 'Ext.app.Controller',
views: 'view_invoices_list',
stores: ['treestore_invoices'],
models: ['model_treestore_invoices']
});

Model:

Ext.define('ECS2.model.model_treestore_invoices', {
extend: 'Ext.data.Model',
fields: [
{name: 'invoice_date', type: 'string'},
{name: 'invoice_number', type: 'string'},
{name: 'invoice_item', type: 'string'}
]
});

TreeStore:

Ext.define('ECS2.store.treestore_invoices', {
extend: 'Ext.data.TreeStore',
rootVisible: false,
model: 'model_treestore_invoices',
proxy: {
type: 'ajax',
url: 'load_invoices.php'
},
autoLoad: true
});

Viewer:

Ext.define('ECS2.view.view_invoices_list.js' ,{
extend: 'Ext.tree.Panel',
alias : 'widget.view_invoices_list',
title: 'Invoice list',
store: 'treestore_invoices',
model: 'model_treestore_invoices',
rootVisible: false,
columns: [{
xtype: 'treecolumn',
text: 'invoice_date',
dataIndex: 'invoice_date',
flex:2
},{
xtype: 'treecolumn',
text: 'invoice_number',
dataIndex: 'invoice_number',
flex:1
},{
xtype: 'treecolumn',
text: 'invoice_item',
dataIndex: 'invoice_item',
flex:1
}],
dockedItems: [{
xtype: 'form',
dock: 'top',
bodyStyle: 'padding:2px 2px 2px 42px',
frame: true,
layout: 'hbox',
height: 35,
items: [{
xtype: 'datefield',
fieldLabel: 'Date from:',
name: 'log_date_start',
width: 140,
labelWidth: 50,
margin: '0 10 0 0'
},{
xtype: 'datefield',
fieldLabel: 'Date to:',
name: 'log_date_end',
width: 140,
labelWidth: 50,
margin: '0 10 0 0'
}]
}]
});

In php simple echo (for test):

<?php
echo " {'text':'.','children': [
invoice_date:'13.01.2012',
invoice_number:'11111',
invoice_item':'test1',
expanded: true,
children:[{
invoice_date:'22222',
invoice_number:'22222',
invoice_item:'test2',
children:[{
invoice_date:'33333',
invoice_number:'33333',
invoice_item:'test3',
leaf':true
},{
invoice_date:'44444',
invoice_number:'44444',
invoice_item:'test4',
leaf:true
}]
}]
]}
";
>

The data from the php file tree is not visible (treegred is clear), the are not errors in console...
What's wrong ?

scottmartin
27 Jul 2012, 1:13 PM
You have numerous errors in your json .. this works:



<?php
echo " {'text':'.','children': [
{
invoice_date:'13.01.2012',
invoice_number:'11111',
invoice_item:'test1',
expanded: true,
children:[{
invoice_date:'22222',
invoice_number:'22222',
invoice_item:'test2',
children:[{
invoice_date:'33333',
invoice_number:'33333',
invoice_item:'test3',
leaf:true
},{
invoice_date:'44444',
invoice_number:'44444',
invoice_item:'test4',
leaf:true
}]
}]
}
]}
";
?>


Scott.

Allan Stark
30 Jul 2012, 12:59 AM
Yes... It's my mistake. :">
But now text labels do not display.
In this sample, it works well: http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/tree/treegrid.html
(http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/tree/treegrid.html)Why ?
Whether to introduce an additional standart field "text" into model or json file ?
But in the example above, there is no such field in json...

37595

Allan Stark
30 Jul 2012, 1:09 AM
Earned by replacing in treestore:

...
model: 'model_treestore_invoices'
...

to

...
model: 'ECS2.model.model_treestore_invoices'
...

Is this bug ?

scottmartin
30 Jul 2012, 6:32 AM
You should not define model in your tree. You model is assigned to the store, the store to the tree.

Scott.