The DataTable is a great control. My client would like the rows "zebra striped" i.e alternating colours. I could not find anything to do this, other than using conditional colouring with the rowStyleClass attribute and an expression.
This seems overkill for this particular usecase, is there a simpler and more CPU efficient way ?
DataTable control: Zebra striping
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
You can create a feature request for this, we haven't added alternating rows as ThemeRoller has none. Still rowStyleClass can be used though.
- bumble.bee
- Posts: 723
- Joined: 29 Sep 2010, 21:39
- Location: United States
floolshat - did you actually get this to work? It would seem zebra striping is not available at all due to the bug mentioned here:
http://primefaces.prime.com.tr/forum/vi ... f=3&t=5753
http://primefaces.prime.com.tr/forum/vi ... f=3&t=5753
No. It is nearly working. I found another posting which suggests using the following attribute on the datatable.
but, the problem is the first two <tr> have a class of row-0, rather than row-0 then row-1. So I have left it for the moment.
Code: Select all
rowStyleClass="row-#{rowIndex % 2}"
PrimeFaces 2.2 RC2 , Glassfish3.0.1 Mojarra 2.0.2, Netbeans 6.9.1 Java, Scala and AKKA
If the DataTables rows attribute is set to an even number, the following should work:
Code: Select all
<p:dataTable
...
rows="6"
rowIndexVar="rowIx"
rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'even-row' : 'odd-row'}"
>
This issue with the unusual behavior of rowIndexVar in the rowStyleClass has been fixed http://code.google.com/p/primefaces/iss ... il?id=1408. This means that
should work correctly now.
Code: Select all
<p:dataTable
...
rows="6"
rowIndexVar="rowIx"
rowStyleClass="#{rowIx mod 2 ne 0 ? 'even-row' : 'odd-row'}"
>
My datatable looks like this. The rowStyleClass discussed above, works fine. You then have to modify your css to provide the styles
style.css contains this
Code: Select all
<p:dataTable id="resultstable"
var="row"
value="#{p_entity.dataRows}"
paginator="true"
rows="20"
dynamic="true"
lazy="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,20,30,40,50"
rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'even-row' : 'odd-row'}"
rowIndexVar="rowIx"
rowEditListener="#{p_entity.rowEditListener}"
onRowEditUpdate ="growlmessages"
loadingMessage="#{resources.datatable_loading}"
emptyMessage="#{resources.datatable_no_data_found}"
selection="#{p_entity.selectedItems}"
>
style.css contains this
.ui-datatable .ui-datatable-data .even-row td{
background-color:#DDE3FD;
}
.ui-datatable .ui-datatable-data .odd-row td{
background-color:#C9D1F7;
}
PrimeFaces 2.2 RC2 , Glassfish3.0.1 Mojarra 2.0.2, Netbeans 6.9.1 Java, Scala and AKKA
-
- Information
-
Who is online
Users browsing this forum: Google [Bot] and 19 guests