my %allowed_sort_columns =
map({ $_, 1 } qw(id customernumber vendornumber name address contact phone fax email
taxnumber sic_code business invnumber ordnumber quonumber));
- $sortorder =
- $form->{sort} && $allowed_sort_columns{$form->{sort}} ?
- $form->{sort} : "name";
+ $sortorder = $form->{sort} && $allowed_sort_columns{$form->{sort}} ? $form->{sort} : "name";
$form->{sort} = $sortorder;
+ my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
if ($sortorder eq "address") {
- $sortorder = "lower(country), lower(city), lower(street)";
+ $sortorder = "lower(country) ${sortdir}, lower(city) ${sortdir}, lower(street) ${sortdir}";
} elsif ($sortorder ne 'id') {
- $sortorder = "lower($sortorder)";
+ $sortorder = "lower($sortorder) ${sortdir}";
+ } else {
+ $sortorder .= " ${sortdir}";
}
if ($form->{"${cv}number"}) {
$form->{IS_CUSTOMER} = $form->{db} eq 'customer';
+ report_generator_set_default_sort('name', 1);
+
CT->search(\%myconfig, \%$form);
my $cvar_configs = CVar->get_configs('module' => 'CT');
my @hidden_variables = (qw(db status obsolete), map { "l_$_" } @columns);
my @hidden_nondefault = grep({ $form->{$_} } @hidden_variables);
my $callback = build_std_url('action=list_names', grep { $form->{$_} } @hidden_variables);
- $form->{callback} = "$callback&sort=" . E($form->{sort});
+ $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
- map { $column_defs{$_}->{link} = "${callback}&sort=${_}" } @columns;
+ foreach (@columns) {
+ my $sortdir = $form->{sort} eq $_ ? 1 - $form->{sortdir} : $form->{sortdir};
+ $column_defs{$_}->{link} = "${callback}&sort=${_}&sortdir=${sortdir}";
+ }
my ($ordertype, $quotationtype, $attachment_basename);
if ($form->{IS_CUSTOMER}) {
$report->set_export_options('list_names', @hidden_variables);
- $report->set_sort_indicator($form->{sort}, 1);
+ $report->set_sort_indicator($form->{sort}, $form->{sortdir});
CVar->add_custom_variables_to_report('module' => 'CT',
'trans_id_field' => 'id',