Return to Snippet

Revision: 12126
at March 3, 2009 05:01 by kurokikaze


Initial Code
function multi_tablesort($header = array()) {
    $sorts = array('asc', 'desc');
    $sorter = '';
    $tablesort = array();
    
    foreach($header AS $field) {
        if (in_array($field['sort'],$sorts)) {
            $tablesort[] = db_escape_string($field['field']) . ' ' . drupal_strtoupper(db_escape_string($field['sort']));
        }

    }
    
    if (count($tablesort) > 0) {
        $sorter = 'ORDER BY ' . implode(', ', $tablesort);
    }
    
    return $sorter;
}

Initial URL

                                

Initial Description
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.

Initial Title
Sorting by multiple columns

Initial Tags
table, drupal

Initial Language
PHP