diff options
| author | Jonathan Prykop <jonathan@freeside.biz> | 2016-07-29 23:53:35 -0500 |
|---|---|---|
| committer | Jonathan Prykop <jonathan@freeside.biz> | 2016-08-29 18:10:17 -0500 |
| commit | b09f61d517dc01dd2eae04b3e03a5b9e5dab1a0f (patch) | |
| tree | e9aa91f8f222c89eca45926b608e9c1ac4791f4b /httemplate/search/elements | |
| parent | dc3c29ad94942345b3316d23e23f6dc8303de566 (diff) | |
RT#42724: Data Usage Report - System Error on Column Sort
Diffstat (limited to 'httemplate/search/elements')
| -rw-r--r-- | httemplate/search/elements/search.html | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index beb017300..8b85324c9 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -135,8 +135,11 @@ Example: # sort, link & display properties for fields - 'sort_fields' => [], #optional list of field names or SQL expressions for - # sorts + 'sort_fields' => [], #optional list of field names or SQL expressions for sorts + + 'order_by_sql' => { #to keep complex SQL expressions out of cgi order_by value, + 'fieldname' => 'sql snippet', # maps fields/sort_fields values to sql snippets + } #listref - each item is the empty string, # or a listref of link and method name to append, @@ -406,6 +409,12 @@ $order_by = $cgi->param('order_by') if $cgi->param('order_by'); my $header = [ map { ref($_) ? $_->{'label'} : $_ } @{$opt{header}} ]; my $rows; +my ($order_by_key,$order_by_desc) = ($order_by =~ /^\s*(.*?)(\s+DESC)?\s*$/i); +$opt{'order_by_sql'} ||= {}; +$order_by_desc ||= ''; +$order_by = $opt{'order_by_sql'}{$order_by_key} . $order_by_desc + if $opt{'order_by_sql'}{$order_by_key}; + if ( ref $query ) { my @query; if (ref($query) eq 'HASH') { |
