Gossamer Forum
Home : Products : DBMan : Customization :

default sort on view all

Quote Reply
default sort on view all
I have read some posts on how to sort after the view all link is clicked....can you sort it by one field (magazine name) and then also sort it again (magazine date) so that the view all displays the results sorted by the magazine name and the date?





Thanks
Quote Reply
Re: [didiasku] default sort on view all In reply to
Look at the link that's used to call "view_all". I guess it contains "&view_records=1&ID=*".

to this link you can simply add "sb=1&so=ascend".

The number after "sb" should be the number of the field you want to sort on; the string after "so" is the sort order.

(Slightly different if you use the multiple sort mod, then you have to use "sb1" and "so1").
kellner
Quote Reply
Re: [kellner] default sort on view all In reply to
Kellner - is the multisort mod listed in the mod list?

Here's what I did to get around this sort problem before I heard of a multisort mod.

I created a new field in my .cfg file called sortfield.

Then in the add_record routine in db.cgi, I did this -

After the following statements.

# Set the userid to the logged in user.

($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);

(!$per_admin) and ($in{$db_validated_field} = "No");

I put this.

#This next line added to create a merged field to sort data output. It is field 19 in .cfg file.

$in{'SortField'}=$in{'PresentationDate'}.$in{'StudentLast'}.$in{'StudentFirst'};

This creates a field that merges all three fields into a single field in the field order I need them sorted.

Then, as Kellner suggested, use sb=19 (or whatever number your field is in your .cfg file) and so=a (if you want ascending)in your link.

Works great for me.

Quote Reply
Re: [cwhatley] default sort on view all In reply to
the multiple sort mod should be accessible in the mod list, or via the unofficial dbman faq.

cwhatley: I'm kind of surprised that your approach works, because the three fields contain different data types - "PresentationDate" is a date and would in the end be sorted numerically, whereas the other two fields, I assume, contain names and would be sorted alphabetically. Alphabetical and numeric sorts are different in perl - try to sort strings of letters numerically, and you'll see.

What data type do you have specified for SortField in your cfg-file? Presumably "alpha", otherwise dbman would choke on the letters.

I'm not sure, and too tired right now to think, but I suspect your approach doesn't really work, but only seems to work because luckily enough your database has so far not produced any "critical" cases which would show it to fail.
kellner
Quote Reply
Re: [kellner] default sort on view all In reply to
It's put in as an alpha field.

I'll send you private email (if I can figure out where your profile is on this "new" system) to let you login and add some records to test. I recently finished constructing it and I cleaned out the database for you. I'd appreciate the feedback on letting me know whether I'm crazy or not Smile.

Chris
Quote Reply
Re: [cwhatley] default sort on view all In reply to
I've already sent this to Chris via e-mail, but just for the record: Chris, I believe the sort function you use works because your data is highly limited in type.

The input form only offers two alternatives for the date field: "3-Sep-2001" and "8-Sep-2001". Sorting alpha on this field first works, because "3" has a lower ASCII value than "8". As soon as you get a date later than the tenth, things will get messy, because perl doesn't sort on "13", but on "1", and "1" has a lower ASCII value than "3".

As long as your data stays this limited, no problem. But I would not recommend this approach for multiple sorts in general.
kellner