DataSorter is not working

  1. #1

    DataSorter is not working

    Hi, in the 2.x version I can access the Datasorter information in codebehind, but in 3.x it sends an array empty error.

    aspx
    <Sorters>
          <ext:DataSorter Property="Cuenta" Direction="ASC"/>
    </Sorters>
    .cs
    In 2.x this is working:
                        
    StoreRequestParameters prms2 = new StoreRequestParameters(context);
    string _sOrderBy = prms2.Sort[0].Property; 
    string _sOrderDirection = prms2.Sort[0].Direction.ToString();
    But in 3.x it throws this error:
    Detalles de la excepci?n: System.IndexOutOfRangeException: Out of bounds array index.

    prms2.Sort[0]
    Out of bounds array index

    Can you help please?
  2. #2
    Please post a complete (but simplified) code sample demonstrating how to reproduce the issue.
  3. #3

    More detalied code

    .aspx
      <ext:GridPanel 
                    id="grdU"
                    runat="server" 
                    Width="700" 
                    Height="320">
                    <Store>
                            <ext:Store runat="server" PageSize="10">
                            <Proxy>
                                <ext:AjaxProxy Url="../../ashx/dal/Usuario.ashx">
                                    <Reader>
                                        <ext:JsonReader RootProperty="data" TotalProperty="total" />
                                    </Reader>
                                    <Listeners>
                                        <Exception Handler="Ext.MessageBox.alert('Carga de Informacion Fallo...', response.statusText);" />
                                    </Listeners>
                                </ext:AjaxProxy>
                            </Proxy>
                            <Model>
                                <ext:Model runat="server" IDProperty="Id">
                                    <Fields>
                                        <ext:ModelField Name="Id" />
                                        <ext:ModelField Name="Cuenta" />
                                        <ext:ModelField Name="Matricula" />
                                        <ext:ModelField Name="Nombre" />
                                        <ext:ModelField Name="Email" />
                                        <ext:ModelField Name="DeviceAny" Type="Boolean" />
                                        <ext:ModelField Name="DeviceSerial"  />
                                        <ext:ModelField Name="Estatus" Type="Boolean" />
                                        <ext:ModelField Name="Lastaccess" Type="Date" />
                                    </Fields>
                                </ext:Model>
                            </Model>
                            <Sorters>
                                <ext:DataSorter Property="Cuenta" Direction="ASC"/>  /*Here it is defined...*/
                            </Sorters>
                        </ext:Store>
                    </Store>
                    <TopBar>
                        <ext:ToolBar runat="server">
                            <Items>
                                <ext:Button runat="server" Icon="Add" Text="Nuevo Usuario">
                                    <Listeners>
                                        <Click Handler="LApp.add()" />
                                    </Listeners>
                                </ext:Button>
                            </Items>
                        </ext:ToolBar>
                    </TopBar>
                    <ColumnModel runat="server">
                        <Columns>
                            <ext:Column runat="server" Text="Cuenta" DataIndex="Cuenta" />
                            <ext:Column runat="server" Text="Nombre" DataIndex="Nombre" />
                            <ext:Column runat="server" Text="Email" DataIndex="Email" />
                            <ext:BooleanColumn runat="server" Text="DeviceAny"  TrueText="Si" FalseText="No" DataIndex="DeviceAny" Width="65" />
                            <ext:Column runat="server" Text="DeviceSerial" DataIndex="DeviceSerial" />
                            <ext:BooleanColumn runat="server" Text="Activo"  TrueText="Si" FalseText="No" DataIndex="Estatus" Width="50" />
                            <ext:DateColumn runat="server" Text="LastAccess" DataIndex="Lastaccess" Format="dd/MM/yy HH:mm" Width="90" Filterable="false" />
                        </Columns>
                    </ColumnModel>
                    <Plugins>
                            <ext:FilterHeader runat="server" Remote="true" />
                    </Plugins>
                    <SelectionModel>
                        <ext:RowSelectionModel runat="server" Mode="Single">
                            <DirectEvents>
                                <Select OnEvent="grdURowSel" Buffer="250">
                                    <EventMask ShowMask="true" Target="CustomTarget" CustomTarget="#{frmU}" />
                                    <ExtraParams>
                                        <ext:Parameter Name="x" Value="record.getId()" Mode="Raw" />
                                    </ExtraParams>
                                </Select>
                            </DirectEvents>
                        </ext:RowSelectionModel>
                    </SelectionModel>
                    <BottomBar>
                        <ext:PagingToolbar runat="server" DisplayInfo="true" DisplayMsg="Usuarios {0} - {1} de {2}" EmptyMsg="No existen Usuarios"/>
                    </BottomBar>
                </ext:GridPanel>
    .ashx

        public class Usuario : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "application/json";
    
                int _iStart = 0;
                int _iLimit = 10;
                string _sOrderBy = "Id";
                string _sOrderDirection = "DESC";
                string _sFilter = string.Empty;
    
                StoreRequestParameters prms2 = new StoreRequestParameters(context);
                _iStart = prms2.Start;
                _iLimit = prms2.Limit;
                _sOrderBy = prms2.Sort[0].Property; /*Here is where the error is generated, out of bounds index */
                _sOrderDirection = prms2.Sort[0].Direction.ToString(); 
                _sFilter = context.Request["filterheader"];
                context.Response.Write(JSON.Serialize(new UsuarioRepository().GetPagingFilterHeader(_iStart, _iLimit, _sOrderBy, _sOrderDirection, _sFilter)));
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    As I mentioned above, the same code in 2.x doesnt complain, but in 3.x it is throwing the error..
  4. #4

    the solution

    It works coding the tag RemoteSort

    <ext:Store runat="server" PageSize="10" RemoteSort="true">
  5. #5
    When Store's RemoteSort is set to false, no sorting information is submitted.

    You can try it on the following sample by setting Store's RemoteSort to false.
    <!DOCTYPE html>
    <html>
    <head runat="server">
    </head>
    <body>
        <ext:ResourceManager ScriptMode="Debug" runat="server" />
        <ext:GridPanel ID="_grd" Title="Ext.Net" Border="true" Width="500" Height="300" runat="server">
            <Store>
                <ext:Store PageSize="10" RemoteSort="true" AutoLoad="true" runat="server">
                    <Sorters>
                        <ext:DataSorter Property="ID" Direction="DESC" />
                    </Sorters>
                    <Proxy>
                        <ext:AjaxProxy Url="~/Example/LoadFakeRecords/" StartParam="start" LimitParam="limit" PageParam="page" SortParam="sort">
                            <ActionMethods Read="POST" />
                            <Reader>
                                <ext:JsonReader RootProperty="data" />
                            </Reader>
                        </ext:AjaxProxy>
                    </Proxy>
                    <Model>
                        <ext:Model IDProperty="ID" runat="server">
                            <Fields>
                                <ext:ModelField Name="ID" Type="Int" />
                                <ext:ModelField Name="Name" Type="String" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Text="ID" DataIndex="ID" runat="server" />
                    <ext:Column Text="Name" Flex="1" DataIndex="Name" runat="server" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:CheckboxSelectionModel ID="_sm" Mode="Multi" runat="server" />
            </SelectionModel>
        </ext:GridPanel>
    </body>
    </html>
    namespace SandBox.Controllers
    {
        public class ExampleController : System.Web.Mvc.Controller
        {
            public ActionResult Index()
            {
                return View();
            }
    
            public StoreResult LoadFakeRecords(int start, int limit, int page, string sort)
            {
                List<Entity> lst = new List<Entity>();
    
                for (int index = start; index < (page * limit); index++)
                {
                    lst.Add(new Entity
                    {
                        ID = index,
                        Name = string.Format("Name - {0}", index)
                    });
                }
    
                lst = Sort(lst, sort);
    
                return new StoreResult(lst, (page * limit) + limit);
            }
    
            public List<Entity> Sort(List<Entity> lst, string sort)
            {
                DataSorter sortDefinition = DataSorter.From(sort).FirstOrDefault();
    
                var parameter = Expression.Parameter(typeof(Entity));
    
                Func<Entity, Object> function = Expression.Lambda<Func<Entity, IComparable>>(Expression.Convert(Expression.Property(parameter, sortDefinition.Property), typeof(IComparable)), parameter).Compile();
    
                if (sortDefinition.Direction == SortDirection.ASC)
                {
                    return lst.OrderBy(function).ToList();
                }
                else
                {
                    return lst.OrderByDescending(function).ToList();
                }
            }
        }
    
        [Serializable]
        public class Entity
        {
            public int ID { get; set; }
    
            public string Name { get; set; }
        }
    }
  6. #6
    It would be possible to overcome the issue (if it's still needed) by doing the following:

    DataSorter sortInfo = prms2.Sort.FirstOrDefault();
    if(sortInfo != null)
    {
        _sOrderBy = sortInfo.Property; 
        _sOrderDirection = sortInfo.Direction.ToString(); 
    }

Similar Threads

  1. Replies: 0
    Last Post: Oct 07, 2014, 9:06 AM
  2. [CLOSED] MVC DataSorter JSON Deserialisation
    By paulc in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Feb 14, 2013, 10:41 AM
  3. Replies: 0
    Last Post: Oct 30, 2012, 6:34 PM
  4. Replies: 3
    Last Post: Feb 21, 2012, 8:46 AM
  5. Replies: 3
    Last Post: Apr 27, 2011, 4:54 PM

Tags for this Thread

Posting Permissions