Code:
Ext.ns("sistema");
sistema.LinkedComboBoxTutorial = {
init: function(){
var empresasStore = this.getStore();
var municipiosStore = new Ext.data.JsonStore({
autoLoad: true,
url: 'datosEmpresas.php',
baseParams:{ accion: 2 },
root: 'datos',
totalProperty: 'total',
fields: [
{name:'value', type: 'string'},
{name:'label', type: 'string'},
]
});
var comboMunicipio =new Ext.form.ComboBox({
fieldLabel: 'Municipio',
name: 'comboMunicipio',
forceSelection: true,
store: municipiosStore,
emptyText: 'Selecciona un Municipio...',
triggerAction: 'all',
displayField: 'label',
valueField: 'value',
mode: 'local',
//hideTrigger:true,
editable: false
//minChars:3
});
var comboEmpresas = new Ext.form.ComboBox({
fieldLabel: 'Empresas',
name: 'comboEmpresas',
forceSelection: true,
store : empresasStore,
emptyText: 'Seleccionar una empresa',
triggerAction: 'all',
editable: false,
displayField: 'EMPRESA',
valueField: 'CVE_EMPRESA',
width: 500,
disabled: true,
mode: 'local'
});
comboMunicipio.on('select',function(cmb,record,index){
comboEmpresas.clearValue();
comboEmpresas.enable();
empresasStore.load({
params:{
accion: 1,
municipio:record.get('value')
}
});
},this);
var panel1 = new Ext.FormPanel({
url: 'datosEmpresas.php',
title: 'Seleccione Filtros',
items: [comboMunicipio, comboEmpresas],
region: 'south',
//layout: 'form',
height: 150,
buttons: [ {text: 'Buscar',
handler: function(){
panel1.getForm().submit();
}
} ]
//iconCls: 'users'
});
var panel2 = new Ext.Panel({
region: 'center'
});
/**
* PANEL PRINCIPAL
*/
var main = new Ext.Panel({
title: 'Banco de Datos',
height:600,
layout: 'border',
defaults: {
//collapsible:true,
border: true,
bodyStyle: 'padding:10px;',
//titleCollapse: true,
},
items: [panel1,panel2]//,panel3]
});
main.render('panel');
},
getStore: function(){
var store = new Ext.data.JsonStore({
url:'datosEmpresas.php',
root:'datos',
fields: ['CVE_EMPRESA','EMPRESA']
});
return store;
}
}
Ext.onReady(sistema.LinkedComboBoxTutorial.init,
sistema.LinkedComboBoxTutorial);