[OPEN] [#26] Grid panel grouping and sorting from code-behind

  1. #1

    [OPEN] [#26] Grid panel grouping and sorting from code-behind

    Two questions for grouping and sorting in a grid panel:

    1. How do I group a grid panel from code-behind? I can set it in the markup but need to change it at run-time.

    2. How do I sort a grid panel from code-behind?
    I tried to use the SetDefaultSort method but I get a message that Ext.Net.Store does not contain a definition for SetDefaultSort. I also tried setting the store's SortInfo property in the markup but it does not accept it.
    Last edited by Baidaly; Nov 16, 2012 at 10:54 PM.
  2. #2
    Hi @Manny,

    As I can see there are no server counterparts for the sort and group methods.
    http://docs.sencha.com/ext-js/4-1/#!...re-method-sort
    http://docs.sencha.com/ext-js/4-1/#!...e-method-group

    I will discuss with the colleagues a possibility to add these server methods.

    For now please use:
    Store1.Call("sort", /* arguments */);
    Store1.Call("group", /* arguments */);
  3. #3
    That works.

    Thank you very much, Daniil!
  4. #4
    Following up on code-behind for grouping: I am trying to close the grouping via

    Grouping1.CollapseAll()
    in the page load event. Is this too earlier? Or is this the wrong method?

    I am aware of the client-side solution https://examples2.ext.net/#/GridPane...eous/Grouping/.

    Ultimately, I would like to show the groups collapsed when the page is loaded.
  5. #5
    Yes, you are right, it is too earlier. A GridPanel should be rendered before. So, please use this method (and similar ones) during a DirectEvent or a DirectMethod.

    Please set this option
    StartCollapsed="true"
    for the Grouping feature.
  6. #6
  7. #7
    Opened an Issue to track this defect, see

    https://github.com/extnet/Ext.NET/issues/26
  8. #8
    The Group and Sort methods has been added for the StoreBase class.

    Here is an example of usage the Sort ones.

    Thank you again for the request.

    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[] { "1", "b" },
                    new object[] { "3", "c" },
                    new object[] { "1", "a" },
                    new object[] { "3", "d" },
                    new object[] { "2", "f" },
                };
                this.Store1.DataBind();
            }
        }
    
        protected void Sort1(object sender, DirectEventArgs e)
        {
            this.Store1.Sort("test1");
        }
    
        protected void Sort2(object sender, DirectEventArgs e)
        {
            this.Store1.Sort("test1", Ext.Net.SortDirection.ASC);
        }
    
        protected void Sort3(object sender, DirectEventArgs e)
        {
            this.Store1.Sort(new DataSorter() { Property = "test1", Direction = Ext.Net.SortDirection.DESC });
        }
    
        protected void Sort4(object sender, DirectEventArgs e)
        {
            
            DataSorter[] sorters = new DataSorter[]
            {
                new DataSorter() { Property = "test1", Direction = Ext.Net.SortDirection.DESC },
                new DataSorter() { Property = "test2", Direction = Ext.Net.SortDirection.DESC }
            };
    
            this.Store1.Sort(sorters);
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:GridPanel runat="server">
            <Store>
                <ext:Store ID="Store1" runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="test1" />
                                <ext:ModelField Name="test2" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column runat="server" Text="Test1" DataIndex="test1" />
                    <ext:Column runat="server" Text="Test2" DataIndex="test2" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    
        <ext:Button runat="server" Text="Sort1" OnDirectClick="Sort1" />
    
        <ext:Button runat="server" Text="Sort2" OnDirectClick="Sort2" />
    
        <ext:Button runat="server" Text="Sort3" OnDirectClick="Sort3" />
    
        <ext:Button runat="server" Text="Sort4" OnDirectClick="Sort4" />
    </body>
    </html>
  9. #9
    Thanks Daniil. Is it already available via SVN? The log shows the latest revision 4586 as of 11/27/12.
    Last edited by Manni; Dec 12, 2012 at 6:43 PM.
  10. #10
    Hello, @Manni!

    Try to update from SVN's trunk.

Similar Threads

  1. Replies: 1
    Last Post: Jan 17, 2014, 3:43 PM
  2. [CLOSED] Use Grid Grouping without sorting by the groupField ?
    By ndotis in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 08, 2011, 7:17 PM
  3. Grouping grid from code behind
    By maephisto in forum 1.x Help
    Replies: 2
    Last Post: Apr 12, 2011, 4:17 PM
  4. Sorting In Grid Panel
    By hardik in forum 1.x Help
    Replies: 0
    Last Post: Apr 08, 2011, 4:02 AM
  5. [CLOSED] Dynamic Grid, Sorting and Grouping Issue
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 16, 2010, 1:06 PM

Tags for this Thread

Posting Permissions