jqGrid default sort order?

Marcus Leon picture Marcus Leon · Sep 16, 2010 · Viewed 40.2k times · Source

It appears that the jqGrid sortname and sortorder properties do not actually cause your data set to be sorted - they just cause the up/down arrows to be displayed.

How can you get your data set to sort on download?

The sort works well when you click the column headers but I want a default sort to be applied to our data.


Update: When we click the next button, the next request sorts the data.

This causes a slightly confusing UI where the data loads with a down arrow on a column - and the data isn't sorted - but when you click next the data is now sorted.

It seems if I omit sortname and sortorder that jqGrid still displays the sort icon - weird.

Answer

Veysel Ozdemir picture Veysel Ozdemir · May 25, 2011

You might be giving the same parameter twice ( a very common mistake when copy paste progrraming :) no offenses. I do it too.)

Say you want to sort by OpeningDate descending

..... options .... 
sortname: "OpeningDate",
sortorder: "desc",  <---- assume you write this line and expect to sort descending
..... some other options .... 
sortorder: "asc",   <---- and this line may also be there but you may not be noticing it 
..... and other options .... 

the second "sortorder" option overrides the first and you will not be able to sort descending