How to conditionally style a row in a rich:dataTable

后端 未结 7 1457
攒了一身酷
攒了一身酷 2021-02-07 02:12

How can I change the style of a particular row based on a condition? I can use JSF EL in rich:column style class attribute, but I have to write for each column. I want to change

7条回答
  •  别那么骄傲
    2021-02-07 02:40

    Use rowClasses ... You can set a nice zebra style for example, and set a particular color when your value is set to what you want :

    Here an example where my value is a boolean. (rowkey is the index of each row, you have to set it as this in rich:datatable :

    rowKeyVar="rowkey"

    rowClasses="#{myBean.is_validValue == false ? (rowkey mod 2 == 0 ? 'order-table-even-row' : 'order-table-odd-row') : 'found'}"

    I set Found class style when ma value == true.

    CSS:

    .found
    {
    background-color: #FACC2E;
    }   
    .order-table-even-row
    {
    background-color: #FCFFFE;
    }
    
    .order-table-odd-row
    {
    background-color: #ECF3FE;
    }
    

提交回复
热议问题