Gossamer Forum
Home : Products : DBMan : Customization :

multiple sort with spreadsheet4 type display

Quote Reply
multiple sort with spreadsheet4 type display
I have the multiple sort working in the spreadsheet4 type display. My problem is as follows:

I have clickable column headers that the user can use to alter the default sort order, which is by 'producer,' 'wine' and 'year. If a user chooses 'year', i have the sort by year and then producer and wine name. I would like to have it work that if the user chooses year again, the sort is descending in year but has the same ascending sort by producer and name within the year. I am having trouble getting the "ascend"/"descend" to switch automatically.

I have searched the forums and haven't found anyone that seems to have posted the solution.

I am a brute-force perl programmer, i.e., not efficient. Here is what I have added to sub html_view_success:

-------------------------------
$new_url =~ s/\&sb1=\d*//;
$new_url =~ s/\&sb2=\d*//;
$new_url =~ s/\&sb3=\d*//;
$new_url =~ s/\&sb4=\d*//;
$new_url =~ s/\&sb5=\d*//;
$new_url =~ s/\&so1=\w*//;
$new_url =~ s/\&so2=\w*//;
$new_url =~ s/\&so3=\w*//;
$new_url =~ s/\&so4=\w*//;
$new_url =~ s/\&so5=\w*//;
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb1'} == $col) {
if ($in{'so1'} eq 'descend') { $so[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }
}
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb2'} == $col) {
if ($in{'so2'} eq 'descend') { $so[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }
}
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb3'} == $col) {
if ($in{'so3'} eq 'descend') { $so[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }
}
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb4'} == $col) {
if ($in{'so4'} eq 'descend') { $so[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }
}
for ($col=0; $col <=$#db_cols; ++$col) {
if ($in{'sb5'} == $col) {
if ($in{'so5'} eq 'descend') { $so[$col] = 'ascend'; }
else { $so[$col] = 'descend'; }
}
else { $so[$col] = 'ascend'; }
}



## Here is the table display
<TABLE bgcolor='#e0e0b1' cellpadding=3 cellspacing=3>
<TD align='left'><a href="$db_script_url?$new_url&sb1=2&so1=$so[2]&sb2=3&so2=$so[2]&sb3=5&so3=$so[5]"><font color='blue'><u>Producer</u></font></a></TD>
<TD align='left'><a href="$db_script_url?$new_url&sb1=4&so1=$so[4]&sb2=5&so2=$so[5]"><font color='blue'><u>Wine Name</u></a></font></TD>
<TD align='left'><a href="$db_script_url?$new_url&sb1=5&so1=$so[5]&sb2=2&so2=$so[2]&sb3=4&so3=$so[4]"><font color='blue'><u>Year</u></a></font></TD>
<TD align='left'><a href="$db_script_url?$new_url&sb1=6&so1=$so[6]&sb2=2&so2=$so[2]&sb3=4&so3=$so[4]&sb4=5&so4=$so[5]"><font color='blue'><u>Country</u></a></font></TD>
<TD align='left'><a href="$db_script_url?$new_url&sb1=8&so1=$so[8]&sb2=2&so2=$so[2]&sb3=4&so3=$so[4]&sb4=5&so4=$so[5]"><font color='blue'><u>Type</u></a></font></TD>
<TD align='left'><a href="$db_script_url?$new_url&sb1=9&so1=$so[9]&sb2=2&so2=$so[2]&sb3=4&so3=$so[4]&sb4=5&so4=$so[5]"><font color='blue'><u>Color</u></a></font></TD>
<TD align='left'><a href="$db_script_url?$new_url&sb1=10&so1=$so[10]&sb2=2&so2=$so[2]&sb3=4&so3=$so[4]&sb4=5&so4=$so[5]"><font color='blue'><u>Price</u></a></font></TD>
<TD align='left'><a href="$db_script_url?$new_url&sb1=11&so1=$so[11]&sb2=2&so2=$so[2]&sb3=4&so3=$so[4]&sb4=5&so4=$so[5]"><font color='blue'><u>Bottle Size</u></a></font></TD>
</TR>\n|;
----------------------------------

This doesn't work. Neither does having
if ($in{'so5'} eq 'descend') { $sb[$col] = 'ascend'; }
instead of
if ($in{'so5'} eq 'descend') { $so[$col] = 'ascend'; }

Any obvious problems/fixes?

In action:

http://www.lechai.com/cgi-bin/dbtest.cgi?db=winestest&uid=default

Go to "list all." Default list is by 'producer' 'wine name' and 'year'. Any other choice, say by 'country' should sort on country, then producer, name and year. The user should then be able to click on "country" once again and reverse the country sort - although the subsorts would stay in the same order.

Any help appreciated.