Default value for date type variable

Page 1 of 2 12 LastLast
  1. #1

    Default value for date type variable

    Hi.........

    I need to know how to set a default value to an item in a grid view....???
    For example, for an int type we'll set default value in "record field" as DefaultValue="00"
    but in the case of string or date type, it is not supporting that kind of statement.............
    Can you help me with an answer????

    Thank you In Advance.....
  2. #2
    Hi,

    You could use RecordField's Convert.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        class Test
        {
            public Nullable<int> IntProperty { get; set; }
            public string StringProperty { get; set; }
            public DateTime DateProperty { get; set; }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new Test()
                    { 
                        IntProperty = 1,
                        StringProperty = "something",
                        DateProperty = DateTime.Now
                    },
                    new Test()
                };
                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:JsonReader>
                            <Fields>
                                <ext:RecordField Name="IntProperty">
                                    <Convert Handler="return value || value == 0 ? value : 'default int';" />
                                </ext:RecordField>
                                <ext:RecordField Name="StringProperty">
                                    <Convert Handler="return value ? value : 'default string';" />
                                </ext:RecordField>
                                <ext:RecordField Name="DateProperty">
                                    <Convert Handler="return value ? Date.parseDate(value, 'Y-m-dTH:i:s') : new Date(1,1,1)" />
                                </ext:RecordField>
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Int" DataIndex="IntProperty" />
                    <ext:Column Header="String" DataIndex="StringProperty" />
                    <ext:DateColumn Header="Date" DataIndex="DateProperty" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
        </form>
    </body>
    </html>
  3. #3
    k....
    Thank you.....
    I'll Check it once........
  4. #4
    Hey it worked.... Thnaks once again for ur help.......
    I have one more doubt....
    Can we assign default value for date as " No Date found" or something in the form of a string................?????
  5. #5
    Replace
    <ext:DateColumn Header="Date" DataIndex="DateProperty" />
    with
    <ext:Column Header="Date" DataIndex="DateProperty" />
    and

    <ext:RecordField Name="DateProperty">
        <Convert Handler="return value ? Date.parseDate(value, 'Y-m-dTH:i:s') : new Date(1,1,1);" />
    </ext:RecordField>
    with
    <ext:RecordField Name="DateProperty">
        <Convert Handler="return value ? Date.parseDate(value, 'Y-m-dTH:i:s') : 'No date'" />
    </ext:RecordField>
    If you need to format how dates look in a column please use Renderer.
  6. #6
    I tried it.. It worked But im getting date for remailning data as "Sun Mar 21 2010 00:00:00 GMT+0530(Indian Standard Time)".
    If i use renderer, im not getting data at all.... The total table is appearing blank....
    I want the date to be displayed as "date-month-year"...
    Pls ge me a sugession....

    Thanks,
    Emon
    Last edited by emon; Mar 04, 2011 at 4:52 AM.
  7. #7

    No need

    I got the solution from your previous replies... Thanks for your help
  8. #8

    One more issue

    The default value is displayed as "NaN-Nan-0NaN" instead od "nodate" even i i use

    <Convert Handler="return value ? Date.parseDate(value, 'Y-m-dTH:i:s') : 'nodate'" />
    But while in exported file it is displaying "nodate"
    :(
    Last edited by Daniil; Mar 10, 2011 at 10:30 AM.
  9. #9
    Please provide a simplified .aspx page to reproduce (like this one that I posted in my first post of this thread).
  10. #10
    Is there any solution????
    Last edited by emon; Mar 08, 2011 at 4:11 AM.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Default date format for Type="Date" RecordField
    By r_honey in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: May 29, 2012, 4:16 PM
  2. With regard to the date of the type stroe
    By guoweidong in forum 1.x Help
    Replies: 2
    Last Post: Mar 10, 2010, 1:05 AM
  3. setting the default value of a date type column of store from backend ?
    By n_s_adhikari@rediffmail.com in forum 1.x Help
    Replies: 2
    Last Post: Oct 16, 2009, 6:35 PM
  4. RecordField type="date" in coolite 0.8
    By dperera in forum 1.x Help
    Replies: 8
    Last Post: Sep 01, 2009, 6:49 PM
  5. [CLOSED] MVC Json and Date field type
    By mthird in forum 1.x Help
    Replies: 2
    Last Post: Oct 17, 2008, 7:05 AM

Posting Permissions