且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何有条件地为表格单元格中的背景着色?

更新时间:2023-01-25 21:01:22

您也可以将css类添加到行和列中,以标识一个单元格. 使用dataTable的rowStyleClass属性(示例). 如果要为多行着色:

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;
}