Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server-side DataTable Sorting in RichFaces

I have a data table with a variable number of columns and a data scroller. How can I enable server side sorting? I prefer that it be fired by the user clicking the column header.

<rich:datascroller for="instanceList" actionListener="#{pageDataModel.pageChange}"/>
<rich:dataTable id="instanceList" rows="10" value="#{pageDataModel}"
                var="fieldValues" rowKeyVar="rowKey">
  <rich:columns value="#{pageDataModel.columnNames}" var="column" index="idx">
    <f:facet name="header">
      <h:outputText value="#{column}"/>
    </f:facet>          
    <h:outputText value="#{classFieldValues[idx]}" />
  </rich:columns>
</rich:dataTable>

I already have a method on the bean for executing the sort.

public void sort(int column)
like image 335
sblundy Avatar asked Sep 25 '08 17:09

sblundy


3 Answers

I ended up doing it manually. I adding a support tag to the header text tag, like so.

<h:outputText value="#{column}">
  <a4j:support event="onclick" action="#{pageDataModel.sort(idx)}"
               eventsQueue="instancesQueue"
               reRender="instanceList,instanceListScroller"/>
</h:outputText>

To get the ascending/descending arrows, I added a css class.

<h:outputText value="#{column}" styleClass="#{pageDataModel.getOrderClass(idx)}" >
  <a4j:support event="onclick" action="#{pageDataModel.sort(idx)}"
               eventsQueue="instancesQueue"
               reRender="instanceList,instanceListScroller"/>
</h:outputText>
like image 187
sblundy Avatar answered Oct 26 '22 18:10

sblundy


There is a fairly elegant solution to this solution here:

http://livedemo.exadel.com/richfaces-demo/richfaces/sortingFeature.jsf?tab=ex-usage

This demo avoids using the tag.

like image 34
Marco Avatar answered Oct 26 '22 16:10

Marco


Your datamodel needs to implement "Modifiable" interface.

The datatable will call it's modify() method to do serverside sorting and filtering.

like image 1
Philipp Avatar answered Oct 26 '22 18:10

Philipp