[CLOSED] Date Field - MVC/JSON

  1. #1

    [CLOSED] Date Field - MVC/JSON

    I have a date field in JSON coming back to a grid panel. The data in JSON is returning in this manner:
        [Object { RequestID=100000004, TaskName="Prepare Document", TaskDueDate="/Date(1334691950203)/", more...}, Object { RequestID=100000004, TaskName="Notify broker that document is ready", TaskDueDate="/Date(1334692008327)/", more...},

    When the data binds with the grid, the date is being displayed is:
    /Date(1335374549773)/
    However, I have the field datatype set to "Date" and I have the date format:
    .Type(ModelFieldType.Date).DateFormat("M/d hh:mmtt")
    I did notice in the tooltip help that DateFormat is for dates in the "\date\" format. Do you think my date is showing as it is due to the fact that the case does not match what your code is looking for for a date?

    Note: The JSON I am returning is automatically generated and I do not have control over the case of the fields.
    Last edited by Daniil; Apr 30, 2012 at 7:58 PM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    Hi,

    Well, ModelField with Date Type can't parse such string.
    "Date(1334691950203)"
    and this is not correct format to parse that string
    DateFormat("M/d hh:mmtt")
    So, if you can't change how this string looks, I can suggest to try the following

    Example
    <ext:ModelField Name="test">
        <Convert Handler="return eval('new ' + value);" />
    </ext:ModelField>
    Here is a full example.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "Date(1334691950203)" },
                    new object[] { "Date(1231334691950)" },
                    new object[] { "Date(1231394691950)" },
                };
                store.DataBind();
            }
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="test">
                                    <Convert Handler="return eval('new ' + value);" />
                                </ext:ModelField>
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:DateColumn runat="server" Text="Test" DataIndex="test" Format="yyyy-MM-dd" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    </body>
    </html>
  3. #3
    My colleague said that you should use just
    DateFormat="M$"
    Example
    <%@ Page Language="C#" %>
      
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "/Date(1334691950203)/" },
                    new object[] { "/Date(1231334691950)/" },
                    new object[] { "/Date(1231394691950)/" },
                };
                store.DataBind();
            }
        }
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="test" Type="Date" DateFormat="M$" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:DateColumn 
                        runat="server" 
                        Text="Test" 
                        DataIndex="test" 
                        Format="yyyy-MM-dd" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    </body>
    </html>
  4. #4

    Date

    Well, that did work, but it gave me this:
    Wed Apr 25 2012 12:22:29 GMT-0500 (Central Daylight Time)

    That's nice to see it know how to "read" the data, but now I need it in a display format of:
    4/25 12:22:29

    Do I need to go back to your original solution or is there something else I should do?
  5. #5
    You should use also the DateColumn with a respective Format as I did in the both examples.
  6. #6

    Thanks

    Sorry..using Razor here. I missed that in your sample. That worked as I needed.

Similar Threads

  1. [CLOSED] Wrong JSON Date Timezone ...
    By prointernet in forum 1.x Legacy Premium Help
    Replies: 17
    Last Post: May 22, 2014, 5:22 AM
  2. Replies: 4
    Last Post: Jul 29, 2011, 1:42 PM
  3. [CLOSED] Displaying Todays date in Date field
    By Vasudhaika in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Feb 22, 2011, 10:38 AM
  4. [CLOSED] How to Set Date Format in a Coolite Date Field
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 02, 2010, 8:47 AM
  5. [CLOSED] MVC Json and Date field type
    By mthird in forum 1.x Help
    Replies: 2
    Last Post: Oct 17, 2008, 6:05 AM

Tags for this Thread

Posting Permissions