Update to my Tips post from yesterday...
Category Technical
Bookmark :
Yesterday I showed you a quick and dirty way to display categories at the top of a $$ViewTemplate for a view that you either can't or don't want to use "traditional" twisties. This method is great for views that don't have many categories - but what about views with a ton of categories? Today let me show you a way to have an A-Z line across the top, with links only for the letters that exist in the view. Take a look at this:
The bolded letters represent documents whose category begins with that letter (in this case, they are names).
Here's the code that produces the alpha navigation:
look := @DbColumn("" : ""; ""; search_view; 1);
list := @If(@IsError(look); ""; @Unique(look));
letters := "A" : "B" : "C" : "D" : "E" : "F" : "G" : "H" : "I" : "J" : "K" : "L" : "M" : "N" : "O" : "P" : "Q" : "R" : "S" : "T" : "U" : "V" : "W" : "X" : "Y" : "Z";
lettercode := "<a href=\"/" + search_view + "?OpenView&StartKey="+letters+"&Count=50\" target=_self><b>" + letters + "</b></a>";
REM "this is a list of the first letters in our list from the view";
listletters := @UpperCase(@Unique(@Left(list; 1)));
listcode := @Trim(@Replace(listletters; letters; lettercode));
results := @Trim(@Replace(letters; listletters; listcode));
"<TR VALIGN=top><TD WIDTH=100%>" + @Implode(results; " ") + "</TD></TR>"
Here's a breakdown of the code....
Code Breakdown
First I do a lookup, test for errors, and unique the results.
look := @DbColumn("" : ""; ""; search_view; 1);
list := @If(@IsError(look); ""; @Unique(look));
Then I make a list of all letters, and then build the link code for each letter.
etters := "A" : "B" : "C" : "D" : "E" : "F" : "G" : "H" : "I" : "J" : "K" : "L" : "M" : "N" : "O" : "P" : "Q" : "R" : "S" : "T" : "U" : "V" : "W" : "X" : "Y" : "Z";
lettercode := "<a href=\"/" + search_view + "?OpenView&StartKey="+letters+"&Count=50\" target=_self><b>" + letters + "</b></a>";
The Search_View parameter is from a field on the $$ViewTemplate form, that contains the view being used for the template. I added a bold tag in my HREF display, to make the letters that have corresponding documents in the view more visible. You can remove those if you want.
Next I get the first letter from each category in the view, and upper case it. After that I take the first letters and create a list of the code that corresponds to the letters from the view.
listletters := @UpperCase(@Unique(@Left(list; 1)));
listcode := @Trim(@Replace(listletters; letters; lettercode));
After I get this list I simply replace the view letters in the full letter list with the code for them.
results := @Trim(@Replace(letters; listletters; listcode));
And I finish by imploding the results on a non-breaking space, and wrap it with the table row code - remember that this is all in a computed text item, and it is surrounded by table tags.
"<TR VALIGN=top><TD WIDTH=100%>" + @Implode(results; " ") + "</TD></TR>"
This produces the results shown in the picture above. Kewl, huh? This technique doesn't have to be used with just letters, either - you can use anything such as numbers or words to accomplish the same thing.
Conclusion
This technique is quick and dirty, and works in Release 5.x and ND6. It provides a nice, flexible and completely automatic navigation interface that is fast and easy to understand - and is browser agnostic.
Enjoy!
Rock
**If I could talk to the animals, I'd tell them about their lousy personal hygiene. And then I'd buy Proctor & Gamble stock, because there are a lot of animals out there.







Blog Roll









Comments
Posted by Trent At 10:38:43 AM On 03/15/2004 | - Website - |
list := @If(@IsError(look); ""; @Trim(@Unique(look)));
because I had gaps in my view and there is a missing semicolon after   in the last line which firefox requires but IE doesn't.
@Implode(results; " ")
Thanks,
Alan.
Posted by Alan Bell At 07:51:36 AM On 04/13/2004 | - Website - |