Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqGrid - Default Sort Order by Column

Happy New Years Eve!

I would like to be able to set the default for value some columns to descending. So, the first time the user clicks on that column, it sorts descending by nature.

I have no problem setting the default sort field and order of my grid. But that is all the info I am finding.

$grid->setGridOptions(array(

"caption"=>"Player Statistics",
"rowNum"=>200,
"rowList"=>array(50,200,1000),
"sortname"=>"percentOwned",
"sortorder" => 'desc',
"width" => 1000,
"height" => 400,
"hoverrows" => true,
"viewrecords" => false

));

How do I set the default sort to descending on a per column basis? Is it possible?

Thanks!

like image 797
Bryan Avatar asked Dec 31 '12 18:12

Bryan


People also ask

How do I sort data in jqxgrid?

The Grid sorting logic is implemented in the jqxgrid.sort.js and you need to reference that javascript file. In the code example below, the Grid data sorting is enabled. To enable or disable the sorting of a Grid column, you can set its sortable property to false.

How do I remove the sort order in the grid?

To remove the sorting, call the "removesort" function. When the data is sorted, the Grid raises the 'sort' event. By default, when the sorting is enabled and the user clicks a column's header, the sort order is changed.

How to override the default sorting logic in the grid?

To override the default sorting logic, you need to set the 'sort' member of the Grid's source object to a custom sorting function. The Grid will pass two parameters to this function - the sort column's datafield and the sort direction.

How do I enable/disable the sorting of a grid column?

The Grid sorting logic is implemented in the jqxgrid.sort.js and you need to reference that javascript file. In the code example below, the Grid data sorting is enabled. To enable or disable the sorting of a Grid column, you can set its sortable property to false. In the code example below, the sorting of the "ShipName" column is disabled.


1 Answers

Although not in the documentation, 'firstsortorder' => 'desc' does the trick.

$grid->setGridOptions(array(
'firstsortorder' => 'desc'
"caption"=>"Player Statistics",
"rowNum"=>200,
"rowList"=>array(50,200,1000),
"sortname"=>"percentOwned",
"sortorder" => 'desc',
"width" => 1000,
"height" => 400,
"hoverrows" => true,
"viewrecords" => false
));
like image 73
Bryan Avatar answered Oct 11 '22 02:10

Bryan