« Couple of code tips... | Main| Sametime plugin for Trillian - FINALLY! »

Update to my Tips post from yesterday...

QuickImage   
Category
Bookmark : del.icio.us  Technorati  Digg This  Add To Furl  Add To YahooMyWeb  Add To Reddit  Add To NewsVine 


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:

A picture named M2

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; "&nbsp") + "</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; "&nbsp") + "</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.

Comments

1 - Nice trick. I did something very similar when I had to create a Name Picker on the web. The lists of letters at the top represented initials for the last name.

2 - great stuff Rocky, I added a trim on the second line
list := @If(@IsError(look); ""; @Trim(@Unique(look)));
because I had gaps in my view and there is a missing semicolon after &nbsp in the last line which firefox requires but IE doesn't.
@Implode(results; "&nbsp;")

Thanks,

Alan.

Meet Rocky

Rock - February 2010
Rocky Oliver
If you see me at a conference, please stop me and say hi!

Calendar

Search

Categories

Proudly Employed By

Wofkflow Studios

Thawte Notary

Thawte Web of Trust Notary

LOTUS GEEK gear

Social Networking


Add to Technorati Favorites

View Rocky Oliver's profile on LinkedIn

Rocky  Oliver

LotusGeek Blog Roll

Why display a blog roll when Planet Lotus does it so much better?

Dilbert

Buy my book!

Blog Buttons

Atheist - Unitarian - Humanist

Poker Players Alliance