简体   繁体   English

行颜色jsf primeFaces

[英]row color jsf primeFaces

I am using datatable and each row in table should have different color according to a value of one of the property of row StatutTicket this my code view: 我使用datatable和各row表应根据行的属性之一的值有不同的颜色StatutTicket这是我的代码视图:

<p:dataTable id="dataTickets" var="ticket"
        rowStyleClass="#{ticket.statutTicket.libelleStatutTicket == 'En attente' ? 'background-color:red': 'background-color:red'}"
        value="#{ticketBean.tickets}">
        <p:column headerText="N Ticket" sortBy="#{ticket.idTicket}"
            filterBy="#{ticket.idTicket}">
            <h:outputText value="#{ticket.idTicket}" />
        </p:column>
        <p:column headerText="Statut Ticket">
            <h:outputText value="#{ticket.statutTicket.libelleStatutTicket}" />
        </p:column>

</p:dataTable>

But the color of the column still not change and the error not appear 但是列的颜色仍然没有改变并且没有出现错误

Actually rowStyleClass attribute accept css class-type instead of direct using as 实际上rowStyleClass属性接受css类类型,而不是直接使用as

rowStyleClass="#{ticket.statutTicket.libelleStatutTicket eq 'En attente' ? 'background-color:red': 'background-color:red'}"

Use something like this. 使用这样的东西。

rowIndexVar="rowIndex"
rowStyleClass="#{(rowIndex mod 2) eq 0 ? 'redClass': 'blueClass'}"

And add this class in your css file as so that you will have two different color for two consecutive rows. 并在css文件中添加此类,以使连续两行具有两种不同的颜色。

.redClass {
    background-color:red;
}
.blueClass {
    background-color:red;
}

Try comparison of Strings using eq instead of == . 尝试使用eq而不是==比较字符串。 Or consider using the backing bean to determine the styleClass , eg: 或考虑使用辅助bean来确定styleClass ,例如:

rowStyleClass="#{ticketBean.styleClass(ticket)}"

It is work for me. 对我来说是工作。

    .rowWarnning {
        background-color: #FF9933 !important;
        background-image: none !important;
        color: #000000 !important;
    }

    <p:dataTable id="dataTickets" var="ticket"
        rowStyleClass="#{ticket.statutTicket.libelleStatutTicket == 'En attente' ? 'rowWarnning': null}"
        value="#{ticketBean.tickets}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM