PDA

View Full Version : ComboBox store and refresh list



sunco
24 Feb 2010, 12:22 PM
I have two ComboBox. When i choose an option on the first Combo, i call the load method of the second Combo. The JSON values returned are fine but not visibles

When i click to open the second Combo it does the load again and this time the values are displayed on the list

How can avoid two load ? I use the e.cancel on beforequery event. This way the list of second Combo is empty

Btw, the beforequery event only fires when click that Combo, so the manual load must work

Maybe i'm missing some refresh stuff

sunco
24 Feb 2010, 2:49 PM
This is the code. As i say it works but not as it should or as i think. It load twice


<input type="text" id="combo_estados_10" size="20"> <input type="text" id="combo_estados_11" size="20">


estados = [
['1', 'Aguascalientes'],
['3', 'Baja California Sur'],
['4', 'Campeche'],
['7', 'Chiapas'],
['8', 'Chihuahua']
];

var store = new Ext.data.ArrayStore({
fields: ['id', 'estado'],
data : estados
});

var storeAjax1011 = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'includes/ajax.php?accion=BuscaCiudades',
listeners: {
load: function() {
alert("load");
}
}
}),
reader: new Ext.data.JsonReader({
root: 'ciudades',
totalProperty: 'registros',
id: 'id_ciudad',
fields: [
{name: 'nom_ciudad'}
]
})
});

var combo10 = new Ext.form.ComboBox({
store: store,
displayField: 'estado',
mode: 'local',
emptyText: 'Selecciona un estado',
triggerAction: 'all',
applyTo: 'combo_estados_10',
listeners: {
select: function(combo, record, index) {
this.collapse();

// other stuff...

storeAjax1011.baseParams = { id_estado : record.data.id };
combo11.store.load(); // this works but does not refresh the list of combo11
}
}
});

var combo11 = new Ext.form.ComboBox({
store: storeAjax1011,
displayField: 'nom_ciudad',
emptyText: 'Selecciona una ciudad',
triggerAction: 'all',
editable: false,
applyTo: 'combo_estados_11',
listeners: {
beforequery:function(e) {
//e.cancel = true;

// without the e.cancel, the code re-load the values
}
}
});

The valid JSON


stcCallback1001({"registros":94,"ciudades":[{"id_ciudad":"3088","nom_ciudad":"ADOLFO LOPEZ MATEOS (EL TAMARI"},{"id_ciudad":"3100","nom_ciudad":"ADOLFO L\u00f3PEZ MATEOS (JAHUARA S"},{"id_ciudad":"3104","nom_ciudad":"ADOLFO RU\u00edZ CORT\u00edNES"},{"id_ciudad":"3127","nom_ciudad":"AGUA VERDE"},{"id_ciudad":"4053","nom_ciudad":"AGUAVERDE, ROSARIO"}]});

Of course, the stcCallback1001 name is dynamic

sunco
24 Feb 2010, 3:00 PM
MODS: Fix that permission stuff. Add some "secure user" when somebody has more than 10 valid posts or moderate post with links

This is the code. As i say it works but not as it should or as i think. It load twice


<input type="text" id="combo_estados_10" size="20"> <input type="text" id="combo_estados_11" size="20">


estados = [
['1', 'Aguascalientes'],
['3', 'Baja California Sur'],
['4', 'Campeche'],
['7', 'Chiapas'],
['8', 'Chihuahua']
];

var store = new Ext.data.ArrayStore({
fields: ['id', 'estado'],
data : estados
});

var storeAjax1011 = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'includes/ajax.php?accion=BuscaCiudades',
listeners: {
load: function() {
alert("load");
}
}
}),
reader: new Ext.data.JsonReader({
root: 'ciudades',
totalProperty: 'registros',
id: 'id_ciudad',
fields: [
{name: 'nom_ciudad'}
]
})
});

var combo10 = new Ext.form.ComboBox({
store: store,
displayField: 'estado',
mode: 'local',
emptyText: 'Selecciona un estado',
triggerAction: 'all',
applyTo: 'combo_estados_10',
listeners: {
select: function(combo, record, index) {
this.collapse();

// other stuff...

storeAjax1011.baseParams = { id_estado : record.data.id };
combo11.store.load(); // this works but does not refresh the list of combo11
}
}
});

var combo11 = new Ext.form.ComboBox({
store: storeAjax1011,
displayField: 'nom_ciudad',
emptyText: 'Selecciona una ciudad',
triggerAction: 'all',
editable: false,
applyTo: 'combo_estados_11',
listeners: {
beforequery:function(e) {
//e.cancel = true;

// without the e.cancel, the code re-load the values
}
}
});

The valid JSON


stcCallback1001({"registros":94,"ciudades":[{"id_ciudad":"3088","nom_ciudad":"ADOLFO LOPEZ MATEOS (EL TAMARI"},{"id_ciudad":"3100","nom_ciudad":"ADOLFO L\u00f3PEZ MATEOS (JAHUARA S"},{"id_ciudad":"3104","nom_ciudad":"ADOLFO RU\u00edZ CORT\u00edNES"},{"id_ciudad":"3127","nom_ciudad":"AGUA VERDE"},{"id_ciudad":"4053","nom_ciudad":"AGUAVERDE, ROSARIO"}]});

Of course, the stcCallback1001 name is dynamic

sunco
25 Feb 2010, 11:31 AM
Don't know what mods think.. this is third time i post this


<input type="text" id="combo_estados_10" size="20"> <input type="text" id="combo_estados_11" size="20">


estados = [
['1', 'Aguascalientes'],
['3', 'Baja California Sur'],
['4', 'Campeche'],
['7', 'Chiapas'],
['8', 'Chihuahua']
];

var store = new Ext.data.ArrayStore({
fields: ['id', 'estado'],
data : estados
});

var storeAjax1011 = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'includes/ajax.php?accion=BuscaCiudades',
listeners: {
load: function() {
alert("load");
}
}
}),
reader: new Ext.data.JsonReader({
root: 'ciudades',
totalProperty: 'registros',
id: 'id_ciudad',
fields: [
{name: 'nom_ciudad'}
]
})
});

var combo10 = new Ext.form.ComboBox({
store: store,
displayField: 'estado',
mode: 'local',
emptyText: 'Selecciona un estado',
triggerAction: 'all',
applyTo: 'combo_estados_10',
listeners: {
select: function(combo, record, index) {
this.collapse();

// other stuff...

storeAjax1011.baseParams = { id_estado : record.data.id };
combo11.store.load();
}
}
});

var combo11 = new Ext.form.ComboBox({
store: storeAjax1011,
displayField: 'nom_ciudad',
emptyText: 'Selecciona una ciudad',
triggerAction: 'all',
editable: false,
applyTo: 'combo_estados_11',
listeners: {
beforequery:function(e) {
//e.cancel = true;

// without the e.cancel, the code re-load the values
}
}
});

The Json


stcCallback1001({"registros":20,"ciudades":[{"id_ciudad":"187","nom_ciudad":"CERRO DE ORTEGA"},{"id_ciudad":"170","nom_ciudad":"CIUDAD DE ARMER\u00edA"},{"id_ciudad":"189","nom_ciudad":"CIUDAD DE VILLA DE \u00c1LVAREZ"},{"id_ciudad":"171","nom_ciudad":"COFRAD\u00edA DE JU\u00e1REZ"},{"id_ciudad":"173","nom_ciudad":"COLIMA"},{"id_ciudad":"175","nom_ciudad":"SUCHITL\u00e1N"},{"id_ciudad":"185","nom_ciudad":"TECOM\u00e1N"}]});

sunco
25 Feb 2010, 1:53 PM
Don't know what mods think.. this is 4th time i post this


<input type="text" id="combo_estados_10" size="20"> <input type="text" id="combo_estados_11" size="20">


estados = [
['1', 'Aguascalientes'],
['3', 'Baja California Sur'],
['4', 'Campeche'],
['7', 'Chiapas'],
['8', 'Chihuahua']
];

var store = new Ext.data.ArrayStore({
fields: ['id', 'estado'],
data : estados
});

var storeAjax1011 = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'includes/ajax.php?accion=BuscaCiudades',
listeners: {
load: function() {
alert("load");
}
}
}),
reader: new Ext.data.JsonReader({
root: 'ciudades',
totalProperty: 'registros',
id: 'id_ciudad',
fields: [
{name: 'nom_ciudad'}
]
})
});

var combo10 = new Ext.form.ComboBox({
store: store,
displayField: 'estado',
mode: 'local',
emptyText: 'Selecciona un estado',
triggerAction: 'all',
applyTo: 'combo_estados_10',
listeners: {
select: function(combo, record, index) {
this.collapse();

// other stuff...

storeAjax1011.baseParams = { id_estado : record.data.id };
combo11.store.load();
}
}
});

var combo11 = new Ext.form.ComboBox({
store: storeAjax1011,
displayField: 'nom_ciudad',
emptyText: 'Selecciona una ciudad',
triggerAction: 'all',
editable: false,
applyTo: 'combo_estados_11',
listeners: {
beforequery:function(e) {
//e.cancel = true;

// without the e.cancel, the code re-load the values
}
}
});

The Json


stcCallback1001({"registros":20,"ciudades":[{"id_ciudad":"187","nom_ciudad":"CERRO DE ORTEGA"},{"id_ciudad":"170","nom_ciudad":"CIUDAD DE ARMER\u00edA"},{"id_ciudad":"189","nom_ciudad":"CIUDAD DE VILLA DE \u00c1LVAREZ"},{"id_ciudad":"171","nom_ciudad":"COFRAD\u00edA DE JU\u00e1REZ"},{"id_ciudad":"173","nom_ciudad":"COLIMA"},{"id_ciudad":"175","nom_ciudad":"SUCHITL\u00e1N"},{"id_ciudad":"185","nom_ciudad":"TECOM\u00e1N"}]});