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.
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
I was facing the same problem. Use this after loading the data:
$("#tableId").jqGrid('sortGrid','colName', false, 'asc');
or
$("#tableId").sortGrid('colName', false, 'asc');
The grid is reloaded if the boolean value is set to true. The last parameter can be 'asc' / 'desc', depending on the sort order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With