5 Replies Latest reply on Jul 7, 2008 9:10 PM by srinivasanrm

    Problem with sorting rich:dataTable

    lucab

      Hi all,
      we are trying to sort a table with the following code but it doesn't work:

      <h:form>
       <rich:dataTable value="#{bean.list}" var="riga">
       <rich:columns value="#{bean.keys}" var="col" index="id" sortBy="#{riga[id].value}">
       <f:facet name="header">
       <h:outputText value="#{col}"/>
       </f:facet>
       <h:outputText value="#{riga[id].value}" />
       </rich:columns>
       </rich:dataTable>
      </h:form>
      


      Can someone help us?
      ps.: we are using richfaces 3.2.0 on tomcat 6.0.

      Thank you

        • 1. Re: Problem with sorting rich:dataTable
          lucab

          please, also notice that our code is merely a cut and pasta from the sample code found on this page of the demo (http://livedemo.exadel.com/richfaces-demo/richfaces/columns.jsf?c=columns). Here is the code so you can easily compare the two:

          <h:form>
           <rich:dataTable value="#{dataTableScrollerBean.model}" var="model" width="750">
           <f:facet name="header">
           <h:outputText value="Cars Available"></h:outputText>
           </f:facet>
           <rich:columns value="#{dataTableScrollerBean.columns}" var="columns"
           index="ind" sortBy="#{model[ind].price}">
           <f:facet name="header">
           <h:outputText value="#{columns.header}" />
           </f:facet>
           <h:outputText value="#{model[ind].model} " />
           <h:outputText value="#{model[ind].mileage} miles " />
           <h:outputText value="#{model[ind].price}$"
           style="font-style:italic;" />
           </rich:columns>
           </rich:dataTable>
           </h:form>
          


          This snippet works although in the demo can be found similar examples that don't. We noticed during testing that when we click on the table header the hashcodes of the objects change. So perhaps we missed something in the documentation (or the docs are incomplete). Does the bean take care of ordering the column by itself? So, does clicking the header fire an AJAX request to the bean? If yes how are we supposed to intercept that?

          Many thanks in advance to any one will be so gentle to share his/her knowledge with us.

          • 2. Re: Problem with sorting rich:dataTable
            lucab

            we found a class Ordering in the model package. We think this will solve our sorting problem...

            • 3. Re: Problem with sorting rich:dataTable
              ilya_shaikovsky

              what about your JSF implementation?

              • 4. Re: Problem with sorting rich:dataTable
                lucab

                we solved our problem! it was our falut regarding a misconception about richfaces.

                • 5. Re: Problem with sorting rich:dataTable
                  srinivasanrm

                  I have been searching through the forums to find a solution to our sort issue and found your question relevant to our problem. We too have collection of strings (in your case it was a map of key/value) as our datamodel and we are trying to sort the scrollabledatatable work.

                  Here is our code:

                  <rich:scrollableDataTable height="370px" rows="25" sortMode="single" var="rowItem" value="#{report.resultList}" width="900px">
                   <rich:columns value="#{report.columns}" var="column" index="index" sortable="true" width="#{column.width}px">
                   <f:facet name="header">
                   <h:outputText title="#{column.title}" class="scrollTableHeader" value="#{column.name}"></h:outputText>
                   </f:facet>
                   <h:outputText value="#{rowItem[index]}" />
                   </rich:columns>
                  </rich:scrollableDataTable>
                  
                  


                  As you can see the data is not from a List. Instead its a list of strings (list<string[]>), so there is no column name I can specify for the sortexpression. Do you have any suggestion as how to specify the Sort expression in this case?

                  If you can post your solution as how you made sorting work in your case, I can get some idea from that too.

                  Thanks for your help.