[CLOSED] Performing sort on GridPanel when it has text with underscore

  1. #1

    [CLOSED] Performing sort on GridPanel when it has text with underscore

    Sorting GridPanel when it has underscore text does not work as expected, as shown below:

    Initial GridPanel's state
    Click image for larger version. 

Name:	img000001.png 
Views:	77 
Size:	7.0 KB 
ID:	5458

    GridPanel's state after sort (ascending)
    Click image for larger version. 

Name:	img000002.png 
Views:	80 
Size:	7.3 KB 
ID:	5459

    Note that the texts that begins with "_" are below those others. As far as i know it should be above.

    <!DOCTYPE html>
    <html>
    <head id="Head1" runat="server">
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:GridPanel Title="Ext.Net" runat="server" >
            <Store>
                <ext:Store runat="server" >
                    <Proxy>
                        <ext:AjaxProxy Url="/Example/LoadFakeRecords/">
                            <ActionMethods Read="POST" />
                            <Reader>
                                <ext:JsonReader Root="data" />
                            </Reader>
                        </ext:AjaxProxy>
                    </Proxy>
                    <Model>
                        <ext:Model ID="Model2" runat="server">
                            <Fields>
                                <ext:ModelField Name="Name" SortType="AsUCText" Type="String" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:RowNumbererColumn runat="server" />
                    <ext:Column Text="Name" DataIndex="Name" runat="server" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    </body>
    </html>
    namespace SandBox.Controllers
    {
        public class ExampleController : System.Web.Mvc.Controller
        {
            public ActionResult Index()
            {
                return View();
            }
    
            public StoreResult LoadFakeRecords()
            {
                List<Entity> lst = new List<Entity>();
    
                for (int index = 0; index < 15; index++)
                {
                    lst.Add(new Entity
                    {
                        Name = index % 2 == 0 ? string.Format("Name{0}", index) : string.Format("_Name{0}", index),
                    });
                }
    
                return new StoreResult(lst, lst.Count());
            }
        }
    
        public class Entity
        {
            public string Name { get; set; }
        }
    }
    Last edited by Baidaly; Jan 24, 2013 at 1:08 AM. Reason: [CLOSED]
  2. #2
    Please open console in your browser and input
    "_Note">"Note0"
    For me it is true, it means that for ASC sorting '_Note' will be below 'Note0'
  3. #3
    Also, it can be related with culture (not sure if javascript string comparing is culture sensitive (like in .NET))
  4. #4
    Hi everybody,

    I can confirm "_" > "N" returns true in IE9, Chrome and FireFox on my PC.

    But this C# code returns -1.
    "_".CompareTo("N")
    Honestly, I don't know why this difference is. Maybe different encoding...

    Anyway, RemoteSort="true" for the Store could be a solution.
  5. #5
    "_note" > "note"
    false

    I think that it should work as i expected since i use SortType="AsUCText"
  6. #6
    >> "_a".charCodeAt(0);
    95
    >> "_a".charCodeAt(1);
    97
  7. #7
    I think that it should work as i expected since i use SortType="AsUCText"
    "AsUCText" converts text to upper case before comparing but A-Z codes 65-90
    Underscore code is 95 therefore undescore > then symbol from A-Z
    You can convert to lower case using CustomSortType of ModelField
    <CustomSortType Handler="return String(value).toLowerCase().replace(Ext.data.SortTypes.stripTagsRE, '');" />
  8. #8
    Sorry Vladmir, i thought it was insensitive (http://forums.ext.net/showthread.php...se-insensitive). Now i realized that UC means Upper Case :)

    Thank you, your solution works like a charm.

    Please mark this thread as closed.

Similar Threads

  1. Replies: 8
    Last Post: Dec 21, 2012, 6:42 AM
  2. Replies: 1
    Last Post: Mar 17, 2012, 6:04 AM
  3. Replies: 4
    Last Post: Jul 25, 2011, 4:57 PM
  4. GridPanel - Sort Issue
    By lucas in forum 1.x Help
    Replies: 1
    Last Post: Nov 29, 2010, 3:58 PM
  5. Sort with Conditional sort direction in JS- help!
    By Tbaseflug in forum 1.x Help
    Replies: 2
    Last Post: May 05, 2009, 12:11 PM

Posting Permissions