1. #1
    Sencha Premium Member
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    330
    Vote Rating
    1
    PranKe01 is on a distinguished road

      0  

    Question [SOLVED] DateFormat from WebService in grid

    [SOLVED] DateFormat from WebService in grid


    Hi there!

    I'm trying to display a date from a WebService in a grid. The date comes in the ISO 8601 and looks like this: "2009-11-17T13:45:12.423".
    Code:
    var ds = new Ext.data.Store({
                                proxy: new Ext.data.MemoryProxy(data),
                                reader: new Ext.data.ArrayReader({id: 0}, [
                                    {name: 'id', type:'int'},
                                    ...
                                    {name: 'date', type: 'date', dateFormat: 'Y-m-dTH:i:s.u'},
                                    ...
                                    {name: 'status', type:'string'}
                                ])
                            });
    var colModel = new Ext.grid.ColumnModel([
                                ...
                                {header: "Date", width: 80, sortable: true, dataIndex: 'date'},
                                ...
                                {header: "Status", width: 80, sortable: true, dataIndex: 'status'}
                            ]);
    The date is saved as dateTime in the SQL-Database and will be transformed in the webservice to the iso-format. Now my problem is that no data is displayed in my Adobe Air application! When I use the type 'string' for the date it is shown but with the ugly ISO-format
    I also tried to change the dateFormat to: dateFormat: 'Y-m-d\\TH:i.u' and dateFormat: 'c' with no results.

    Anyone knows what went wrong?

  2. #2
    Sencha Premium Member
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    330
    Vote Rating
    1
    PranKe01 is on a distinguished road

      0  

    Default


    Does nobody got an answer or an idea? Thought this ISO norm is pretty much used?!

  3. #3
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    82
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Date.parseDate uses 'new Function' to create the Date parser function.

    Unfortunately, this is only allowed in Adobe AIR during script load, which means you have to declare all your date formats before Ext.onReady, e.g.
    Code:
    Date.createParser('c');
    Ext.onReady(...);
    (I would recommend using the 'c' date format instead of 'Y-m-d\\TH:i.u')

  4. #4
    Sencha Premium Member
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    330
    Vote Rating
    1
    PranKe01 is on a distinguished road

      0  

    Default


    Ah - thanks =) I already seen it anywehere but when I tried it it doesn't work. Maybe because I changed something else?
    Anyway - now the date will be shown but in a very long format. When trying to change it with:
    Code:
    {header: "Posteingang", width: 100, /*xtype: 'datecolumn',*/ sortable: true, dataIndex: 'anzahlneuernachrichten', renderer: Ext.util.Format.dateRenderer('d/m/Y')/*format: 'd/m/Y'*/}
    it does not change the output Searching for whats going wrong I found a thread where stood that I have to add the following line before the onReady func:
    Code:
    Date.createNewFormat('d/m/Y');
    But that gave me an error: "TypeError: Result of expression 'Date.createNewFormat' [undefined] is not a function."
    When using
    Code:
    Date.createFormat('d/m/Y');
    there is no error but again there is no change to the dateresult

  5. #5
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    82
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    No, it's:
    Code:
    Date.createParser('d/m/Y');

  6. #6
    Sencha Premium Member
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    330
    Vote Rating
    1
    PranKe01 is on a distinguished road

      0  

    Default


    That didn't work for me in Adobe Air. But I found the solution here: http://www.extjs.com/forum/showthread.php?t=74310
    You must add
    Code:
    Date.precompileFormats("d/m/Y");
    before the onReady func

    In Adobe Air it should finally look like:
    Code:
    Date.createParser('c');
    Date.precompileFormats("d.m.Y");
    
    Ext.onReady(function(){...}

Thread Participants: 1