How do I conditionally color the background in a table cell?

前端 未结 2 1391
难免孤独
难免孤独 2020-12-29 15:43

I am rendering a table with p:dataTable (PrimeFaces) and what I want to do is color the background of cells depending on the value of their content. This i

相关标签:
2条回答
  • 2020-12-29 16:17

    You can add a css class to the row and to the column too, that identifies a cell. Use the dataTable's rowStyleClass attribute (example). If you want to color multiple rows:

    <p:dataTable value="#{bean.rows}" var="rowVar"
         rowStyleClass="#{rowVar.firstCol gt 0 ? 'firstColColored' : ''}
                               #{rowVar.secondCol gt 0 ? 'secondColColored' : ''}">
         <p:column styleClass="firstCol">...
         <p:column styleClass="secondCol">
    

    css:

    .firstColColored .firstCol {
         background: pink;
    }
    
    0 讨论(0)
  • 2020-12-29 16:18

    how about adding padding to your class , with px or percents...

    something like this

    .colored{
        background-color:yellow;
        padding-top:25px;
        padding-bottom:25px;
        padding-right:50px;
        padding-left:50px;
    }
    
    0 讨论(0)
提交回复
热议问题