[CLOSED] How do you format the date value in a DateColumn that is submitted back the server for update

  1. #1

    [CLOSED] How do you format the date value in a DateColumn that is submitted back the server for update

    Hi,

    In your example here:
    https://examples1.ext.net/#/GridPane..._DirectMethod/

    You show how a date column can be formatted for display (using yyyy-MM-dd on the DateColumn).

    But when it is submitted back to the server, your notification box (and the HTTP post back) shows the value actually being sent back is something like "2011-11-01T00:00:00" (i.e. the date that is picked but with the time bit set to zero).

    Is there a way to format the date value when it is sent to the server (in my particular case I don't want anything after "T")?

    Thanks!
    Last edited by Daniil; Nov 01, 2011 at 5:56 PM. Reason: [CLOSED]
  2. #2
    Such format is produced by Ext.encode method, it is standard JSON format for the date
    That method internally uses Ext.util.JSON.encodeDate method

    encodeDate( Date d ) : String
    Encodes a Date. This returns the actual string which is inserted into the JSON string as the literal expression. The returned value includes enclosing double quotation marks.
    The default return format is "yyyy-mm-ddThh:mm:ss".
    To override this:

    Ext.util.JSON.encodeDate = function(d) { return d.format('"Y-m-d"');};Parameters

    • d : DateThe Date to encode

    Returns

    • StringThe string literal to use in a JSON string.


  3. #3
    Thanks for such a quick response -- yet again :)

    And thanks for that pointer... given that is the standard format for JSON serialized dates, I'll keep it as is (we handle it on the server anyway, was just hoping to optimize at the UI layer).

    You can mark as closed/solved etc.
  4. #4
    Btw, just as a minor point, looks like JSON specs don't actually define something for dates:

    http://www.json.org/
    - Values are defined as string, numbers, object, array, true, false, null
    - no date representation

    Wikipedia (yes, with a pinch of salt) points to a few agreed things but server and client must agree
    http://en.wikipedia.org/wiki/JSON

    For us we have a separate notion of Date and DateTime so we will deal with that ourselves -- it just means overriding encodeDate for us is not really an option - so we will have to deal with this on the server which is a good thing to get right anyway :)

Similar Threads

  1. Ext.Net.DateColumn Format issue
    By lmueller in forum 1.x Help
    Replies: 4
    Last Post: Sep 17, 2018, 4:05 AM
  2. Replies: 1
    Last Post: Nov 29, 2011, 5:11 PM
  3. [CLOSED] Date Format in DateColumn Elements
    By ljcorreia in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 28, 2011, 8:12 AM
  4. Replies: 0
    Last Post: Feb 20, 2011, 6:29 PM
  5. [CLOSED] DateColumn, Format
    By jeybonnet in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 03, 2010, 1:57 PM

Posting Permissions