views:

175

answers:

4

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.

A: 

Try to use

$("#list").jqGrid('setGridParam',{ page: 1 }).trigger("reloadGrid");

or

$("#list").jqGrid('setGridParam',{ rowNum: 10 }).trigger("reloadGrid");

(replace 10 to value which you define as rowNum parameter). If it will not help then post your code in your question.

Oleg
Are you suggesting we load the grid twice? The initial load (not sorted) and a second load which will hopefully be sorted?
Marcus
@Marcus: You don't insert any code in your question so I have to guess what do you do. It you load the JSON or XML data from the server the server sort the data, so you should fix your server code. If you load the data from the local source or load from the server as **unsorted** with "loadonce:true" you should **sort** the data once. To do this you have to refresh the data displayed in the current page ot the grid. You can do this with respect of `trigger("reloadGrid")` - in case of local data it is just "refreshing" the current page. Sometimes setting parameters like `page` or `rowNum` helps
Oleg
We are loading unsorted data from the server with `loadonce:true`. Will try `trigger...`
Marcus
A: 

the problem is (I believe) that the parameter sortName nor sidx are read when requesting the first data set

zdux
A: 

You might have made the same mistake as myself, which was to base my client script off of an old example which used "sortName" instead of "sortname"

zdux
A: 

/Cheesy Answer Alert

Why not hide the sorted icon the first time you load? First time someone sorts, unhide it and things work as intended. Sounds like it was your intent to load unsorted until the user chooses a column to sort on.

Jason Slocomb