PDA

View Full Version : [CLOSED] [#699] Disable remote sort and sort locally



RCN
Feb 10, 2015, 11:12 AM
On the following example
http://forums.ext.net/attachment.php?attachmentid=20721&stc=1

Select the records 3, 4, 5 and 6 in this specific order, then click Show Only Selected Records button
http://forums.ext.net/attachment.php?attachmentid=20731&stc=1

The remote sort was disabled, then local sort was performed (Lines 21 to 24), but unfortunately with no effect, the sort was not performed correctly.
Note that it's sorted by ID, descending, but the records are sorted by ID ascending.
http://forums.ext.net/attachment.php?attachmentid=20741&stc=1

On version 2.x, it works as expected.
http://forums.ext.net/attachment.php?attachmentid=20751&stc=1
Note: to run the example on version 2.x it's necessary to rename JsonReader's RootProperty to Root.

Thanks in advance.


<!DOCTYPE html>
<html>
<head runat="server">
<script type="text/javascript">
var ShowOnlySelectedRecords = function () {

var grid = App._grd;
var store = App._grd.store;

var selectedRecords = new Array();

for (var index = 0; index < App._sm.selected.length; index++) {
selectedRecords.push(App._sm.selected.items[index].raw);
}

store.clearData(true);

store.add(selectedRecords);

//Sort locally
var originalSort = store.remoteSort;
store.remoteSort = false;
store.sort();
store.remoteSort = originalSort;
}
</script>
</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>
<Buttons>
<ext:Button Text="Show Only Selected Records" runat="server">
<Listeners>
<Click Handler="ShowOnlySelectedRecords();" />
</Listeners>
</ext:Button>
</Buttons>
</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; }
}
}

Dimitris
Feb 11, 2015, 6:32 PM
Hello Raphael,

I've tried your sample and yes it does not perform sorting. But I also noticed that the grid ill behaves after the javascript code runs. The last added row remains checked and if I click the button again I get error:



TypeError: record is undefined


Maybe it is related to the original issue. Nevertheless, I will run a few more tests.

RCN
Feb 11, 2015, 7:12 PM
The last added row remains checked and if I click the button again I get error:


TypeError: record is undefined


Dimitris, honestly i haven't tested the sample as a whole. I just reproduced the issue, since in my real-world scenario it's quite more complex.

Can you list the steps to get the error. I would appreciate to reproduce it.

Thank you.

RCN
Feb 11, 2015, 7:17 PM
Dimitris, please replace


selectedRecords.push(App._sm.selected.items[index].raw);

by


selectedRecords.push(App._sm.selected.items[index].data);

Dimitris
Feb 12, 2015, 10:30 AM
Well, yes, no sorting. It is like the call to sort() is ignored. I have added a BeforeSort listener but it never gets fired, too.

Let me try with v.2.x and check a few things to decide if it is an intended change of behavior or a bug.

Theoretically speaking, I am not quite following the logic behind this mix of client and server side sorting considering that RemoteSort=true causes the data to be loaded from the server every time.

RCN
Feb 12, 2015, 10:49 AM

Dimitris
Feb 12, 2015, 3:25 PM
Certainly Raphael. After testing with 2.x. I do think this is a bug. I will post again as soon as we open an issue.

Issue (https://github.com/extnet/Ext.NET/issues/699) created.

RCN
Feb 12, 2015, 3:31 PM
Thank you.

Daniil
Feb 13, 2015, 9:05 AM
Hello everybody,

This should be used

store.setRemoteSort(false);
instead of

store.remoteSort = false;

So, the end of the ShowOnlySelectedRecords should look:

var originalSort = store.remoteSort;
store.setRemoteSort(false);
store.sort();
store.setRemoteSort(originalSort);

Please confirm it is working for you.

Seems not a bug.

Dimitris
Feb 13, 2015, 9:22 AM
I confirm it works for me. We can close the issue and the thread and move it out of Bugs as soon as Raphael confirms it works, too.

RCN
Feb 13, 2015, 11:10 AM
I confirm. Please mark this thread as closed.



This should be used

store.setRemoteSort(false);

It makes sense. I should have checked by myself. Sorry for that.