Date with Grid

  1. #1

    Date with Grid

    Im using a grid panel and manually a record into the store from codebehind. Im having problems with the date fields, I have used a combination of setting the format on the RecordField in the store using Type="Date" and DateFormat="d/m/Y" as well as playing with the renderer on the column of the grid but with no success.

    I've had a look at the store and can see that the date is being stored looks like this:

    /Date(1324292400000+1300)

    Im using
    store.insertRecord(IDictionary<string, object>)
    to populate the store from code behind.

    Is this correct?
    Last edited by Daniil; Dec 07, 2011 at 7:53 AM. Reason: Please use [CODE] tags
  2. #2
    Hi,

    DateFormat must be a .NET date time format string and should be set up if you bind a string, not a DateTime object.

    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)
            {
                this.Store1.DataSource = new object[] 
                { 
                    new object[] { DateTime.Now, "07/12/2011" },
                    new object[] { DateTime.Now.AddDays(1), "08/12/2011" },
                    new object[] { DateTime.Now.AddDays(2), "09/12/2011" }
                };
                this.Store1.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 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Reader>
                            <ext:ArrayReader>
                                <Fields>
                                    <ext:RecordField Name="test1" Type="Date" />
                                    <ext:RecordField Name="test2" Type="Date" DateFormat="dd/MM/yyyy" />
                                </Fields>
                            </ext:ArrayReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:DateColumn Header="DateTime" DataIndex="test1" />
                        <ext:DateColumn Header="String" DataIndex="test2" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
    And if you bind a Dictionary, you have to set up IsComplex="true" for a RecordField and parse it manually, something like this:
    http://forums.ext.net/showthread.php...ll=1#post70103

Similar Threads

  1. [CLOSED] date format in Grid
    By vali1993 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 21, 2011, 7:49 PM
  2. [CLOSED] Date Grid Filter Issue
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Mar 02, 2011, 9:09 AM
  3. Add date range grid filter
    By stone216 in forum 1.x Help
    Replies: 12
    Last Post: May 24, 2010, 5:32 PM
  4. date format for all date fields in grid?
    By marcmvc in forum 1.x Help
    Replies: 0
    Last Post: Dec 01, 2009, 3:41 PM
  5. Can't change date format in grid
    By dbassett74 in forum 1.x Help
    Replies: 2
    Last Post: Apr 20, 2009, 1:15 PM

Posting Permissions