Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqGrid default sort order?

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.

like image 223
Marcus Leon Avatar asked Sep 16 '10 19:09

Marcus Leon


2 Answers

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

like image 192
Veysel Ozdemir Avatar answered Sep 19 '22 14:09

Veysel Ozdemir


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.

like image 20
Kedarnath Calangutkar Avatar answered Sep 18 '22 14:09

Kedarnath Calangutkar