Conditional Formatting using the Advanced Computed Field


I got a question on how to use the Advanced Computed Field for conditional formatting and when I finished writing up the response I figured I might as well share it with the community, being you all :)

Here’s the config I used:

<FieldRefs>
<FieldRef Name="TestField" /> </FieldRefs> <DisplayPattern>

<Switch> <Expr>
    <Field Name="TestField" /> </Expr>
   <Case Value="value1">
     <HTML><![CDATA[<div style='color: green;'><b>GREEN</b></div>]]></HTML> </Case> <Case Value="value2"> <HTML><![CDATA[<div style='color: blue;'><b>BLUE</b></div>]]></HTML> </Case> <Case Value="value3"> <HTML><![CDATA[<div style='color: red;'><b>RED</b></div>]]></HTML>
  </Case>
   <Default> <HTML><![CDATA[<div style='color: brown;'><b>BROWN</b></div>]]></HTML> </Default>
</Switch> </DisplayPattern>

 


Links to this post

Comments

Monday, 22 Mar 2010 02:35 by Thomas
Hi Steven, I would like to display different colors in dependence of a DateField (09.03.2010). Maybe: IF LastModified > [TODAY] AND LastModified < [TODAY] + 14 THEN green color ELSE red. any idea how to retrieve the date form a date column? Bye, Thomas

Thursday, 25 Mar 2010 10:28 by Steven Van de Craen
Thomas, I'd do this using jQuery. Pass the date value in a diff with css class. Then on your page or in the masterpage make sure the jQuery exists that will manipulate all divs with that css class.

CAPTCHA Image Validation