PDA

View Full Version : Format a date in an groupingfeature



SebastianZ
25 Jun 2014, 3:48 AM
Hi,

i hope you guys can help me.

I'm searching for a possibility to show a date formated in an grouping-header of an grid.

https://fiddle.sencha.com/fiddle/70s

(https://fiddle.sencha.com/fiddle/70s)If you group the "Date" - Field in this fiddle, you can see the unformated date - value.

Is there a way to show that header in a format like "d.m.Y".

Best regards,
Sebastian

Gary Schlosberg
5 Jul 2014, 9:56 AM
Duplicate, response and user solution posted on this thread.
http://www.sencha.com/forum/showthread.php?287915

SebastianZ
6 Jul 2014, 10:17 PM
Here is where i found my solution:

http://docs.sencha.com/extjs/4.2.1/#...groupHeaderTpl (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.grid.feature.Grouping-cfg-groupHeaderTpl)
You could similarly format your date that way.

Here is how i solve my problem:



groupHeaderTpl: Ext.create('Ext.XTemplate', '{columnName}: {name:this.formatName}'
{ formatName: function(name) {
function isValidDate(value)
{
var dateWrapper = new Date(value);
return (typeof value == 'object')&&(!isNaN(dateWrapper.getDate()));
}

if (isValidDate(name)){ return Ext.Date.format(name, 'd.m.Y');}
else return name.toLocaleString();
}
}