conditional formatting in datatable

UI Components for JSF
Post Reply
AxonIDI
Posts: 5
Joined: 24 Sep 2011, 10:08
Location: Internet

30 Oct 2011, 08:03

how can i conditionally highlight/color a row based on the date value of that row...

i searched around and found that i can use the rowStyleClass property of the datatable and make it point to a bean so the bean will return a string that corresponds to a class in the CSS...

however, how do i get each row's data in the getter of that string property...

at the datatable,
rowStyleClass=#{bean.rowStyleClass}

in the bean,
public String getRowStyleClass() {
if (this) {
return "this color"
else {
return "that color"
}

another way i know of is to use the "if else" statements in the expression languages, but how do i compare dates there?

if the date is 30 days ago, highlight it...
PrimeFaces 2.2.1 + NetBeans 7.0.1 + GlassFish 3.1.1 + MySQL 5.5.12

byr
Posts: 13
Joined: 28 Oct 2011, 13:51

30 Oct 2011, 09:55

Hi!

What I do in such cases, that I add a true/false boolean or 0-1 integer column in my datamodel, and set it accordingly to my formatting criteria. Then I use this "hidden" column in the rowStyleClass property or any style property with a simple EL expression like #{data.colorcolumn == true ? 'color: red' : 'color: white'} or similar.

byr
Jboss AS 7.1.1, JSF 2.1.14, PrimeFaces 3.5 SNAPSHOT

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 39 guests