PDA

View Full Version : Combobox load store every time triggered



KRavEN
5 Mar 2008, 12:58 PM
I'm trying to save some code by using the same datastore for multiple comboboxes. Everything works fine except the combobox only loads the datastore the first time it is clicked. How can I make it load the store every time the trigger is clicked?

Here is the store:

rule_combo = new Ext.data.Store({
url : '/frontend_dev.php/rule/jsonCombo',
reader : new Ext.data.JsonReader({
root : 'combo'
}, [{
name : 'severity'
}, {
name : 'rule_id-rule_name'
}, {
name : 'rule_id-rule_suite'
}, {
name : 'rule_id-region'
}, {
name : 'rule_id-net_area'
}, {
name : 'rule_id-net_as'
}])
});

Here are some ComboBoxes:

items : [{
fieldLabel : 'Hostname',
name : 'filters[hostname]'
}, {
fieldLabel : 'Rule Name',
xtype : 'combo',
store : rule_combo,
displayField : 'rule_id-rule_name',
editable : false,
selectOnFocus:true,
triggerAction : 'all',
listWidth : 500,
allQuery : 'rule_id-rule_name',
queryParam : 'group',
name : 'filters[rule_id-rule_name]'
}, {
fieldLabel : 'Rule Suite',
xtype : 'combo',
store : rule_combo,
displayField : 'rule_id-rule_suite',
editable : false,
triggerAction : 'all',
allQuery : 'rule_id-rule_suite',
queryParam : 'group',
name : 'filters[rule_id-rule_suite]'
}, {
fieldLabel : 'Region',
xtype : 'combo',
store : rule_combo,
displayField : 'rule_id-region',
editable : false,
triggerAction : 'all',
allQuery : 'all',
queryParam : 'group',
name : 'filters[rule_id-region]'
}, {
fieldLabel : 'Area',
xtype : 'combo',
store : rule_combo,
displayField : 'rule_id-net_area',
editable : false,
triggerAction : 'all',
allQuery : 'rule_id-net_area',
queryParam : 'group',
name : 'filters[rule_id-net_area]'
}, {
fieldLabel : 'AS',
xtype : 'combo',
store : rule_combo,
displayField : 'rule_id-net_as',
editable : false,
triggerAction : 'all',
allQuery : 'rule_id-net_as',
queryParam : 'group',
name : 'filters[rule_id-net_as]'
}, {
fieldLabel : 'Tested object',
name : 'filters[tested_object]'
}, {
fieldLabel : 'Severity',
xtype : 'combo',
store : rule_combo,
displayField : 'severity',
editable : false,
triggerAction : 'all',
allQuery : 'severity',
queryParam : 'group',
name : 'filters[severity]'
}, {
fieldLabel : 'Ticket',
name : 'filters[ticket]'
}, {
fieldLabel : 'Etr',
name : 'filters[etr]'
}, {
fieldLabel : 'Fixed',
name : 'filters[fixed]'
}, {
fieldLabel : 'Valid',
name : 'filters[valid]'
}]

The server json response varies depending on the group parameter that is sent.
Here is an example with group=severity:

{combo:[{"severity":"NOTE"},{"severity":"WARNING"}]}

KRavEN
6 Mar 2008, 9:10 AM
adding a listener focus function works except sometimes the previous combobox doesn't loose focus when you click on a different combobox. This causes multiple comboboxes to open at the same time. If you click somewhere else, causing the current combobox to loose focus, then click on a different combobox the problem doesn't happen.


listeners:{
'focus': function(){
if(this.store.collect(this.displayField).length == 0){
this.store.baseParams = {filter:1, group: this.displayField}
this.store.load();
}
}
}

Anyone have any ideas on how to resolve that?

catacaustic
6 Mar 2008, 2:50 PM
If you're doing that, it would probably be better to use the "before" event. That way it will reload every time that you show the list.

KRavEN
7 Mar 2008, 5:01 AM
beforequery works the same way. If you click the trigger on a combobox, don't select anything from the list, and then click the trigger on a different combobox then it shows multiple lists open at the same time. If you click the trigger again to close the combobox list before clicking a different trigger the problem doesn't happen.

KRavEN
7 Mar 2008, 5:10 AM
I did some investigating and blur doesn't fire when you have the combobox list open and then click on a different trigger. If you close the combobox list and then click a different trigger blur will then fire.

KRavEN
7 Mar 2008, 6:38 AM
Okay, well here's how I got it behaving correctly. I'm not sure if there is an easier way to accomplish the same thing, but it works.

'beforequery' : function() {
var items = formPanel.items.items;
for(var i=0;i<formPanel.items.length;i++){
if(items[i].id != this.id && items[i].hasFocus == true){
items[i].wrap.removeClass('x-trigger-wrap-focus');
items[i].el.removeClass('x-form-focus');
items[i].hasFocus = false;
}
}
if (this.store.collect(this.displayField).length == 0) {
this.store.baseParams = {filter: 1,group: this.displayField}
this.store.load();
}
}

Condor
7 Mar 2008, 7:50 AM
Or you could set combo.lastQuery = null instead of loading the store (will reload the store the next time it expands).