PDA

View Full Version : how to render datetime in a particular format in extjs 3.4



Vamshi Barana
1 Oct 2013, 1:54 AM
Hi,
I need to display to datetime in date format inorder to do sorting.Below is mt columnModel to dispaly it.



header : 'DateTime(dd:mm:yy)</b>',
dataIndex : 'time',
renderer: Ext.util.Format.dateRenderer('m-d-Y H:i:s')

and in store I have given the type :'date' and format:'m-d-Y H:i:s'. But its not displaying anything.Please do help me in this.

Thanks,
Vamshi

raj_plays
1 Oct 2013, 9:36 AM
This works for me...
In store


{name: 'start_date', type: 'date', dateFormat: 'Y-m-d\TH:i:sP'}


In Column model


{header: "Start Date", width: 90, dataIndex: 'start_date', renderer: Ext.util.Format.dateRenderer('Y-m-d')}

Vamshi Barana
2 Oct 2013, 8:27 PM
Hi Raj,

It hav'nt worked for me.In my case sorting is not working properly..


Regards,
Vamshi

raj_plays
3 Oct 2013, 12:54 AM
Does your column config have sortable: true?
If so, check the date format returned from your server.
That should be the same as the dateFormat in store.

Vamshi Barana
3 Oct 2013, 1:20 AM
Hi Raj,


Thanks alot ...Its fixed :):):)


Thanks,
Vamshi

willigogs
3 Oct 2013, 1:24 AM
It sounds like the date format being returned from the server does not match what you are stating it is inside your store's field.

So for example, the below expects the format returned from the server to be "2013-01-02 12:34:56".


var fields = [
{name:'datetime', mapping:'datetime', type:'date', dateFormat:'Y-m-d H:i:s'}
];

var store = new Ext.data.JsonStore({
// USUAL CONFIG HERE
fields: fields
});


If your returned format differs from that stated in your store, then it will fail, and display blank values if you try and apply different date rendering in your grid column.

Vamshi Barana
3 Oct 2013, 1:44 AM
Hi willigogs,

You are right...

This is the field in store ,
{ name : 'time',mapping : 'time',type: 'date',dateFormat: 'd-m-Y H:i:s'}

&
Here is the columnModel
{header: "Time", width: 90, dataIndex: 'time',format:'d-m-Y H:i:s', xtype: 'datecolumn',
renderer : function(val, meta, record) {return '<div align="center">' + val + '</div>';} }


This works well. Format Should be specified same everywhere.




Thanks,
Vamshi