1. #1
    Sencha User harman's Avatar
    Join Date
    Jul 2011
    Location
    India
    Posts
    138
    Vote Rating
    3
    Answers
    2
    harman is on a distinguished road

      0  

    Default Answered: String Date to ExtJS Date Formatted

    Hi,

    I have a Date field that comes to me as a String in JSON like
    Code:
    "09-05-2012 7:33 AM"
    I have to show it as a Date with the same format in my Grid column.
    (I am converting it to date as grid column does not sort it as Date but String)
    How do i do it?
    If i do this in my model
    Code:
    {name: 'someDate', type: 'String', convert:function(value, records){                 var rcptDate=new Date(value);
                     return Ext.Date.format(rcptDate, 'm-d-Y g:i A');
                 }}
    i get value like NaN-NaN-0NaN 12:NaN PM

    What am i doing wrong?
    Or is it that it cant be converted?

  2. You can define the field in the store as follows:

    Code:
    {
        name: 'someDate',
        type: 'date',
        dateFormat: 'm-d-Y g:i A'
    }
    and then put the following renderer on your grid column:

    Code:
    renderer: Ext.util.Format.dateRenderer('m-d-Y g:i A')

  3. #2
    Touch Premium Member
    Join Date
    Feb 2011
    Location
    NJ
    Posts
    314
    Vote Rating
    55
    Answers
    59
    droessner is a jewel in the rough droessner is a jewel in the rough droessner is a jewel in the rough droessner is a jewel in the rough

      0  

    Default

    You can define the field in the store as follows:

    Code:
    {
        name: 'someDate',
        type: 'date',
        dateFormat: 'm-d-Y g:i A'
    }
    and then put the following renderer on your grid column:

    Code:
    renderer: Ext.util.Format.dateRenderer('m-d-Y g:i A')

  4. #3
    Sencha User Tim Toady's Avatar
    Join Date
    Feb 2010
    Location
    Pennsylvania
    Posts
    582
    Vote Rating
    268
    Answers
    62
    Tim Toady has much to be proud of Tim Toady has much to be proud of Tim Toady has much to be proud of Tim Toady has much to be proud of Tim Toady has much to be proud of Tim Toady has much to be proud of Tim Toady has much to be proud of Tim Toady has much to be proud of

      0  

    Default

    I would also use the date type for the field as droessner stated, but I would be slightly more lazy and use the datecolumn

  5. #4
    Sencha User harman's Avatar
    Join Date
    Jul 2011
    Location
    India
    Posts
    138
    Vote Rating
    3
    Answers
    2
    harman is on a distinguished road

      0  

    Default

    Thanks droessner,

    Exactly what i wanted.
    However i will need a little more testing to see if the Sorting works correctly.

Thread Participants: 2

Tags for this Thread