开发者

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.

开发者_Go百科

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.


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.


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"


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


/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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜