I am hooking into the callback where I attempt to sort the rows in the grid once the data has loaded. Code below:

grid.parse(data, function () {
grid.sortRows(5, “des”);
}, “json”);

The grid still remains unsorted after calling the sortRows method. Any pointers will be greatly appreciated.

What type and sorting type does 5th column have?

I am using a custom excell type (date2). I have overridden the getValue() method and defined a custom sort method (date2_custom) for this type. The sorting works correctly when the header is clicked.

Second parameter of sortRows() method should be type of sorting, not sorting order

mygrid.sortRows(col, type, order) … t_sortrows

Hi Olga.
I have tried using the type and the sorting is still not applied after the data is loaded…

var sortArr = grid.getSortingState();
var type = grid.getColType(sortArr[0]);
grid.sortRows(sortArr[0], type, sortArr[1]);

When do you call getSortingState method? If no one column was sorted method returns empty array.

That’s correct. I save the sorting state when the user sorts with header. I’m just trying to apply the sort using code when fresh data is loaded into the grid. Cheers

PS there is definitely data in the array when I call the sortRows method.

when fresh data is loaded into the grid
Timing of call is important here. When data is loaded in grid, in some cases it can reset current state and configuration ( when xml contains HEAD section for example ), in such case information about previous sorting will be lost.

The safe way is the next

var state = grid.getSortingState(); grid.load(url, function(){ grid.sort(state[0]); });

Above code stores state before loading and call sort after loading.