I need to change the row color depending on the values of a picklist field in a column:
<apex:pageBlockTable value="{!pagoList}" var="pg">
<apex:column headerValue="Name">
<apex:inputField value="{!pg.Name}" />
</apex:column>
<apex:column headerValue="Tipo">
<apex:inputField value="{!pg.Tipo__c}" />
</apex:column>
<apex:column headerValue="Otros tipos">
<apex:inputField value="{!pg.OtrosTipos__c }" />
</apex:column>
<apex:column headerValue="Importe">
<apex:inputField value="{!pg.Importe__c}" />
</apex:column>
<apex:column headerValue="Forma de Pago">
<apex:inputField value="{!pg.FormaPago__c}" />
</apex:column>
</apex:pageBlockTable>
This code is rendering this:
being the field 'Tipo__c' the 'type' of object ....
My requirement is to highlight the rows with a color where Tipo__c equals some values in the picklist. Tipo__c is the picklist field.
I've been reading and trying diferent things like this one but nothing seems to work.
This new code:
<style>
.greenColour {background-color:green;}
.redColour {background-color:red;}
.greyColour {background-color:grey;}
</style>
<script>
var redRow = document.getElementsByClassName("redColour");
var greenRow = document.getElementsByClassName("greenColour");
var greyRow = document.getElementsByClassName("greyColour");
for(var i=0;i<redRow.length;i++){
redRow[i].parentNode.className = "redColour";
}
for(var i=0;i<greenRow.length;i++){
greenRow[i].parentNode.className = "greenColour";
}
for(var i=0;i<greyRow.length;i++){
greyRow[i].parentNode.className = "greyColour";
}
</script>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!QuikSave}" value="Guardado rapido"/>
<apex:commandButton action="{!Save}" value="Guardar"/>
<apex:commandButton action="{!Cancel}" value="Cancelar"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Cuadre">
<apex:outputField value="{!Cuadre__c.Name}"/>
<apex:outputField value="{!Cuadre__c.Diferencia__c}"/>
<apex:outputField value="{!Cuadre__c.ImporteCompra__c}"/>
<apex:outputField value="{!Cuadre__c.PendienteCobro__c}"/>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!pagoList}" var="pg">
<apex:column headerValue="Name">
<apex:inputField value="{!pg.Name}" />
</apex:column>
<apex:column value="{!pg.Tipo__c }"
styleClass = "{! If(pg.Tipo__c=='Transferencia' ,'redColour',
If(pg.Tipo__c=='Cheque Bancario Nominativo','greenColour', 'greyColour')) }" />
<apex:column headerValue="Tipo">
<apex:inputField value="{!pg.Tipo__c}" />
</apex:column>
<apex:column headerValue="Otros tipos">
<apex:inputField value="{!pg.OtrosTipos__c }" />
</apex:column>
<apex:column headerValue="Importe">
<apex:inputField value="{!pg.Importe__c}" />
</apex:column>
<apex:column headerValue="Forma de Pago">
<apex:inputField value="{!pg.FormaPago__c}" />
</apex:column>
</apex:pageBlockTable>
is rendering this page:
but the Tipo field is not rendering as it should (a picklist) and also the row is not hightlighting, only the field.
Any idea on how to achieve this ?