5

I am using a BlockTable and colorize its colums depending on object values.

<apex:variable value="" var="column_1_color"/>

<apex:pageBlockTable value="{!objectList}" var="object">

    <apex:column>
        <apex:variable var="column_1_color"
            value="{!IF(object.Name="test","green","red")}"/>
        Name:
    </apex:column>

    <apex:column style="background-color:{!column_1_color}">
        {!object.Name}
    </apex:column>

</apex:pageBlockTable>

|Name: | xxx |<--red
|Name: | test |<--green

The var needs to render for each row,
but what if I need the var value before creating first |Name: | column?
Is there any tag that keeps me from using an empty column?

Like this: (does not work)

<apex:variable value="" var="column_1_color"/>

<apex:pageBlockTable value="{!objectList}" var="object">

    <apex:variable var="column_1_color"
        value="{!IF(object.Name="test","green","red")}"/>

    <apex:column style="background-color:{!column_1_color}">
        Name:
    </apex:column>

    <apex:column style="background-color:{!column_1_color}">
        {!object.Name}
    </apex:column>

</apex:pageBlockTable>
1
  • What do you mean "what if I need the var value before creating first |Name: | column?" I see that the Name: is a repeat of the objectList.
    – Rao
    Commented Jun 5, 2013 at 16:52

1 Answer 1

5

Your <apex:variable> doesn't need a <apex:column> for itself. It can be immediately after <apex:repeat> and it should work just fine.

In fact you can ditch it completely and directly use your condition (makes sense if it'd be used only once. If you need the conditional formatting in more than 1 place - leave it in variable).

<apex:column style="background-color:{!IF(object.Name="test","green","red")}">
    {!object.Name}
</apex:column>

Not sure if that answers your question...

5
  • yes <apex:variable> is not rendered or not working in <apex:pageblocktable>
    – D-Horse
    Commented Jun 5, 2013 at 18:09
  • That is how it should work, but it doesn't. not even an <apex:variable var="column_1_color" value="red"/> immediately after blockTable works.. it is not rendering this var outside a column
    – itsmebasti
    Commented Jun 6, 2013 at 6:51
  • @Basti It should work, i've tested it too and got colirized columns. Commented Jun 6, 2013 at 7:10
  • 1
    That's because pageBlockTable "thinks" in columns. repeat would "think" in rows if you're willing to craft the html yourself. Try the second way or you can also rearrange styling a bit: <apex:column><div style="background-color:{!IF(object.Name="test","green","red")}">{!object.Name}</div></apex:column>
    – eyescream
    Commented Jun 6, 2013 at 7:11
  • good to know!! But I would prefer an empty column, than styling a whole new table. and using divs in TDs just leads to more problems.
    – itsmebasti
    Commented Jun 6, 2013 at 8:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .