PDA

View Full Version : Dates with Json



oracio
28 May 2007, 3:34 AM
Hello,

I have a script that generates a json string from my ms sql data.
my problem is that my dates in my sql formated in a d/m/y 00:00:00 way.
and what I get is the following:


,"lastlogindate": "16\u002F05\u002F2007 16:51:32",

and this is unreadable by Ext.
I understand that i need to run something in the middle that takes the json and encodes it in the right way and then call it by the Ext.

how do I do so?

oracio
28 May 2007, 4:04 AM
my code looks like this:



function setupDataSource() {
ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'ajaxasp3.asp'}),
reader: new Ext.data.JsonReader(
{root: 'data', id: 'itemid'},
[
{name: 'itemid', mapping: 'itemid'},
{name: 'itemname', mapping: 'itemname'},
{name: 'itempath', mapping: 'itempath'},
{name: 'itemprice', mapping: 'itemprice'},
{name: 'itemwidth', mapping: 'itemwidth'},
{name: 'lastlogindate', type:'date', dateFormat:'n/j/Y h:i a'}
]
)
}
);

ds.load();
}


function getColumnModel() {
if(!columnModel) {
columnModel = new Ext.grid.ColumnModel(
[
{
header: 'Item ID',
width: 250,
sortable: true,
dataIndex: 'itemid'
},

{
header: 'Item Name',
width:100,
sortable: true,
dataIndex: 'itemname'
},
{
header: 'Item Path',
width:100,
sortable:true,
dataIndex: 'itempath'
},
{
header: 'Item Price',
width:100,
sortable: true,
dataIndex: 'itemprice'
},
{
header: 'Item Width',
width:100,
sortable:true,
dataIndex:'itemwidth'
},
{
header: 'Last Login Date',
width:100,
sortable:true,
dataIndex:'lastlogindate',
renderer: Ext.util.Format.dateRenderer('m/d/Y')
}
]
);
}
return columnModel;
}

oracio
28 May 2007, 5:21 AM
Well I was able to fix that and now my json looks like this:



,lastlogindate: '17/05/2007 22:00:00'


in the JsonReader the line looks lik this:



{name: 'lastlogindate', type:'date', dateFormat:'d/m/Y H:i:s'}


and in the columnModel:



{
header: 'Last Login Date',
width:100,
sortable:true,
dataIndex:'lastlogindate',
renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s')
}


it works great in FireFox and Opera but doesn't work in IE7, any idea how to get it working in IE7?

oracio
28 May 2007, 5:31 AM
Well again i forgot the mapping: which fixed it

sorry for the bother :">