PDA

View Full Version : dateFormat error, function not found?



benny
30 Apr 2007, 3:17 AM
Hi,

I have a feeling this is a dumb question with an easy answer, I just cannot see it right now.

While using a grid, I'm trying to apply a date format with a renderer (as per the paging example).

For example:


var cm = new Ext.grid.ColumnModel([
// some other rows
{header: "TimeDate", width: 120, dataIndex: 'timestamp', type: 'date', renderer: renderDate}
]);

// the renderer
function renderDate(value){
return String.format(value.dateFormat('M j, Y, g:i a'));
}
// also used this one with no luck
function renderDate(value){
return value.dateFormat('M j, Y, g:i a');
}


Firebug Error:


value.dateFormat is not a function
[Break on this error] return String.format(value.dateFormat('M j, Y, g:i a'));


Not sure what is happening, can any one help?

dfenwick
30 Apr 2007, 5:20 AM
Hi,

I have a feeling this is a dumb question with an easy answer, I just cannot see it right now.

While using a grid, I'm trying to apply a date format with a renderer (as per the paging example).

For example:


var cm = new Ext.grid.ColumnModel([
// some other rows
{header: "TimeDate", width: 120, dataIndex: 'timestamp', type: 'date', renderer: renderDate}
]);

// the renderer
function renderDate(value){
return String.format(value.dateFormat('M j, Y, g:i a'));
}
// also used this one with no luck
function renderDate(value){
return value.dateFormat('M j, Y, g:i a');
}


Firebug Error:


Not sure what is happening, can any one help?

Are you sure you're not calling that renderer from another data element as well? Or perhaps you're getting a date back that's not a valid date?

sfwalter
30 Apr 2007, 6:02 AM
Are you sure the value is a Date object? It might help if you post the creation of the datastore so that we can see your reader configuration.

scott.

benny
30 Apr 2007, 6:14 AM
Are you sure you're not calling that renderer from another data element as well? Or perhaps you're getting a date back that's not a valid date?

No, I just created the renderer - so it is only called once. The date format is coming through valid (2007-01-21 12:03:23).
Thanks

benny
30 Apr 2007, 6:16 AM
Are you sure the value is a Date object? It might help if you post the creation of the datastore so that we can see your reader configuration.

scott.

Hmm, you may be correct, I do have a bit ob confusion of where to declare the field as data (in dataStore or in columnModel).... here is the data store:



var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'get_json.php'}),
reader: new Ext.data.JsonReader({
root:"records",
totalProperty: 'totalCount',
id:"id"
}, ['id','version','report_number','timestamp','store_name','store_number','icc']

)
});


Many Thanks

sfwalter
30 Apr 2007, 7:06 AM
I believe in your reader for your column that you want to treat as a Date data type. You need to identify it as date type as well as the format of the incoming date text.

For example:

{name: 'duedate', type:'date', dateFormat:'n/j/Y h: i a'}

benny
30 Apr 2007, 7:23 AM
thanks sfwalter, that makes sense. Do you have any idea what the date format mask is for timestamp? (2007-04-30 16:22:34 - for example) I can not find any reference to this is the API docs.

tryanDLS
30 Apr 2007, 7:42 AM
Look at the docs for the Date class (http://extjs.com/deploy/ext/docs/output/Date.html)- there are a some examples there and also a link to the PHP site on which the formats are based - I think there are more examples there.

benny
30 Apr 2007, 8:03 AM
Fantastic, many thanks guys. It now works :)
For reference, the timestamp dateformat is:
'Y-m-d H:i:s'

hallikpapa
24 Feb 2008, 1:58 PM
I am having this exact same problem. What am I staring at that I am missing?



function renderDate(value){
return value.dateFormat('Y-m-d H:i:s');
};


my error in firebug:

value.dateFormat is not a function
renderDate("2008-01-08 00:49:38")

My datetime stamp is the same as benny's, so I am obviously missing something stupid.

I mean if I comment out the renderer, It displays data fine. Just trying to understand the grid-php example completely and why it isn't working for me.



},{
dataIndex: 'FirstCall',
header: "First Call",
//renderer: renderDate,
sortable: true,
width: 20
},{
dataIndex: 'LastCall',
header: "LastCall",
//renderer: renderDate,
sortable: true,
width: 20
},