0
votes

I have a combobox in ExtJS 4 that has two listeners assigned to it. One is on afterrender, to select a default value. (The combobox lists months, the default grid has data for the current month, I want the combobox to show this month.) The other is on select, which goes and gets the report based on the selected month. Since the report gets preloaded, I don't want it to activate on the prepopulation of the combo box, only on subsequent uses of the combobox (ie, human interaction).

This is how I have the listeners set up:

init: function init() {
    this.control({
        '[xtype=monthcombo]': {
            afterrender: this.onMonthComboAfterRenderDo,
            select: this.onMonthComboSelectDo
        }
    })
}

And this is the prepop afterrender function:

onMonthComboAfterRenderDo: function(monthcombobox) {
    monthcombobox.suspendEvents(false); // Don't fire the select event
    var date = new Date(),
        thisMonth = Ext.Date.add(date, Ext.Date.MONTH,0);
    thisMonth = Ext.Date.format(thisMonth,'Ym');
    monthcombobox.calculateMonths(23,0);
    monthcombobox.setValue(thisMonth);
    monthcombobox.resumeEvents();
}

Oh, I did try suppressing the firing of events as you can see, but those calls don't seem to actually do anything. Finally, this is the function called when an item is selected.

onMonthComboSelectDo: function(monthcombobox) {
    console.debug('Month selected');
    var monthcode = monthcombobox.getValue();
    var grid = Ext.ComponentQuery.query('shipmentsvsgrid')[0];
    grid.store.getProxy().setExtraParam('monthID', monthcode);
    grid.store.load();
}
3
As far as I can remember it's the monthcombobox.setValue(thisMonth); that fires the event somehow. Check in the API doc if you can set the initial value another way that doesn't fire the event or use a flag that would be checked elsewhere.Nick.T

3 Answers

0
votes

Have you tried using the setRawValue method?

0
votes

A clean alternative would also be to set the value when the reports preload is finished. On control initialisation you can set the emptyText to the value you want and that won't fire anything.

0
votes
onMonthComboAfterRenderDo: function(monthcombobox) {
    monthcombobox.initialSet = true;
    var date = new Date(),
        thisMonth = Ext.Date.add(date, Ext.Date.MONTH,0);
    thisMonth = Ext.Date.format(thisMonth,'Ym');
    monthcombobox.calculateMonths(23,0);
    monthcombobox.setValue(thisMonth);
}

onMonthComboSelectDo: function(monthcombobox) {
    if(monthcombobox.initialSet) {
        monthcombobox.initialSet = false;
        return false;
    }
    var monthcode = monthcombobox.getValue();
    var grid = Ext.ComponentQuery.query('shipmentsvsgrid')[0];
    grid.store.getProxy().setExtraParam('monthID', monthcode);
    grid.store.load();
}