9 Replies Latest reply on Mar 29, 2010 2:26 PM by rseely

    can't get dataTable to sort

      I have a dataTable that I can get sort icons to appear for in the header.  When I click on the headers, though, I can see that some AJAX action is fired off, but neither the data nor the sort icons changes.  I need help from someone who can point out the problem in this dataTable:


      <rich:dataTable
        rendered="#{mddb.dataList.size>0}" styleClass="growthDisplayDataTable"
        value="#{mddb.dataList}" var="dataItem" id="mdt" rowKeyVar="idx">

       

        <rich:column width="30%" id="mdtKeyColumn">
          <h:outputText styleClass="growthDisplayDataKeyColumn"
              value="#{idx+1}. #{dataItem.getValue()[0]}" />
        </rich:column>
         
        <rich:columns
          value="#{mddb.filteredDisplayColumns}"
          var="dispCol" index="columnIdx" width="#{dispCol.columnWidth}%"
          id="mdtColumn#{columnIdx}" sortable="true"
          sortBy="#{dataItem.getValue()[columnIdx+1]}"
          selfSorted="true"
          sortOrder="#{marketDisplayDataBean.getSortOrdering(dispCol,columnIdx)}"
          <f:facet name="header">
            <h:outputText value=" " />
          </f:facet>
          <h:outputText
            value="#{mdf.format(dispCol.formatIndex, dataItem.getValue()[columnIdx+1] * dispCol.formatMultiplier)}" />
        </rich:columns>
       
      </rich:dataTable>

       

      This markup is essentially translated from a backing bean that I was initially binding to b/c I didn't know how to accomplish what I needed to with markup alone.  Once I'd done that, of course, I understood how the markup needed to be structured, so I brought it to this.  I mention that only to say that my sortBy and output values, while different, did work as I have them defined with the backing bean.  Everything's working for me in the markup now except for the sorting.

       

      Thanks!

       

      Robert

        • 1. Re: can't get dataTable to sort
          nbelaevski

          Hi Robert,

           

          I think that data table cannot update sort order value by this expression: sortOrder="#{marketDisplayDataBean.getSortOrdering(dispCol,columnIdx)}" and that's causing problems. Try using static map for this.

          • 2. Re: can't get dataTable to sort
            ilya_shaikovsky

            if there are some problems listend in server log?

            http://livedemo.exadel.com/richfaces-demo/richfaces/columns.jsf - sample which works. So I guess there are problems with your sortBy, sortOrder definitions.

            • 3. Re: can't get dataTable to sort

              Thanks for the suggestion, Nick, but I can't seem to find a combination of changes to those two that helps.  This reworking of my rich:columns element was the closest that I could come to simplifying things:

               

              <rich:columns
                  value="#{marketDisplayDataBean.filteredDisplayColumns}"
                  var="dispCol" index="columnIdx" width="#{dispCol.columnWidth}%"
                  id="mdtColumn#{columnIdx}" sortable="true"
                  sortBy="#{dataItem.key}" selfSorted="true"
                  sortOrder="UNSORTED"
                  styleClass="growthDisplayDataColumn #{dispCol.align=='R' ? 'textAlignRight' : (dispCol.align=='C' ? 'textAlignCenter' : '')} #{marketTree.activeNode.properties.columnSortIndex==columnIdx ? 'highlightedDisplayDataColumn' : ''}">
                  <f:facet name="header">
                      <h:outputText value=" " />
                  </f:facet>
                  <h:outputText
                      value="#{dataItem.key}" />

              </rich:columns>

               

              In this case, dataItem.key is a unique integer, and without the more complex conditions and formatting, it still won't sort.  I have a spinner graphic that displays whenever AJAX requests are made to the server, and that spinner appears whenever I click a header to sort; so I know that the table is trying to do something ... I just don't know what.  Why would it need to send any information back to the server?  Can it not sorts its data client-side?

               

              All best,

              Robert

              • 4. Re: can't get dataTable to sort

                Thanks for your thoughts, Ilya ... please see my message above to Nick for more on sortBy and sortOrder changes.  I think that my problem is that I don't understand what the sort request is making a roundtrip to the server for.  Can the dataTable be sorted client-side?  Could I be missing something on the server side that it needs?

                 

                All best,

                Robert

                • 5. Re: can't get dataTable to sort

                  Also, Ilya, I don't see anything in my server logs.

                  • 6. Re: can't get dataTable to sort
                    nbelaevski

                    Robert,

                     

                    Sorting is done on the server-side, client-side sorting is not implemented.

                     

                    Please take a look at this issue: https://jira.jboss.org/jira/browse/RF-6234 .

                    1 of 1 people found this helpful
                    • 7. Re: can't get dataTable to sort

                      Thanks, Nick.  Is RichFaces sorting the table by itself on the server side, or does my bean need to provide any methods for it to be able to set the newly-sorted values?  I did try adding a setter method for the data that's being pulled in, but that didn't seem to help anything.  I suppose I'll try setting log4j to trace for RichFaces, and see if it turns up anything interesting.

                       

                      I'll take a look at your link over the next day or two ... got some new priority rearing its ugly head today.

                       

                      All best,

                      Robert

                      • 8. Re: can't get dataTable to sort
                        ilya_shaikovsky

                        Modifiable interface should be implemented by your model in order to implement sorting/filtering in your custom model. But RF has defaut implementation and wraps your model handling sorting and filtering if you not provided it. So in simplest case nothing required from you to make your data sortable. If you want to take a look at our models implementations - download sources for richfaces-demo application.

                        1 of 1 people found this helpful
                        • 9. Re: can't get dataTable to sort

                          Thanks for the help, guys.  It turned out to be the sortOrder issue that's described in the JIRA issue that Nick sent.  I did have to try a couple of different approaches, because my first attempt was to map the DisplayColumn entity that's used to define the columns to their respective Orderings in a HashMap and look those up, but that didn't work.  When I took the simpler approach of mapping the DisplayColumn's name (a String) to the Orderings, everything worked fine.

                           

                          All best,

                          Robert