PDA

View Full Version : Extjs 4.1.1: Grid filter does not work for custom DATE type



ruishi
10 Oct 2013, 12:10 PM
I created a new date type called 'date_ymd', here is the code:

Ext.data.Types.DATE_YMD = {
convert: function(value) {
if(value) {
value = removeMillisecondsBecauseIECroaksOnThem(value);
date = getJsDateWithoutTzConversion(value);
if(date != 'Invalid Date'){
value = Ext.Date.format(date, 'Y-m-d');
}
}
return value;


function getJsDateWithoutTzConversion(value){
value = value.replace('-', '/');
return new Date(Date.parse(value));
}


function removeMillisecondsBecauseIECroaksOnThem(value) {
return value.replace(/\.[0-9]{3}\b/, ''); // would replace the .123 in 2012-05-05 12:01:02.123 GMT
}
},
type: 'date_ymd'
};


So that, in grid date type value, such as 'Thu May 20 2013 00:00:00 GMT-0500 (Central Daylight Time)', can be displayed as '2013-05-20'.

The problem is when I tried to add a filter to it using FilterFeature.js, an error of 'Uncaught TypeError: object is not a function' occurred. For the filter I used the following code:

var filters = {
ftype: 'filters',
local: true,
filters: [{
type: 'date_ymd',
dataIndex: 'something'
}]
};


I think it was because it couldn't recognize 'date_ymd', since if I change it to 'date' the filter works but the format is not what I want.

Can anyone help me? Thanks in advance.

eric.cook
10 Oct 2013, 12:35 PM
I think you're looking for the dateFormat (http://docs.sencha.com/extjs/4.1.1/#!/api/Ext.ux.grid.filter.DateFilter-cfg-dateFormat) config. As you've probably realized, the "type" config is the type of the filter, not the type of the field.

If that doesn't work, you may need to extend the DateFilter class to better suit your needs.



filters: [{
type: 'date',
dateFormat: 'Y-m-d',
dataIndex: 'something'
}];

ruishi
10 Oct 2013, 1:00 PM
Thanks for your reply. I have already tried this. It makes no change. Yes, the "type" is for the filter, so the "type" for the filter is "date", while for the field it is "date_ymd". I think this is the reason that the filter returns nothing no matter I choose "before", "after" or "on". Any thoughts?


I think you're looking for the dateFormat (http://docs.sencha.com/extjs/4.1.1/#!/api/Ext.ux.grid.filter.DateFilter-cfg-dateFormat) config. As you've probably realized, the "type" config is the type of the filter, not the type of the field.

If that doesn't work, you may need to extend the DateFilter class to better suit your needs.



filters: [{
type: 'date',
dateFormat: 'Y-m-d',
dataIndex: 'something'
}];

ruishi
10 Oct 2013, 1:02 PM
Yeah, I probably I need to modify the DateFilter class..


I think you're looking for the dateFormat (http://docs.sencha.com/extjs/4.1.1/#!/api/Ext.ux.grid.filter.DateFilter-cfg-dateFormat) config. As you've probably realized, the "type" config is the type of the filter, not the type of the field.

If that doesn't work, you may need to extend the DateFilter class to better suit your needs.



filters: [{
type: 'date',
dateFormat: 'Y-m-d',
dataIndex: 'something'
}];

ruishi
15 Oct 2015, 5:55 AM
Ext 6 will fix this. This can be closed now.

qloz
6 Jan 2016, 11:11 AM
The dateFormat string has no affect on the filter query being sent.