Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add multi-column sorting to jqgrid?

I can add single column sorting to jqgrid, no problem. How can I add multi-column sorting to jqgrid?

That is, sort by column 1, then sort by column 2, the final sort order is: column 2, column 1

like image 856
John Mills Avatar asked Sep 03 '10 01:09

John Mills


2 Answers

A simple work around is to list all fields as a comma separated string ex.

sortname: 'customer_id, store_id, start_date'

On the server side just go ahead and parse the string and and craft your query.

like image 32
Darren Cato Avatar answered Oct 14 '22 02:10

Darren Cato


Current version of jqGrid not support multi-column sorting.

On http://www.trirand.com/blog/ you can "Which feature do you like to see in jqGrid?" vote the answer

  • Export to PDF
  • Freeze columns
  • Sort by multiple columns
  • Group by multiple columns

In general you can try to implement multi-sorting yourself by modifying sortname and sortorder parameters of jqGrid inside onSortCol event handler with respect of setGridParam. In case of two columns which having column indexes like firstName and lastName for example the sorting by the first column only imply having sortname as 'firstName' and sortorder as 'asc'. If you want to sort first by the firstName and by lastName as the secont criteria you can set sortname as 'firstName asc, lastName' and sortorder as 'asc'. Your server program should of cause be able to interpret this, but if you just construct ORDER BY something like ORDER BY $sidx $sord (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:first_grid#php_and_mysql_example_file) it will work.

like image 64
Oleg Avatar answered Oct 14 '22 02:10

Oleg