1
            <p:dataTable id="test" value="#{test.attLogList}"
                 var="item" 
                 selection="#{test.searchedAttLogList}"
                 rowStyleClass="#{item.name eq 'abb' ? 'Closed' : null}"
                 rowKey="#{item.employeeNumber}">

            <p:column sortBy="#{item.employeeNumber}"
                headerText="#{o:translate('Employee')}">
                <h:outputText value="#{item.employeeNumber} " />
            </p:column>

css tag is

<style type="text/css">
        .Closed {
            background-color: #FF0000 !important;
            color: #000000 !important;
        }
</style>

I want to change row color in data table depend upon condition.Below code is working but only for First row it is not applying for remaining rows.The condition is applying for first row of datatable. kindly help me.

closed is a css tag

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Aishwarya Pal
  • 21
  • 1
  • 3
  • 1
    Possible duplicate of [How to conditionally render or style a row of primefaces dataTable?](https://stackoverflow.com/questions/36711029/how-to-conditionally-render-or-style-a-row-of-primefaces-datatable) – mariuss Oct 04 '18 at 12:01
  • Check with a browser developertool if it is overridden... And better to have the alternative be `''` instead of `null`. And also better to use more specific selectors than to use !important. See https://stackoverflow.com/questions/8578494/how-to-override-stylesheets-of-primefaces – Kukeltje Oct 04 '18 at 13:56
  • The data depending things are business things. You should make this kind of formatting in the `test` bean. (Where the list comes from) Bind the table component to a variable in this bean and call a method (for example getRowClass(rowIndex)) to format the table row. – The Bitman Oct 08 '18 at 06:18

1 Answers1

1

This worked for me

.yellowRaw {
    background: yellow  !important;
}
<p:dataTable rowStyleClass="#{not empty position.replacedBy?'yellowRaw':''}" ...>
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
fjkjava
  • 1,414
  • 1
  • 19
  • 24