jqGrid - Default Sort Order by Column

Bryan picture Bryan · Dec 31, 2012 · Viewed 11.4k times · Source

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!

Answer

Bryan picture Bryan · Dec 31, 2012

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
));