tags:

views:

23

answers:

2

When using jqgrid you can set the select statement via:

$grid->SelectCommand = $query

However you cannot set the ORDER BY here.

jqgrid allows you to sort the grid on any column.

If my DB table has a column called "cost" and I want my grid to be in order by cost but NOT show cost. Is there a way to do that?

+1  A: 

In your DB select statement you can select the data to return based on the order by cost or you can include cost as a column in your jqgrid and set it to hidden and order by the cost column.

Byron Cobb
+2  A: 

You can include on your html page an additional element like checkbox or a select with options which allows the user to choose the sort order. To read information about users selection you can use

var addSortInfo = jQuery("#orderByCost").is(':checked');

or

var addSortInfo = jQuery("#selectList option:selected").val();

Then you can use postData option of jqGrid to send additional data with all requests to the server. The value of the postData parameter can be an object like {mySortInfo: addSortInfo} where "mySortInfo" is the name of additional parameter which you will see on the server side together with sidx, page and other standard parameters of every requests. In case of HTTP GET requests the data from postData will be appended to the server url and in case of HTTP POST the data will be added to the request body.

You can also use functions inside of postData. The advantages of this approach you can read in http://stackoverflow.com/questions/2928371/how-to-filter-the-jqgrid-data-not-using-the-built-in-search-filter-box/2928819#2928819 for more information.

Oleg