PDA

View Full Version : [CLOSED] Performing sort on GridPanel when it has text with underscore



RCN
Jan 23, 2013, 3:37 PM
Sorting GridPanel when it has underscore text does not work as expected, as shown below:

Initial GridPanel's state
5458

GridPanel's state after sort (ascending)
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; }
}
}

Vladimir
Jan 23, 2013, 3:45 PM
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'

Vladimir
Jan 23, 2013, 3:48 PM
Also, it can be related with culture (not sure if javascript string comparing is culture sensitive (like in .NET))

Daniil
Jan 23, 2013, 3:57 PM
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.

RCN
Jan 23, 2013, 4:05 PM
"_note" > "note"
false

I think that it should work as i expected since i use SortType="AsUCText"

RCN
Jan 23, 2013, 4:08 PM
>> "_a".charCodeAt(0);
95
>> "_a".charCodeAt(1);
97

Vladimir
Jan 23, 2013, 4:22 PM
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.SortT ypes.stripTagsRE, '');" />

RCN
Jan 23, 2013, 4:36 PM
Sorry Vladmir, i thought it was insensitive (http://forums.ext.net/showthread.php?10372-CLOSED-GridPanel-sortable-case-insensitive). Now i realized that UC means Upper Case :)

Thank you, your solution works like a charm.

Please mark this thread as closed.