[CLOSED] How to deal with a null date in a JSON Web Service?

  1. #1

    [CLOSED] How to deal with a null date in a JSON Web Service?

    Hii,
    I'm trying to move my datastore from a datatable to a webservice to achieve remote paging. But i'm a little bit annoying with date 01/01/0001. When datatable is used, my datagrid show a blank column for 01/01/00001 but when using webservice it does not. My question is how to show a null date from a web service?

    I am trying examples, https://examples1.ext.net/#/GridPane...ON_WebService/ and modify the first xml node into:


     
    <plant>
    <common>Bloodroot</common>
    <botanical>Sanguinaria canadensis</botanical>
    <zone>4</zone>
    <colorCode>E7E7E7</colorCode>
    <light>Mostly Shady</light>
    <price>2.44</price>
    <availability>01/01/0001</availability>
    <indoor>true</indoor>
    </plant>
    Is there any config missed from the example to show a null date?
    Last edited by Daniil; Sep 01, 2010 at 1:44 PM. Reason: [CLOSED]
  2. #2
    Hello!

    "01/01/0001" is showed because of it's a valid date, Jan 1 1.
    If you would try to change value to really invalid date such as "01/01/0a01" an exception will be thrown.

    If you would like to prevent showing date such as "01/01/0001" you can use a Renderer.

    Example
    <ext:Column Header="Available" DataIndex="Availability">
        <Renderer Handler="return (value === '01/01/0001') ? '' : value;" />
    </ext:Column>
    Last edited by Daniil; Aug 31, 2010 at 5:14 PM.
  3. #3
    Hello again!

    If you want to avoid showing specific dates using a DateColumn control I would recommend you to use Convert section of RecordField control.

    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.Store.Primary;
                store.DataSource = new object[] { 
                                             new object[] {new DateTime(2010, 1, 1)},
                                             new object[] {new DateTime(2010, 2, 2)},
                                             new object[] {new DateTime(2010, 3, 3)},
                                    };
                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" Type="Date">
                                    <Convert Handler="  value = Date.parseDate(value, 'Y-m-dTh:i:s'); 
                                                        return value.format('Y-m-d') == new Date(2010,1,2).format('Y-m-d') ? '': value" />
                                </ext:RecordField>
                            </Fields>
                        </ext:ArrayReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:DateColumn Header="Test" DataIndex="test" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
        </form>
    </body>
    </html>

Similar Threads

  1. Replies: 0
    Last Post: Dec 02, 2011, 12:23 AM
  2. Replies: 0
    Last Post: Dec 01, 2011, 6:43 AM
  3. Problem CRUD with JSON&Web Service
    By oseqat in forum 1.x Help
    Replies: 1
    Last Post: Jul 12, 2011, 10:23 AM
  4. [CLOSED] i wana handle my web service when replay with {d:null}
    By farisqadadeh in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Dec 23, 2010, 6:07 PM
  5. Replies: 1
    Last Post: Jun 08, 2010, 11:38 AM

Posting Permissions