2 Replies Latest reply on Jun 12, 2008 3:18 PM by Sergey Smirnov

    rich:dataTable Different colors for rows?

    Victor Manuel Ojeda Valiente Newbie

      Hi all,

      I want to put a different color in each row according to a property in my bean. Is that possible? If yes, how? I can change the background color of an output text control but I don't know how change the whole row? Any ideas?

      Thanks in advance,

      Victor

      Some code follows

      <rich:dataTable id="operationOrdersList" rows="10"
       value="#{operationOrdersByPriority}" var="operationOrder" width="100%" columnsWidth="7%,5%,16%,14%,16%,12%,11%,9%,10%">
      
       <f:facet name="header">
      
       <rich:columnGroup>
      
       <h:column>
       <h:outputText value="#{messages['number']}" styleClass="columnHeader"/>
       </h:column>
       <h:column>
       <h:outputText value="#{messages['date']}" styleClass="columnHeader"/>
       </h:column>
       <h:column>
       <h:outputText value="#{messages['responsible']}" styleClass="columnHeader" />
       </h:column>
       <h:column>
       <h:outputText value="#{messages['division']}" styleClass="columnHeader" />
       </h:column>
       <h:column>
       <h:outputText value="#{messages['customer']}" styleClass="columnHeader" />
       </h:column>
       <h:column>
       <h:outputText value="#{messages['detail']}" styleClass="columnHeader" />
       </h:column>
       <h:column>
       <h:outputText value="#{messages['followUpStatus']}" styleClass="columnHeader" />
       </h:column>
       <h:column>
       <h:outputText value="#{messages['priority']}" styleClass="columnHeader"/>
       </h:column>
       <h:column>
       <h:outputText value="#{messages['daysLeftToLimitDate']}" styleClass="columnHeader"/>
       </h:column>
      
       </rich:columnGroup>
      
       </f:facet>
      
       <h:column>
       <s:link id="operationOrderNumberId" value="#{operationOrder.operationOrderNumber}" action="#{operationOrdersByPriorityAction.select(operationOrder)}"/>
       </h:column>
       <h:column>
       <h:outputText value="#{operationOrder.operationOrderDate}" style="#{operationOrder.style}">
       <f:convertDateTime dateStyle="short"/>
       </h:outputText>
       </h:column>
       <h:column>
       <h:outputText value="#{operationOrder.responsibleName}" style="#{operationOrder.style}"/>
       </h:column>
       <h:column>
       <h:outputText value="#{operationOrder.divisionName}" style="#{operationOrder.style}"/>
       </h:column>
       <h:column>
       <h:outputText value="#{operationOrder.accountName}" style="#{operationOrder.style}"/>
       </h:column>
       <h:column>
       <h:outputText value="#{operationOrder.description}" style="#{operationOrder.style}"/>
       </h:column>
       <h:column>
       <h:outputText value="#{operationOrder.followUpStatusName}" style="#{operationOrder.style}"/>
       </h:column>
       <h:column>
       <h:outputText value="#{operationOrder.priorityName}" style="#{operationOrder.style}"/>
       </h:column>
       <h:column>
       <h:outputText value="#{operationOrder.daysLeftToLimitDate}" style="#{operationOrder.style}"/>
       </h:column>
      
       <f:facet name="footer">
       <rich:datascroller/>
       </f:facet>
      
       </rich:dataTable>
      


      where sytle is a property in the OperationOrder bean with a value like

      background-color:#FF0000


        • 1. Re: rich:dataTable Different colors for rows?
          leandro godoy Apprentice

          I did this on the lines of my table as follows:

          <rich:column filterBy="#{cr.contasreceberid}" filterEvent="onkeyup"sortBy="#{cr.contasreceberid}" width="5">
           <f:facet name="header">
           <h:outputText value="#{msg.pesq}"></h:outputText>
           </f:facet>
           <center>
           <h:outputText value="#{cr.contasreceberid}"
           styleClass="#{cr.situacao=='PAGO'? 'aberto' : cr.situacao=='ABERTO'? 'fechado':'erro' }">
           </h:outputText>
           </center>
          
           </rich:column>
          



          the lines are colored according to the situation of the request, if the application is open use a class css for coloring the line was closed this use another and so on.

          • 2. Re: rich:dataTable Different colors for rows?
            Sergey Smirnov Master

            If you doing like that you stylize the table cell, but not the table row. It might be difference if you use paddings and margins inside the table.
            rich:ColumnGroup is a component that produces TR. Applying style to it means applying style to row.