rich:datatable - Way to sort rowClasses?
zbandersnatch Jul 28, 2008 3:12 AMHi all,
I'm building an event tracking system and would like to use the rowClasses attribute of rich:datatable to apply different background colors to each row based on their priority. This works ok:
<rich:dataTable id="evttable" value="#{eventAction.eventList}" var="evt" ... rowClasses="#{eventAction.rowClasses}"> <rich:column id="priorityId" sortBy="#{evt.priority}"> <f:facet name="header"><h:outputText value="Priority" /></f:facet> <h:outputText value="#{evt.priorityName}"/> </rich:column> <rich:column id="type" sortBy="#{evt.type}"> <f:facet name="header"><h:outputText value="Type" /></f:facet> <h:outputText value="#{evt.typeName}"/> </rich:column> ...
with the corresponding getRowClasses() method in the bean returning a comma-delimited list of CSS style classes based on the priority of each event. However, upon sorting the table data (by clicking on column headers) the row styles do not "stick" to the rows--even though the data is rearranged, the row styles stay the way they were before the sort.
What I'd like to be able to do is something like this:
<rich:dataTable id="evttable" value="#{eventAction.eventList}" var="evt" ... rowClasses="#{evt.rowClass}">
where the rowClasses attribute would iterate over the eventList collection, as the datatable does when displaying data for each row. I've tried this, but it doesn't work as the rowClasses attribute is expecting a String value rather than a collection.
The odd thing is, I've played with randomizing the order of the styles in getRowClasses(), and the new styles *are* displayed when the table is re-rendered. It's meaningless, though, unless I can find a way to match the style order with the way the data is sorted. If I could somehow send the sort criteria back to the bean, I could modify getRowClasses() to send back the styles in the correct order.
Does anyone know of a way to do this? I've tried attaching actions to the column headers, but that doesn't work. Is there a method to retrieve the sort order somehow, either through a datatable attribute (stateVar looked promising, but I can't find any documentation on how to use it) or even through JavaScript?
Any help would be very much appreciated!
ZB