PDA

View Full Version : [OPEN-1137] Sort toggle doesn't work if initial sort direction comes from metaData



jweber
19 Jul 2010, 4:20 PM
Ext version tested:

Ext 3.21
Ext 2.3


Adapter used:

ext


css used:

only default ext-all.css




Browser versions tested against:

Safari 4


Operating System:

Mac OS X


Description:

Create a JsonReader that gets its metaData from the JSON response. This metaData should include a sortInfo property, which specifies the sort field and direction of the initial result set. The initial direction should be DESC.
Create a grid which uses this JsonReader. After its data is loaded, the sorted column will appear correctly, with the appropriate arrow, pointing downward.
Click the sorted column to toggle its sort. This should switch it to ASC. However, the request it makes is for dir=DESC. So the field remains sorted in descending order.
Click the same column again. This time it toggles correctly to ascending order.


Test Case:



var reader = new Ext.data.JsonReader();
var store = new Ext.data.JsonStore({
url:'response.js',
reader:reader,
remoteSort:true
});
var cm = new Ext.grid.ColumnModel([
{header: "Name", sortable: true, dataIndex:"name"},
{header: "Job", sortable: true, dataIndex:"job"}
]);
var grid = new Ext.grid.GridPanel({
renderTo:"gridEl",
store:store,
cm:cm,
height:300
});
store.load();


In this example, "response.js" just returns the example from the JsonReader API docs, except that I set the initial direction to DESC:


{
metaData: {
"idProperty": "id",
"root": "rows",
"totalProperty": "results",
"successProperty": "success",
"fields": [
{"name": "name"},
{"name": "job", "mapping": "occupation"}
],
// used by store to set its sortInfo
"sortInfo":{
"field": "name",
"direction": "DESC"
},
// paging data (if applicable)
"start": 0,
"limit": 2,
// custom property
"foo": "bar"
},
// Reader's configured successProperty
"success": true,
// Reader's configured totalProperty
"results": 2000,
// Reader's configured root
// (this data simulates 2 results per page)
"rows": [ // *Note: this must be an Array
{ "id": 1, "name": "Bill", "occupation": "Gardener" },
{ "id": 2, "name": "Ben", "occupation": "Horticulturalist" }
]
}



Steps to reproduce the problem:

Run the above example code. The grid should appear sorted by Name, descending.
Click the Name column. The browser will send a POST request with two paramters: sort=name and dir=DESC.
The grid won't actually sort if you're using the example response.js, but that doesn't matter.


The result that was expected:

A request with dir=ASC.


The result that occurs instead:

A request with dir=DESC.


Debugging already done:

see below


Possible fix:

This seems to be because Store.singleSort() is looking for a value in this.sortToggle, to find the current sort direction. But this value isn't set when Store.onMetaChange() receives the sortInfo parameters. Maybe onMetaChange should be calling setDefaultSort() rather than setting this.sortInfo directly?

Jamie Avins
20 Jul 2010, 9:04 AM
You issue has been entered in Trac for review. Thank for your the report.