PDA

View Full Version : Linked combos in grid



mdavis6890
17 Jan 2011, 5:24 PM
I've been struggling to figure out how to get this done properly. I really just want the obvious linked combos in a grid.

Please see this thread, which was pretty helpful:
http://www.sencha.com/forum/showthread.php?90395-3.1.0-Filtering-a-grid-editor-combo-box-before-edit&p=430603

So now I've got:

SelectBox:

IDB.selectbox.SelectBox = Ext.extend(Ext.ux.form.SelectBox, {
clearFilterOnReset:false,
});
Ext.reg('IDB.selectbox.SelectBox', IDB.selectbox.SelectBox);
IDB.selectbox.Site = Ext.extend(IDB.selectbox.SelectBox, {
mode : 'remote',
fieldLabel: 'Site',
name: 'site_code',
store: Ext.StoreMgr.get('storeSites'),
valueField: 'site_code',
displayField: 'site_code',
initComponent : function() {
IDB.selectbox.Site.superclass.initComponent.call(this);
}
});
Ext.reg('IDB.selectbox.Site', IDB.selectbox.Site);

Snippet from my grid/form container object initComponent:

this.getGridPanel().on('beforeedit', function(e) {
Ext.StoreMgr.get('storeSites').filter('site_code', 'LAX010');
});

Problem: The first time I click a selectbox to edit, I see the unfiltered list. Any subsequent edits show the filtered version.

Any ideas?

Thanks,
Michael

Condor
18 Jan 2011, 12:45 AM
Configure the ComboBox (or SelectBox) with:

triggerAction: 'all',
lastQuery: ''
(otherwise it will clear the existing filter)

mdavis6890
18 Jan 2011, 8:28 AM
I'll give that a shot right now. Since it was already working after the first click, if these parameters help I won't know why.

mdavis6890
18 Jan 2011, 8:31 AM
Well I guess I shouldn't be surprised - it works fine now.

Can you give me ten words on why it didn't work before, and what this changed?

Condor
18 Jan 2011, 8:37 AM
Not in ten words...

A mode:'local' ComboBox uses filtering to filter the store when something is typed.
You can disable this by setting triggerAction:'all', but that still makes the store clear the filter the first time it is used.
By specifying lastQuery:'' you make the ComboBox believe it already cleared the filter (it checks to see if it needs to filter by comparing the current value with lastQuery - and in case of triggerAction:'all' the current value is set to allQuery - which is '' by default).

mdavis6890
18 Jan 2011, 8:43 AM
That still doesn't explain why it would filter properly after the second click. There's a piece of the puzzle I feel I'm missing.

Condor
18 Jan 2011, 11:44 PM
Your filter action happens before the combobox is shown, so assume the store is properly filtered when you click the trigger.
SelectBox already uses triggerAction:'all', so the first time you click on the trigger if will check if the current query (= allQuery = '') is equal to lastQuery (= undefined). It isn't so it clears the filter and stores the current query in lastQuery.
The next time you press on the trigger is checks the current query (= allQuery = '') is equal to lastQuery (= ''). It is, so it doesn't clear the filter.