jsf-2primefaces

Changing background color for non-header cells in column of p:dataTable


I would like to know how to set up background color for a specific column in a datatable.I have tried the below css code

.mystyle.ui-datatable .ui-datatable-data td, .mystyle.ui-datatable .ui-datatable-data td{
background-color:#B5D3A5;   
}  

But the above seems to change the background color for all the columns in the datatable. Please let me know how to change the background color for a specific column in the datatable. Thanks in Advance


Solution

  • You can use the style and styleClass attributes of p:column for this:

    <p:column style="background-color: red" ...>
    

    This will colorize table cells and header cells.

    If you don't want to change header cells you could do the following:

    Give the column a styleClass attribute:

    <p:column styleClass="foo" ...>
    

    And then add the following style definition to your css/html:

    td.foo {
        background-color: red;
    }