PDA

View Full Version : Did not loaded data into combobox at Grid with Writable Store



VezaR
31 Mar 2012, 8:56 AM
Greetings.
I am using the following example http://dev.sencha.com/deploy/ext-4.0.7-gpl/examples/writer/writer.html to add a column called'' last ". This column is the type combobox. I I'm using practice.

The combobox load perfectly if the data is stored locally, ie if I set store: ["Hello","How about"] ...
But when I try to access data stored on the server, not the load but remains inloading.
The firebug does not flag an error, it returns me strange that the server data in this form {"list": {"last": "Ok"}}

I want to know why the selection does not show the "Ok"?

My code in writer.js


initComponent: function(){


this.editing = Ext.create('Ext.grid.plugin.CellEditing');

//Here data server
var lista = new Ext.data.JsonStore({
autoLoad: true,
proxy: new Ext.data.HttpProxy({
url: 'access.php',
method: 'POST'
}),
root: 'lista',
fields: [
{name:'last', type: 'string'},]
});

Ext.apply(this, {
iconCls: 'icon-grid',
frame: true,
plugins: [this.editing],
dockedItems: [{
xtype: 'toolbar',
items: [{
iconCls: 'icon-add',
text: 'Add',
scope: this,
handler: this.onAddClick
}, {
iconCls: 'icon-delete',
text: 'Delete',
disabled: true,
itemId: 'delete',
scope: this,
handler: this.onDeleteClick
}]
}, {
weight: 2,
xtype: 'toolbar',
dock: 'bottom',
items: [{
xtype: 'tbtext',
text: '<b>@cfg</b>'
}, '|', {
text: 'autoSync',
enableToggle: true,
pressed: true,
tooltip: 'When enabled, Store will execute Ajax requests as soon as a Record becomes dirty.',
scope: this,
toggleHandler: function(btn, pressed){
this.store.autoSync = pressed;
}
}, {
text: 'batch',
enableToggle: true,
pressed: true,
tooltip: 'When enabled, Store will batch all records for each type of CRUD verb into a single Ajax request.',
scope: this,
toggleHandler: function(btn, pressed){
this.store.getProxy().batchActions = pressed;
}
}, {
text: 'writeAllFields',
enableToggle: true,
pressed: false,
tooltip: 'When enabled, Writer will write *all* fields to the server -- not just those that changed.',
scope: this,
toggleHandler: function(btn, pressed){
this.store.getProxy().getWriter().writeAllFields = pressed;
}
}]
}, {
weight: 1,
xtype: 'toolbar',
dock: 'bottom',
ui: 'footer',
items: ['->', {
iconCls: 'icon-save',
text: 'Sync',
scope: this,
handler: this.onSync
}]
}],
columns: [{
text: 'ID',
width: 40,
sortable: true,
dataIndex: 'id'
}, {
header: 'Correo',
flex: 1,
sortable: true,
dataIndex: 'email',
field: {
type: 'textfield'
}
}, {
header: 'Nombre',
width: 100,
sortable: true,
dataIndex: 'first',
field: {
type: 'textfield'
}
}, {
header: 'Apellido',
width: 100,
sortable: true,
dataIndex: 'last',
field: {
type: 'textfield'
}
}, {
xtype: 'datecolumn',
header: 'Fecha',
dataIndex: 'fecha',
width: 100,
editor: {
xtype: 'datefield',
format: 'Y/m/d',
minValue: '01/01/2012',
disabledDays: [0, 6],
disabledDaysText: 'Fecha no disponible',
maxValue: Ext.Date.format(new Date(), 'Y/m/d')
}
}, {
header: 'Selección', //Here combobox
dataIndex: 'lista',
width: 130,
editor: {
xtype: 'combobox',
store: lista,
displayField:'last',
valueField: 'last',
editable: false,
typeAhead: true,
queryMode: 'local',
forceSelection:true,
triggerAction: 'all',
emptyText:'Selecciona...',
selectOnFocus:true
}
}]
});
this.callParent();
this.getSelectionModel().on('selectionchange', this.onSelectChange, this);
},



My code in access.php


<?php
//include 'bd.php';
//initDB();
//$query = "SELECT id, last FROM db_prueba.tbl_usuario;";
//$result = mysql_query($query);
//
//$lista=array();
//
//while($registro=mysql_fetch_row($result))
// {
// $array=array('id'=>$registro[0], 'last' => $registro[1]);
// array_push($lista, $array);
// }
//
//closeDB();
echo json_encode(
array(
"lista" => array("last"=>"Ok")
)
);
?>


Can you please suggest me what is wrong here?

vietits
31 Mar 2012, 4:16 PM
//Here data server
var lista = new Ext.data.JsonStore({
autoLoad: true,
proxy: new Ext.data.HttpProxy({
url: 'access.php',
method: 'POST'
}),
root: 'lista',
fields: [
{name:'last', type: 'string'},]
});

You should define root for proxy reader, not store. Why don't you create store like below?


var lista = Ext.create('Ext.data.Store', {
autoLoad: true,
proxy: {
type: 'ajax',
url: 'access.php',
method: 'POST',
reader: {
type: 'json',
root: 'lista'
}
},
fields: [
{name:'last', type: 'string'}
]
});

VezaR
1 Apr 2012, 5:42 AM
thanks buddy! It worked well. =)