7 Replies Latest reply on May 12, 2007 7:42 PM by flow1986

    how to make a column in dataTable sortable?

    vh

      I didn't find the attributes to make a table column sortable.

      and can I plugin my own sorting function?

        • 1. Re: how to make a column in dataTable sortable?

          You can do something like this:

          <h:dataTable id="dataTable" value="#{yourbean.yourdata}" var="row">
           <h:column>
           <f:facet name="header">
           <a4j:commandLine value="Column 1" action="#{yourbean.sortColumn1}" reRender="dataTable" />
           </f:facet>
           <h:outputText value="#{row.attribute1}" />
           </h:column>
           <h:column>
           <f:facet name="header">
           </f:facet>
           <h:outputText value="#{row.attribute2}" />
           </h:column>
          </h:dataTable>

          where yourdata is a list of beans containing attribute1 and attribute2. This is the sortColumn1 method:
          public String sortColumn1() {
           // sort your yourdata list
           return null;
          }

          and don't forget to put the <h:dataTable> in a <h:form>.

          • 2. Re: how to make a column in dataTable sortable?
            vh

            So there is no build in suport for sorting? (I have to do everything myself?).
            Do I need to remember which column and which order I am soring in etc?

            • 3. Re: how to make a column in dataTable sortable?

              So, as dxxvi suggested, you need one command on the page and one method in java. What else is needed to just go ahead?

              P.S. Sounds curiously, but built-in support will require much more steps from your side to customize it.

              • 4. Re: how to make a column in dataTable sortable?
                vh

                In woodstock, by default all the table columns are sortable based on the datatype in that column.

                There is an attribute in woodstock to tell which column you want to initially sort on and the order. It also shows a small arrow in the column header to indicate the order.

                Think that might be useful.

                • 5. Re: how to make a column in dataTable sortable?
                  ilya_shaikovsky

                  Such component planned, and the one reason it was planned so far from initial releases as Sergey already said - that there are not so large work to write own sorting method and use ajax-ed controls in headers for example.

                  • 6. Re: how to make a column in dataTable sortable?

                     

                    "vh" wrote:
                    In woodstock, by default all the table columns are sortable based on the datatype in that column.

                    There is an attribute in woodstock to tell which column you want to initially sort on and the order. It also shows a small arrow in the column header to indicate the order.

                    Think that might be useful.
                    So, in woodstock, does it sort the data table by comparing the Java objects or does it allow us to specify a sort method where we can compare Java objects or do a sql statement?

                    • 7. Re: how to make a column in dataTable sortable?
                      flow1986