PDA

View Full Version : date format in a grid 4.1



Anthony.Hall
14 May 2012, 6:49 AM
I'm getting inconstant results with my dates. Sometime they are getting converted to us format.

I have the following json

"Created":"09/03/12"

In my grid i have


{ id: 'Created',
text: "Created",
dataIndex: 'Created',
xtype: 'datecolumn',
format: 'd/m/y',
width: 150,
sortable: true,
field: {
xtype: 'datefield',
allowBlank: false,
format: 'd/m/y'
}
},

So i want to display

09/03/12 ( 9th March )
but i'm getting 03/09/12

sword-it
15 May 2012, 2:57 AM
Hi
Try to use following code you will get date as per your needs.



Ext.onReady(function () {
win = new Ext.Window({
title: 'My First Window'
, width: 300
, height: 300
, layout: 'form'
, items: [
{
xtype: 'datefield'
, fieldLabel: 'Current Date'
, labelWidth: 100
, value: '09/03/2012'
, format: 'd/m/Y'
},
{
xtype: 'grid'
, title: 'My First Grid'
, store: new Ext.data.ArrayStore({
data: [
['testing', '09/03/2012']
]
, fields: [{ name: 'name' }
, {name:'date' , type: 'date', dateFormat: 'd/m/Y'}
]
})
, columns: [
{
header: 'Name'
, dataIndex: 'name'
, field: {
xtype: 'textfield'
}
},
{
header: 'Date'
, dataIndex: 'date'
, xtype: 'datecolumn'
, format: 'd/m/Y'
, field: {
xtype: 'datefield'
, allowBlank: false
, format: 'd/m/Y'
}
}
]
, selType: 'rowmodel'
, plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1
})
]
}
]

})
win.show();
})

mjhaston
8 Feb 2013, 6:56 AM
Is it me? I define a date as 'm/d/Y' everywhere possible and still it displays the complete date and submits in complete date format as well. See attachment.

I'm going CRAZY with this and it's going to be something simple!


JSON:


"mbrdob" : "09/17/1964"




Defined in model for store:


}, {
name : 'mbrdob',
type : 'date',
dateFormat : 'm/d/Y'
}, {




Defined in grid. Just added the extra "field" code. Doesn't work without it either:


}, {
text : 'mbrdob',
dataIndex : 'mbrdob',
allowBlank : false,
xtype : 'datecolumn',
field : {
xtype : 'datefield',
allowBlank : false,
format : 'd/m/Y'
},
renderer : function(value, metaData, record) {
if (record.data.e10 !== "") {
metaData.tdAttr = 'data-qtip="' + record.data.e10 + '"';
metaData.style = 'color:#D10000;font-weight:bold;background:#F7E4E4;'
return value;
} else {
return value;
}
},
editor : {
xtype : 'datefield',
editable : false
}
}, {

mankz
8 Feb 2013, 7:21 AM
renderer : function(value, metaData, record) {
if (record.data.e10 !== "") {
metaData.tdAttr = 'data-qtip="' + record.data.e10 + '"';
metaData.style = 'color:#D10000;font-weight:bold;background:#F7E4E4;'
return value;
} else {
return value;
}
},

Renderers have no effect on a 'DateColumn', instead you should set the 'format' config.

mjhaston
8 Feb 2013, 7:29 AM
Had that code before the last change. Put it back in with no effect. Is that where you were talking about?



text : 'mbrdob',
dataIndex : 'mbrdob',
allowBlank : false,
xtype : 'datecolumn',
format : 'd/m/Y',



The renderer is just setup to show errors. See attached.

mankz
8 Feb 2013, 7:31 AM
Can you post your full grid, store, model code?

mjhaston
8 Feb 2013, 7:33 AM
Okay, interesting, removed the renderer and the date displays correctly. Still submits the full complete date, but I figure that's a submitFormat I need somewhere.

Problem is ... I need that renderer on the field. I need to highlight errors and give the tooltip.

Do I need to look at renderData?

mankz
8 Feb 2013, 7:36 AM
Then you should use a plain Ext Column, DateColumn doesn't offer anything for you :)

mjhaston
8 Feb 2013, 7:39 AM
Thank you.