File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Specifying row classes in dataTables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Specifying row classes in dataTables" Watch "Specifying row classes in dataTables" New topic
Author

Specifying row classes in dataTables

Jamie Williams
Ranch Hand

Joined: Mar 31, 2006
Posts: 70
I need to specify a different coloured background for a row in a datatable based depending on the properties of my dataTable value. I am already using the 'rowClasses' property of the dataTable to produce alternating light and dark rows, but I need to specify for some elements that the row is all very dark. Is this possible?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Yes. You can change the class based on any condition.
Jamie Williams
Ranch Hand

Joined: Mar 31, 2006
Posts: 70
umm... how? thanks for replying!
madhuri madhuri
Ranch Hand

Joined: Jan 18, 2006
Posts: 58
I am looking forward for some help on the same. I would appreciate if anyone can put forth their thoughts how this can be done.

Thanks in Advance,


~Madhuri
madhuri madhuri
Ranch Hand

Joined: Jan 18, 2006
Posts: 58
is there anybody in the group who could throw some light on this . I am badly stuck here ( ( (
Jamie Williams
Ranch Hand

Joined: Mar 31, 2006
Posts: 70
Yes, please help! I am unable to find anything on this anywhere!
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
rowClasses can be a comma-delimited list of CSS style classes for the rows. Like we can specify multiple styles for a row by separating them with a
space in HTML. Here, after each style has been applied, they repeat.

So, we can check which list of classes or a class we need to add in rowclasses. We can alter the renderer for this. Or I think we can use JSTL for this.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
you can define a method like
boolean isHighlighted(){
}
to use it with JSTL.

In that method you can put your logic and use that method inside rowClasses attribute usign JSTL, something like below
if true .. then .. x-row .. else ..normal-ones

Just an idea.
[ May 26, 2006: Message edited by: Adeel Ansari ]
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
One idea is to use styleClass in addition to rowClasses. Condition styleClass to override rowClasses


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
madhuri madhuri
Ranch Hand

Joined: Jan 18, 2006
Posts: 58
Originally posted by Bruce Jin:
One idea is to use styleClass in addition to rowClasses. Condition styleClass to override rowClasses


I have tried this approach but it does not color the entire row it just highlights the text in the cell.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by madhuri madhuri:
I have tried this approach but it does not color the entire row it just highlights the text in the cell.


Could you please send your resulted HTML code. I think it should work with <td>.
madhuri madhuri
Ranch Hand

Joined: Jan 18, 2006
Posts: 58
Originally posted by Adeel Ansari:


Could you please send your resulted HTML code. I think it should work with <td>.


madhuri madhuri
Ranch Hand

Joined: Jan 18, 2006
Posts: 58
Originally posted by Adeel Ansari:


Could you please send your resulted HTML code. I think it should work with <td>.


Can anybody please tell me where am i going wrong...?
Jamie Williams
Ranch Hand

Joined: Mar 31, 2006
Posts: 70
It would be really helpful if someone could just post the JSF code for the dataTable showing how to condition the rowClass/styleClass or whatever needs to be done.

If you know how to do it please share your knowledge with us!
Jamie Williams
Ranch Hand

Joined: Mar 31, 2006
Posts: 70
Can anyone out there supply some JSF code for this?
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
I needed to highlight some rows in orange based on some condition in addition to alternating the row colors. I used this way in my code and it works for me:
For the datatable, I removed the attribute rowClasses and added the attribute rowStyleClass like "#{tableData.style}" where style is a method in my tableData(managed bean) class returning a String. This method has code like this:
public String style(){
Account styleAccount = (Account)table.getRowData();
if (styleAccount.getMyProperty.equals("condition"){

return "highlightedStyleClass";
}
else
if (table.getRowIndex() % 2 == 0){
return "evenRowStyleClass";
}
else
{
return "oddRowStyleClass";
}
}
-----------
My datatable rows represent account objects and 'table' is UIData bound to datatable.
BTW I am using Tomahawk. I have not tried with others, but I hope you get an idea with this.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Specifying row classes in dataTables
 
Similar Threads
Adding subrow with additional information for each row in dataTable
how to select a row datatable
Accessing a dataTable's row in javascript
JSF,marked a selected row of datatable
calling action method on data table row click