Posted By

kurokikaze on 03/03/09


Tagged

table drupal sorting


Versions (?)

Sorting by multiple columns


 / Published in: PHP
 

Use instead of standard "sql_tablesort()" function. Handles multiple "sort" in $header, but the arrow will be only on last sorted column. This can be handled with rewriting theme_table, for example.

  1. function multi_tablesort($header = array()) {
  2. $sorts = array('asc', 'desc');
  3. $sorter = '';
  4. $tablesort = array();
  5.  
  6. foreach($header AS $field) {
  7. if (in_array($field['sort'],$sorts)) {
  8. $tablesort[] = db_escape_string($field['field']) . ' ' . drupal_strtoupper(db_escape_string($field['sort']));
  9. }
  10.  
  11. }
  12.  
  13. if (count($tablesort) > 0) {
  14. $sorter = 'ORDER BY ' . implode(', ', $tablesort);
  15. }
  16.  
  17. return $sorter;
  18. }

Report this snippet  

You need to login to post a comment.