PDA

View Full Version : Linked Combos



SwetaMishra
27 Dec 2010, 3:59 AM
var winDelUser;
var frmDelUser;
var userInfoStore = new Ext.data.JsonStore(
{
url : 'UserInformation.action',
remoteSort : false,
root : 'list',
idProperty : 'id',
totalProperty : 'total',
fields : ['Name','id','cid']
//autoLoad : true
});

var CompanyInfo = new Ext.data.JsonStore({
url : 'UserRoleInformation.action?loc=company',
remoteSort : false,
autoLoad : true,
idProperty : 'id',
root : 'list',
totalProperty : 'total',
fields : ['cid','Company']
});

Ext.onReady(function() {
Ext.QuickTips.init();
var dataSet = {
xtype : 'fieldset',
autoHeight : true,
layout : 'form',
align : 'center',
items : [
{
xtype : 'combo',
fieldLabel : '<font color=#15428B><b>Company Name</b></font><font color=red>*</font>',
displayField : 'Company',
valueField : 'cid',
id : 'delCmpInfo',
name : 'delCmpInfo',
//disabled : true,
forceSelection : true,
editable : false,
store : CompanyInfo,
typeAhead : false,
lazyInit : false,
triggerAction : 'all',
mode : 'local',
//lastQuery : '',
width : 200,
height : 100,
allowBlank : false,
emptyText : 'Please Select',
listeners : {
select : {
fn : function(combo, value) {
var User = Ext.getCmp('delUser');
User.clearValue();
User.setDisabled(true);
User.store.filter('cid', combo.getValue());
User.setDisabled(false);
}
}
}


},

{
xtype : 'combo',
fieldLabel : '<font color=#15428B><b>User Name</b></font>',
id : 'delUser',
name : 'delUser',
displayField : 'Name',
valueField : 'cid',
disabled : true,
store : userInfoStore,
triggerAction : 'all',
mode : 'remote',
allowBlank:false,
autoSelect : false,
forceSelection : true,
disableKeyFilter : false,
typeAhead : false,
lazyInit : false,
emptyText : 'Please Select',
selectOnFocus : true,
width : 200,
height : 100
}
]

};

frmDelUser= new Ext.FormPanel({

frame : false,
border : false,
buttonAlign : 'center',
bodyStyle : 'padding:150px 150px 20px 15px 15px;',
width : 430,
//monitorValid: true,
labelWidth : 160,
id : 'frmDelUser',
items : [dataSet],
buttonAlign : 'center',
buttons : [{
text : '<font color=#15428B size=2><b>Delete</b></font>',
id:'btnUser',
//formBind: true,
handler : function() {
var button=Ext.getCmp('btnUser').getText();
if(button=='<font color=#15428B><b>Delete</b></font>')
{

alert("if");
//var rname=document.getElementById("editassName").value;
frmDelUser.getForm().submit({
url : 'DeleteUserInfo.action',
method : 'POST',
waitTitle : 'Checking',
waitMsg : 'Validating ....',
success : function() {
Ext.Msg.alert('Delete','User has been deleted',
function(btn, text) {
if (btn == 'ok') {
winDelUser.hide();
frmDelUser.getForm().reset();
Ext.getCmp('Msglabel').update('<b><font size=2pt color=red></font></b>');
UploadWin.show();
Uploadform.show();
uploadCompanyStore.load();
Uploadform.getForm().reset();
Ext.getCmp('Reglabel').update('<b><font size=2pt color=red></font></b>');
Ext.getCmp('btnUser').setDisabled('false');
}
});
},

failure : function(form, action) {
if (action.failureType == 'server') {
//Ext.Msg.alert('Error',
//'Registration failed due to server error');
Ext.getCmp('Reglabel').update('<center><b><font size=2pt color=red>User not deleted </font></b></center>');
} else { // formRegister.getForm().submit();
//Ext.Msg .alert('Registration Failed','Email Id already exist or Manadatory fields are left unfilled !!!');
Ext.getCmp('winDelUser').setHeight(210);
Ext.getCmp('Reglabel').update('<center><b><font size=2pt color=red>User not deleted</font></b></center>');
frmDelUser.getForm().reset();
}

}

}


);

}
else
{
alert("else");
winAddUser.show();
//Ext.getCmp('btnUser').setDisabled('false');
Ext.getCmp('submitbtn').setText('<font color=#15428B><b>Update</b></font>');
Ext.getCmp('winAddUser').setTitle('<font color=#15428B size=4><b><center>Edit Information</center></b></font>');
//Ext.getCmp('AddPassword').getEl().up('.x-form-item').setDisplayed(false);
//Ext.getCmp('AddCpassword').getEl().up('.x-form-item').setDisplayed(false);
// winRegisterSub.show();
// var cinno=document.getElementById("upcompcinno").value;
// var rtype=document.getElementById("editAsscompnames").value;
// var rname=document.getElementById("editassName").value;
// formRegisterSub.getForm().reset();
// Ext.getCmp('winRegisterSub').setHeight(435);
// winRegisterSub.show();
// Ext.getCmp('subcompName').getEl().up('.x-form-item').setDisplayed(false);
// Ext.getCmp('subcompcinno').getEl().up('.x-form-item').setDisplayed(false);
// Ext.getCmp('subNo').getEl().up('.x-form-item').setDisplayed(false);
// Ext.getCmp('subcompnames').getEl().up('.x-form-item').setDisplayed(false);
// Ext.getCmp('subassName').getEl().up('.x-form-item').setDisplayed(false);
//

//f.container.up('div.x-form-item').hide();
// var company=Ext.getCmp('editAsscompName');
// company.setDisabled(true);
//
frmDelUser.getForm().load(

{
url:'EditCompReg.action',
params:{upcompcinno:cinno, hid_divno:rtype,editassName:rname},
method:'POST'

});


}
}
}
]
});
winDelUser = new Ext.Window({
title : '<font color=#15428B size=3><b><center>Delete Role</center></b></font>',
id : 'winDelUser',
layout : 'fit',
width : 410,
height : 195,
resizable : false,
closable : false,
items : [frmDelUser]

});
// winRegisterDiv.show();
// };

});


I am using linked combos.When the user selects a company based on it the user list is populated but when i select any company for first time all the exisitng users are displayed.Next time i select any company then the user list is populated correctly.

Condor
27 Dec 2010, 4:15 AM
You can only filter a store after it is loaded, so you will need to make the userInfoStore store autoLoad:true.

An alternative is reloading the userInfoStore store with the company as parameter (and have your server return only the appropriate records).