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;
}
});
(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;
}
});