tags:

views:

21

answers:

1

I'm in the beforeRequest handler, and would like to know what the current sort column is. How can I find that?

A: 

You can examine the values of the jqGrid parameters sortname and sortorder ("desc" or "asc"). To get the parameters you can use getGridParam method:

var sortColumnName = $("#list").jqGrid('getGridParam','sortname');

and

var sortOrder = $("#list").jqGrid('getGridParam','sortorder'); // 'desc' or 'asc'
Oleg
that's helpful, thanks. What I really want to do is add a class (either sortAsc or sortDesc) to the th of the sorted column.
sprugman
@sprugman: What do you mean under "add a class ... to the sorted column."? Do you mean the column header or all cells in the column or both?
Oleg
@Oleg: the <th> tags in the column header. I can write some code to do it with what you've given me. (In fact, I already have.) Just checking to see if there was something built in.
sprugman
@sprugman: you can use `setLabel` method. See http://stackoverflow.com/questions/3003187/jquery-jqgrid-how-to-set-alignment-of-grid-header-cells/3006853#3006853 as an example.
Oleg
Using the setLabel method, how do I unset the old class using that method? So, first time through, the first column gets the sort-asc class. Then I click on the third column. Col 1 needs to have sort-asc removed, while col 3 has it added....
sprugman
@sprugman: A good point! You can't. Currently `setLabel` method use only `addClass` or `css` methods and no `removeClass`. So use have to do this manually. The `setLabel` method do following (see http://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2904): It convert the name of the column to the column position if needed. Then it uses `var thecol = $("tr.ui-jqgrid-labels th:eq("+pos+")",$t.grid.hDiv);` to get the `<th>` element and finally calls `$(thecol).addClass(prop);` or `$(thecol).css(prop);`. You can do the same to be most close to `setLabel` method but use `removeClass`.
Oleg