Monday, April 7, 2014

Change current month event in Ext.picker.Date

There is no change event month in object 'Ext.picker.Date' in Ext JS 4.
Here is an implementation that allows you to add this event by extending class 'Ext.picker.Date':
Ext.define("YourCalendarPicker", {
    extend: "Ext.picker.Date",
    ...
    update : function(date, forceRefresh){
        var me = this,
            monthViewChange = me.isAnotherMonthView(date);
        me.callParent(arguments);
        if (monthViewChange){
            me.fireEvent("monthviewchange", me, date, me.activeDate);
        }
        return me;
    },
    ...

    /**
     * return true if the given date is in a different month view of the actual calendar date
     * @param {Date} date
     * @return {Boolean}
     */
    isAnotherMonthView: function(date){
        var activeDate = this.activeDate || date;
        return date.getYear() != activeDate.getYear() || 
               date.getMonth() != activeDate.getMonth();
    }
};

No comments: