Alternating Rows on Web

Alternating Rows on Web

After reading this tip, if you decide that it would be good to add to your archive or that you think a friend would like it, go to the bottom of the tip and click "Have Tip Mailed".

If you have ever wanted greater control over the way your views display on the Web you may have considered using a view that displays HTML. That's great! But now you realize you don't have alternating row colors. Attached is a column formula using JavaScript to get those alternating colors.

The formula is a combination of @Formula, Javascript, and HTML. You can use @Formulas for data manipulation then use JavaScript to get the modulus of the @DocNumber. If @DocNumber returns an odd number then the variable "color" gets light gray otherwise it gets dark gray. That javascript variable is then incorporated into a document.write that writes each line of the view as the page loads. (Mind the quotes!)

You can achieve the same results in a dblookup but you'll have to write into the JavaScript another variable that is incremented for each row because you won't have access to the @DocNumber
Create a single view column using the following code. Once added, go to the property box for the view and select the beanie tab. Select "Treat view contents as HTML". You will notice in the formula that we have used the name of the color interchangably with the HTML hex code for the color. Replace the FormVariableOne with your variable. You may also want to change the

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

"Author" and "Created Date" for the first line of the view. Name the view "XYZ"

com:= @ReplaceSubstring(@Trim(FormValiableOne);@NewLine;"n");
"&LTscript> var color=(("+@DocNumber("")+"%2)==1)?
"Yellow":"#FFFFFF";"+
@Char(13)+
"document.write("&LTtd width=450 bgcolor="+color+">"
+@Name([CN];Author) + " entered on: "+@Text(@If
(CreateDate="";@Created;CreateDate)) + "</td></tr>&LTtr>&LTtd
bgcolor="+color+">" +@If(Title="";" ";"Comment: " +com) +
"</td></tr>");</script>"+@Char(13)

When you have completed the view, create a new form. Name the form "$$ViewTemplate for XYZ". Replace the XYZ with the actual name you gave the view. Add a field to the form called "$$ViewBody" and add the following code around it.

[add pic1] Sample of what this technique would look like if used for a view on DominoTips.

[add pic]

This was first published in November 2000

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.