PDA

View Full Version : DateTimeFilter grid filter



otatop
23 Oct 2008, 12:15 PM
Here's a grid filter for use with the grid filter example code on the ext examples. This one is like the date filter but also provides a time picker. To use it set the filter datatype as dateTime. (note, we use locale objects so you'll have to create your own strings for that)

(this must be used with the DateTimeMenu from http://extjs.com/forum/showthread.php?p=242498)


Ext.namespace("Ext.grid.filter");


Ext.grid.filter.DateTimeFilter = Ext.extend(Ext.grid.filter.DateFilter, {
beforeText: commonLocale.before,
afterText: commonLocale.after,
onText: commonLocale.on,
init: function() {
var opts = Ext.apply(this.pickerOpts, {
minDate: this.minDate,
maxDate: this.maxDate,
format: this.dateFormat
});
var dates = this.dates = {
'before': new Ext.menu.CheckItem({text: this.beforeText, menu: new Ext.ux.menu.DateTimeMenu(opts)}),
'after': new Ext.menu.CheckItem({text: this.afterText, menu: new Ext.ux.menu.DateTimeMenu(opts)}),
'on': new Ext.menu.CheckItem({text: this.onText, menu: new Ext.menu.DateMenu(opts)})
};

this.menu.add(dates.before, dates.after, "-", dates.on);

for(var key in dates) {
var date = dates[key];
date.menu.on('select', this.onSelect.createDelegate(this, [date]), this);

date.on('checkchange', function(){
this.setActive(this.isActivatable());
}, this);
};
},

getFieldValue: function(field) {
var fieldValue = this.dates[field].menu.picker.activeDate.format(this.dateFormat);
if (this.dates[field].menu.timefield) {
fieldValue += " " + this.dates[field].menu.timefield.getValue();
}
return fieldValue;
},

serialize: function() {
var args = [];
if(this.dates.before.checked) {
args = [{type: 'date', comparison: 'lt', value: this.getFieldValue('before')}];
}
if(this.dates.after.checked) {
args.push({type: 'date', comparison: 'gt', value: this.getFieldValue('after')});
}
if(this.dates.on.checked) {
args = {type: 'date', comparison: 'eq', value: this.getFieldValue('on')};
}

this.fireEvent('serialize', args, this);
return args;
}

});

mjlecomte
23 Oct 2008, 2:04 PM
Said filter class and subclasses are in the ux repo in my signature. Feel free to add your filter and it would be combined with the others in the main ux trunk. ;)

elDub
12 Mar 2009, 10:25 AM
Said filter class and subclasses are in the ux repo in my signature. Feel free to add your filter and it would be combined with the others in the main ux trunk. ;)

I cannot seem to get this to work properly even when placed in the Ext.ux namespace, and I am not finding these libraries within the Ext.ux library that your sig references. Is there a working version of this or has it been pulled?

sytel
26 Nov 2009, 3:32 AM
Any chance to have this ported to Ext 3?

otatop
27 Nov 2009, 11:05 AM
Haven't had to yet. Probably will be a little while till I do but that depends on if it's still a part of our requirements after we upgrade. Feel free to make any necessary updates and post it.