4 Replies Latest reply on Feb 22, 2011 4:33 AM by Ilya Shaikovsky

    How to use external sorting for extendedDataTable in RichFaces 4 M6?

    David Vallner Newbie

      My JSF code is essentially the same as in http://docs.jboss.org/richfaces/latest_4_0_X/Component_Reference/en-US/html/chap-Component_Reference-Tables_and_grids.html#sect-Component_Reference-Table_sorting-External_sorting

       

      However, that doesn't seem to do anything - the table headers don't become links and clicking them does nothing. Am I supposed to create the sorting links and indicators manually? (If so, what does RichFaces do for me in this case, other than keep the sort order between requests?)

       

      My data table is backed by an ExtendedDataModel subclass that does pagination in the database. I need the sorting to also happen on the database over the entire dataset as well.

        • 1. How to use external sorting for extendedDataTable in RichFaces 4 M6?
          Ilya Shaikovsky Master

          check richfaces-showcase sample code. yes for now we have no built-in controls but providing only base attributes to map the sort orders and conditions.

           

          B.t.w. notice the refactoring Modifiable model -> Arrangeable model between 3.3.x and 4.x.

          1 of 1 people found this helpful
          • 2. How to use external sorting for extendedDataTable in RichFaces 4 M6?
            David Vallner Newbie

            OK, so if I figured things out right, you're supposed to:

             

            1. Bind the sortOrder and sortPriority attributes to a backing bean. Also define the sortBy attributes to contain something useful. (In my case it was column names.)

            2. Implement your own sortBy() methods. In those methods manage the sortOrder and sortPriority collections yourself.

            3. What RichFaces seems to do for you is that it takes the values of sortOrder and sortPriority, and calls Arrangeable.arrange() with them.

             

            What I don't know is: how does step 3 work? I only have column names and SortOrder values in those collections, but arrange() gets called with ValueExpressions.

             

            What I'm also missing however is preserving the sortOrder / sortPriority between requests - right now I can only get this to work by declaring my bean as @ViewScoped. If I use @RequestScoped my sortOrder and sortPriority are empty every time sortBy is called. Shouldn't data tables save their sorting / filtering state like a datascroller does?

            • 3. Re: How to use external sorting for extendedDataTable in RichFaces 4 M6?
              Ilya Shaikovsky Master
              1. Bind the sortOrder and sortPriority attributes to a backing bean. Also define the sortBy attributes to contain something useful. (In my case it was column names.)

               

              not column names but object properties should be there. like #{tableVar.objectProp}

               

              What I'm also missing however is preserving the sortOrder / sortPriority between requests - right now I can only get this to work by declaring my bean as @ViewScoped. If I use @RequestScoped my sortOrder and sortPriority are empty every time sortBy is called. Shouldn't data tables save their sorting / filtering state like a datascroller does?

              When the table will be added with built-in control it will be like you describing. Als it's already works in that way if just use sorting JS API (without having to manage the sortOrder on your own). check the richfaces-showcase. ComponentControl sample in Misc contains sample of filtering with JS API and you could do the same for sorting. Then you will not have to store sort order on your own.

              • 4. Re: How to use external sorting for extendedDataTable in RichFaces 4 M6?
                Ilya Shaikovsky Master

                here is even more simple example:

                <h:form>

                                    <rich:dataTable value="#{capitalsBean.capitals}" var="cap" id="table">

                                              <rich:column sortBy="#{cap.name}" id="name">

                                                        <f:facet name="header">

                                                                  <a4j:commandLink value="Sort by Capital Name" onclick="#{rich:component('table')}.sort('name')"/>

                                                        </f:facet>

                                                        <h:outputText value="#{cap.name}" />

                                              </rich:column>

                                    </rich:dataTable>

                          </h:form>