You need to sign in to do that
Don't have an account?
megmooPDX
conditionally highlight row based on index position
I want to change the background color for the first row of data in a table displayed on a visual force page. I am thinking the best way to do this is change the style based on a test of which record is being displayed. However, I'm not sure how to determine which record is being displayed.
Here's the code in a portion of my VF page:
<apex:pageBlock >
<apex:pageBlockTable value="{!cRecords}" var="cRecord">
<apex:column value="{!cRecord.Name}">
<apex:facet name="header">HCC</apex:facet>
</apex:column>
<apex:column value="{!cRecord.HCC_strNum__c}">
<apex:facet name="header">HCC</apex:facet>
</apex:column>
<apex:column value="{!cRecord.Type__c}">
<apex:facet name="header">Type</apex:facet>
</apex:column>
<apex:column value="{!cRecord.Confidence_Level__c}">
<apex:facet name="header">Confidence Level</apex:facet>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
I thought the best way to do this is to use the index number of the array to determine whether to highlight the field, but I don't know how to retrieve the index number. Is there way to achieve something like the line below? I know cRecords.indexnumber = 0 is not correct/valid, but I'm looking for what that syntax might be.
<apex:column value="{!cRecord.Name}" style="{!IF(cRecords.indexnumber = 0),"background-color: green;",""background-color: white);"
Here's the code in a portion of my VF page:
<apex:pageBlock >
<apex:pageBlockTable value="{!cRecords}" var="cRecord">
<apex:column value="{!cRecord.Name}">
<apex:facet name="header">HCC</apex:facet>
</apex:column>
<apex:column value="{!cRecord.HCC_strNum__c}">
<apex:facet name="header">HCC</apex:facet>
</apex:column>
<apex:column value="{!cRecord.Type__c}">
<apex:facet name="header">Type</apex:facet>
</apex:column>
<apex:column value="{!cRecord.Confidence_Level__c}">
<apex:facet name="header">Confidence Level</apex:facet>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
I thought the best way to do this is to use the index number of the array to determine whether to highlight the field, but I don't know how to retrieve the index number. Is there way to achieve something like the line below? I know cRecords.indexnumber = 0 is not correct/valid, but I'm looking for what that syntax might be.
<apex:column value="{!cRecord.Name}" style="{!IF(cRecords.indexnumber = 0),"background-color: green;",""background-color: white);"
Are you looking for something as explained in the below blog:
https://sites.google.com/site/infallibletechie/code-for-alternate-background-color-for-rows-in-a-pageblocktable
Code on the above link will help you color the bckgrd of the pageblocktable which you have created.
All Answers
Are you looking for something as explained in the below blog:
https://sites.google.com/site/infallibletechie/code-for-alternate-background-color-for-rows-in-a-pageblocktable
Code on the above link will help you color the bckgrd of the pageblocktable which you have created.
<apex:pageBlock >
<apex:variable var="i" value="{!0}"/>
<apex:pageBlockTable value="{!cRecords}" var="cRecord">
<apex:column >
<apex:variable var="i" value="{!i+1}"/>
</apex:column>
<apex:column value="{!cRecord.Name}" style="background-color:{!IF(i=1,'#00FF00','')}">
<apex:facet name="header">HCC</apex:facet>
</apex:column>
<apex:column value="{!cRecord.HCC_strNum__c}" style="background-color:{!IF(i=1,'#00FF00','')}">
<apex:facet name="header">HCC</apex:facet>
</apex:column>
<apex:column value="{!cRecord.Type__c}" style="background-color:{!IF(i=1,'#00FF00','')}">
<apex:facet name="header">Type</apex:facet>
</apex:column>
<apex:column value="{!cRecord.Confidence_Level__c}" style="background-color:{!IF(i=1,'#00FF00','')}">
<apex:facet name="header">Confidence Level</apex:facet>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>