PDA

View Full Version : Weird dateformat behavior



carze
22 Mar 2011, 12:21 PM
Hey all, hope I can get some answers as to why I am getting some weird behavior when displaying a date in a GridPanel. My Ext code is below:


var arc3Store = new Ext.data.JsonStore({
autoDestroy: true,
autoLoad: false,
reader: new Ext.data.JsonReader(),
proxy: new Ext.data.HttpProxy({
url: cgibinDir + '/execute_query.pl',
method: 'GET'
}),
listeners: {
exception: function(proxy, type, action, options, res, arg) {
Ext.Msg.show({
title: 'Load Error',
msg: 'Error loading results from the database. Please contact the site administor.',
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
});

var arc3Grid = new Ext.grid.GridPanel({
plugins: [
{ptype: 'ux-grid-metagrid'}
],
id: 'arc3Grid',
title: 'Results',
store: arc3Store,
disabled: true,
border: true,
trackMouseOver: false,
disableSelection: true,
loadMask: true,
stripeRows: true,
viewConfig: {
forceFit: true,
}
}
I am using the metagrid plugin to receive the column layout from the server side and am setting the render on the column to 'Y-m-d' and the type to 'date.' So far so good, but when the page loads up and I receive everything from the server it seems that the dates displaying the grid are off by one. An example of (removed a lot of extraneous data here) the JSON I am receiving is below:


{
"metaData": {
"totalProperty": "total",
"fields": [
{
"mapping": "patient_id",
"align": "center",
"name": "patient_id",
"type": "string",
"sortable": "true",
"header": "Subject ID"
},
{
"mapping": "age",
"align": "center",
"name": "age",
"type": "int",
"sortable": "true",
"header": "Age"
},
{
"mapping": "gender",
"align": "center",
"name": "gender",
"type": "string",
"sortable": "true",
"header": "Gender"
},
{
"mapping": "geolocation",
"align": "center",
"name": "geolocation",
"type": "string",
"sortable": "true",
"header": "Location"
},

"mapping": "treatment_outcome",
"align": "center",
"name": "treatment_outcome",
"type": "string",
"sortable": "true",
"header": "Treatment outcome"
},
{
"mapping": "collection_date",
"align": "center",
"name": "collection_date",
"type": "date",
"sortable": "true",
"header": "Sample collection date",
"renderer": "Ext.util.Format.dateRenderer('Y-m-d')"
}
],
"idProperty": "id",
"successProperty": "success",
"root": "results"
},
"id": "arc_db_query",
"total": "8079",
"results": [
{
"fk_study_arm": "4",
"chrom": "4",
"age": "25",
"geolocation": "Pailin",
"collection_date": "2008-06-02",
},

Looking at the store in firebug the dates are being stored correctly ("2008-06-02") but when the GridPanel is loaded up for some reason the dates are displaying as "2008-06-01." Pretty sure I am doing something stupid here so any help would be appreciated.

Thanks!

hpet
23 Mar 2011, 12:44 AM
Try using 'Y-m-d' in your date renderer.

carze
23 Mar 2011, 3:04 AM
Ah I guess that was a typo from when I was playing around with different dateRenderer formats. Setting the dateRenderer to 'Y-m-d' still exhibits the same behavior.

carze
23 Mar 2011, 6:08 AM
Solved the issue. Turns out I was being stupid and wasn't passing back a dateFormat that my JSON reader could use to parse the date. Adding one allows for the correct date to be displayed.