[CLOSED] Sort by date in GridPanel

  1. #1

    [CLOSED] Sort by date in GridPanel

    Hi,

    I'm trying to sort the GridPanel Store datasource on the server by a data field in descending order. Somehow, it doesn't work for me: the sorting doesn't take effect and the column sorting indicator icon doesn't show up after the page is rendered. What am I missing here?

    Thanks,

    Vadym

                
    <ext:GridPanel ID="GridPanel1" runat="server">
                    <Store>
                        <ext:Store ID="Store1" runat="server" WarningOnDirty="false">
                            <Reader>
                                <ext:JsonReader>
                                    <Fields>
                                        <ext:RecordField Name="MyString" />
                                        <ext:RecordField Name="MyDate" Type="Date" SortType="AsDate" SortDir="DESC" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <ColumnModel runat="server">
                        <Columns>
                            <ext:Column ColumnID="MyString" Header="My String" DataIndex="MyString" />
                            <ext:DateColumn ColumnID="MyDate" Format="MMM dd, yyyy" Header="My Date" DataIndex="MyDate" />
                        </Columns>
                    </ColumnModel>
                </ext:GridPanel>
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    DataTable dt = GetDataTable();
                    this.Store1.DataSource = dt;
                    this.Store1.DataBind();
                    this.Store1.Sort("MyDate", Ext.Net.SortDirection.DESC);
                }
            }
    Last edited by Daniil; Jun 19, 2012 at 8:39 PM. Reason: [CLOSED]
  2. #2
    Hi,

    To set up initial sorting, please set up Store SortInfo.

    Example
    <ext:Store runat="server">
        <SortInfo Field="MyDate" Direction="DESC" />
    </ext:Store>
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    To set up initial sorting, please set up Store SortInfo.

    Example
    <ext:Store runat="server">
        <SortInfo Field="MyDate" Direction="DESC" />
    </ext:Store>
    Hi Daniil,

    Where exactly do I place the SortInfo element? I'm getting a client side error:

    Unable to get value of the property 'store': object is null or undefined
    <Store>
                        <ext:Store ID="Store1" runat="server" WarningOnDirty="false">
                            <SortInfo Field="MyDate" Direction="DESC" />
                            <Reader>
                                <ext:JsonReader>
                                    <Fields>
                                        <ext:RecordField Name="MyString" />
                                        <ext:RecordField Name="MyDate" Type="Date" SortType="AsDate" SortDir="DESC" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
    Thanks,

    Vadym
  4. #4
    It appears to be working correctly for me.

    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[] { DateTime.Now.AddDays(1) },
                    new object[] { DateTime.Now },
                    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>
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <SortInfo Field="date" Direction="DESC" />
                    <Reader>
                        <ext:ArrayReader>
                            <Fields>
                                <ext:RecordField Name="date" Type="Date" />
                            </Fields>
                        </ext:ArrayReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:DateColumn Header="Date" DataIndex="date" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    </body>
    </html>
  5. #5
    Yes, the problem was on my side. Thanks Daniil, please mark this question as resolved.

    Vadym

Similar Threads

  1. Replies: 1
    Last Post: Apr 13, 2012, 1:52 PM
  2. Replies: 4
    Last Post: Jul 25, 2011, 4:57 PM
  3. [CLOSED] [1.0] GridPanel insertRecord Sort?
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 31, 2011, 9:48 AM
  4. Replies: 1
    Last Post: Feb 15, 2011, 5:45 PM
  5. [CLOSED] GridPanel and Sort
    By Stefanaccio in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 17, 2010, 8:12 AM

Tags for this Thread

Posting Permissions