PDA

View Full Version : Grid Date Filter Question



ragecf
26 Dec 2012, 11:57 PM
When I select a date in grid date filter, the "before" or "after" checkbox can not be selected automatically. But this function was OK in Ext 3.4.

I checked code for DateFilter.js



init : function (config) {
var me = this,
pickerCfg, i, len, item, cfg;

pickerCfg = Ext.apply(me.pickerOpts, {
xtype: 'datepicker',
minDate: me.minDate,
maxDate: me.maxDate,
format: me.dateFormat,
listeners: {
scope: me,
select: me.onMenuSelect //This function is I wanted but overrided by onPickerSelect
}
});

me.fields = {};
for (i = 0, len = me.menuItems.length; i < len; i++) {
item = me.menuItems[i];
if (item !== '-') {
cfg = {
itemId: 'range-' + item,
text: me[item + 'Text'],
menu: Ext.create('Ext.menu.Menu', {
items: [
Ext.apply(pickerCfg, {
itemId: item,
listeners: {
select: me.onPickerSelect, // Override here
scope: me
}
}),
]
}),
listeners: {
scope: me,
checkchange: me.onCheckChange
}
};
item = me.fields[item] = Ext.create('Ext.menu.CheckItem', cfg);
}



Why to do this modification in Ext4, any concern?


I modified this in my code:




init : function (config) {
var me = this,
pickerCfg, i, len, item, cfg;

pickerCfg = Ext.apply(me.pickerOpts, {
xtype: 'datepicker',
minDate: me.minDate,
maxDate: me.maxDate,
format: me.dateFormat,
listeners: {
select: me.onPickerSelect, //changed to onPickerSelect
scope: me
}
});

me.fields = {};
for (i = 0, len = me.menuItems.length; i < len; i++) {
item = me.menuItems[i];
if (item !== '-') {
cfg = {
itemId: 'range-' + item,
text: me[item + 'Text'],
menu: Ext.create('Ext.menu.Menu', {
items: [
Ext.apply(pickerCfg, {
itemId: item

//listeners: {
// select: me.onPickerSelect, //marked override
// scope: me
//}

})
]
}),

................

// mixed onMenuSelect to onPickerSelect

onPickerSelect : function (picker, date) {
var fields = this.fields,
field = this.fields[picker.itemId];

field.setChecked(true);

if (field == fields.on) {
fields.before.setChecked(false, true);
fields.after.setChecked(false, true);
} else {
fields.on.setChecked(false, true);
if (field == fields.after && this.getFieldValue('before') < date) {
fields.before.setChecked(false, true);
} else if (field == fields.before && this.getFieldValue('after') > date) {
fields.after.setChecked(false, true);
}
}

this.values[picker.itemId] = date;

this.fireEvent('update', this);

picker.up('menu').hide();
},




Did I do it correctly? It works fine currently.

Is there any potential problem?

Thanks.

ChadB
11 Jun 2014, 8:18 AM
This solution worked for me as well. Thanks.