[CLOSED] Date Format in DateColumn Elements

  1. #1

    [CLOSED] Date Format in DateColumn Elements

    Hi,

    In this thread you have said that a DateField element gets it's format by default from:

    System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.ShortDatePattern
    I have therefore set this in my Web.config:

    <globalization culture="en-GB" uiCulture="en-GB" />
    and this works for DateField elements (they are now defaulting to format dd/MM/yyyy).

    However, the same does not appear to be true for the DateColumn element (it is not defaulting to this date format). Could you tell me how I can have a default format which will be applied to DateColumn elements as well?

    Secondly, RecordField elements of type="Date" appear to need a DateFormat property set. Would it be possible to get this from a default date format as well?

    Thirdly, in general I have found that in lots of pages I have properties (like "PageSize" in the PagingToolbar element) which I would like to set globally for my whole project rather than duplicating these values in many pages. Is it possible to set default values of element properties in any way?

    Many Thanks
    Last edited by Daniil; Jul 11, 2011 at 10:19 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Quote Originally Posted by ljcorreia View Post
    the same does not appear to be true for the DateColumn element (it is not defaulting to this date format). Could you tell me how I can have a default format which will be applied to DateColumn elements as well?

    Secondly, RecordField elements of type="Date" appear to need a DateFormat property set. Would it be possible to get this from a default date format as well?

    Thirdly, in general I have found that in lots of pages I have properties (like "PageSize" in the PagingToolbar element) which I would like to set globally for my whole project rather than duplicating these values in many pages. Is it possible to set default values of element properties in any way?
    You can set respective your own settings in Web.config (or any other settings store), read and set up them for widgets in code behind (for example, in Page_Load).

    Secondly, RecordField elements of type="Date" appear to need a DateFormat property set. Would it be possible to get this from a default date format as well?
    By the way, you don't need to set up .DataFormat for a RecordField if you bind a DateTime object to that RecordField.
  3. #3
    Quote Originally Posted by Daniil View Post
    You can set respective your own settings in Web.config (or any other settings store), read and set up them for widgets in code behind (for example, in Page_Load).
    Setting the attributes on fields in the code behind is exactly what I am trying to avoid - I would have to reference every DateColumn element separately and then set the attribute on it from the Web.config and doing this on all the pages which have DateColumn elements creates a lot of code duplication and is almost as bad as just setting the formats individually.

    If it is not possible to set default attributes globally (this would be a really useful feature, please consider it!), then is there any easy way to get all the elements of one type on a page from the code behind - i.e. a method which returns all of the DateColumn elements in a page?
  4. #4
    If it is not possible to set default attributes globally (this would be a really useful feature, please consider it!),
    There are lot and lot of properties of different widgets. The solution can look cumbersome.

    A structural solution can be creating your own inherited from DateColumn class with default values.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        class MyDateColumn : DateColumn
        {
            public override string Header
            {
                get
                {
                    return "MyDateColumn";
                }
            }
            
            public override string Format
            {
                get
                {
                    return "Y-mm-dd";
                }
            }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            this.GridPanel1.ColumnModel.Columns.Add(new MyDateColumn()
            {
                DataIndex = "test"
            });
            
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { DateTime.Now },
                    new object[] { DateTime.Now.AddDays(1) },
                    new object[] { DateTime.Now.AddDays(2) }
                };
                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 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
                <Store>
                    <ext:Store runat="server">
                        <Reader>
                            <ext:ArrayReader>
                                <Fields>
                                    <ext:RecordField Name="test" />
                                </Fields>
                            </ext:ArrayReader>
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:GridPanel>
        </form>
    </body>
    </html>
    then is there any easy way to get all the elements of one type on a page from the code behind - i.e. a method which returns all of the DateColumn elements in a page?
    It can look like this:

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            List<GridPanel> grids = Ext.Net.Utilities.ControlUtils.FindControls<GridPanel>(this);
            foreach (GridPanel grid in grids)
            {
                foreach (ColumnBase c in grid.ColumnModel.Columns)
                {
                    if (c.GetType().Equals(typeof(DateColumn)))
                    {
                        ((DateColumn)c).Format = "Y-mm-dd";
                        ((DateColumn)c).Header = "My DateColumn";
                    }
                }
            }
    
            if (!X.IsAjaxRequest)
            {
                Store store = this.Store1;
                store.DataSource = new object[] 
                { 
                    new object[] { "test1", DateTime.Now },
                    new object[] { "test2", DateTime.Now.AddDays(1) },
                    new object[] { "test3", DateTime.Now.AddDays(2) }
                };
                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 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:ArrayReader>
                        <Fields>
                            <ext:RecordField Name="test" />
                            <ext:RecordField Name="date" />
                        </Fields>
                    </ext:ArrayReader>
                </Reader>
            </ext:Store>
            <ext:GridPanel runat="server" StoreID="Store1" AutoHeight="true">
                <ColumnModel>
                    <Columns>
                        <ext:Column Header="Test" DataIndex="test" />
                        <ext:DateColumn DataIndex="date" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
            <ext:GridPanel runat="server" StoreID="Store1" AutoHeight="true">
                <ColumnModel>
                    <Columns>
                        <ext:Column Header="Test" DataIndex="test" />
                        <ext:DateColumn DataIndex="date" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>

Similar Threads

  1. Ext.Net.DateColumn Format issue
    By lmueller in forum 1.x Help
    Replies: 4
    Last Post: Sep 17, 2018, 5:05 AM
  2. [OPEN] [#98] GridPanel: date values in DateColumn not localized
    By sbg in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 27, 2012, 9:57 AM
  3. Replies: 1
    Last Post: Nov 29, 2011, 6:11 PM
  4. Replies: 3
    Last Post: Nov 01, 2011, 7:15 PM
  5. [CLOSED] DateColumn, Format
    By jeybonnet in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 03, 2010, 2:57 PM

Tags for this Thread

Posting Permissions