4 Replies Latest reply on Mar 1, 2010 4:58 AM by damianharvey

    Sorting using rich:columns

    damianharvey

      Hi all,

       

      I'm trying to use rich:columns to implement column re-ordering. I realise that this feature is part of the extendedDataTable however for this project I can't use it.

       

      Using rich:columns I can display the columns as I want and all looks ok, however the sorting just won't work. The messages gets posted back to the server however the response doesn't render a sorted table.

       

      Here is the relevant part of my page:

       

      <rich:dataTable
            id="Tpdsie"
            value="#{poDetailTableList}"
            sortMode="single"
            selectionMode="single"
            noDataLabel="#{noDataLabel}"
            var="pdsi">
          <rich:column status="STts" id="Cb" sortable="true" label="SKU" sortBy="#{pdsi.poDetail_sku}" rendered="#{poTableColumnManager.isSelectedColumn('SKU')}">
              <f:facet name="header">SKU</f:facet>
              #{pdsi.poDetail_sku}
          </rich:column>
          <rich:columns id="#{column.id}" value="#{poDetailColumns}" var="column" index="ind" sortBy="#{pdsi[column.value]}" rendered="#{column.rendered}">
              <f:facet name="header">
                  #{column.label}
              </f:facet>
              #{pdsi[column.value]}
          </rich:columns>
      </rich:dataTable>

       

      Note that the first column is there to test the sorting. Clicking on that works fine. Clicking on the same column rendered via rich:columns produces the same (very similar) AJAX message, but the while the sorting on the first column works, the second doesn't.

       

      The column model is :

       

      public class PoTableColumn {

       

          private int sequence;
          private String label;
          private String id;
          private boolean sortable;
          private String sortBy;
          private boolean rendered;
          private String value;

          public PoTableColumn(
                  int sequence,
                  String label,
                  String id,
                  boolean sortable,
                  boolean rendered,
                  String value) {
              this.sequence = sequence;
              this.label = label;
              this.id = id;
              this.sortable = sortable;
              this.rendered = rendered;
              this.value = value;
          }

       

      And the code that creates these columns is :

       

          @Factory("poDetailColumns")
          public List<PoTableColumn> getPoDetailColumns() {
              List<PoTableColumn> cols = new ArrayList<PoTableColumn>();
              cols.add(new PoTableColumn(1, "SKU", "Csku", true, true, "poDetail_sku"));
              cols.add(new PoTableColumn(2, "Description", "Cdes", true, true, "poDetail_description"));

              return cols;
          }

       

       

      I suspect that I've missed something in how the sort attribute is supposed to be defined but I can't see it. The examples are based on sorting by one column (price). Can anyone point me in the correct direction?

       

      Thanks,

       

      Damian.

        • 1. Re: Sorting using rich:columns
          eugenbesel

          Hello Damian,

           

          for sorting you should use SortOrder-attribute also.

           

          I have implemented it and it works fine.

           

          sortOrder="#{col.sortOrder}"

           

          take a look at example

          http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=modifiableDataModel&cid=5372498

          • 2. Re: Sorting using rich:columns
            damianharvey

            Thanks Eugene,

             

            [EDITED]: Good call thanks. I see it can't be the string literal of the Ordering enum eg. "UNSORTED". It needs to be passed to the attribute as a value of type Ordering.

             

            My column model now looks like this:

             

            public class PoTableColumn {

                private int sequence;
                private String label;
                private String id;
                private boolean sortable;
                private Ordering sortOrder;
                private boolean rendered;
                private String value;

                public PoTableColumn(int sequence, String label, String id, boolean sortable, Ordering sortOrder, boolean rendered, String value) {
                    this.sequence = sequence;
                    this.label = label;
                    this.id = id;
                    this.sortable = sortable;
                    this.sortOrder = sortOrder;
                    this.rendered = rendered;
                    this.value = value;
                }
            }

             

            Cheers,

             

            Damian.

             

            Message was edited by: Damian Harvey. Resolved issue.

            • 3. Re: Sorting using rich:columns
              eugenbesel

              my code looks like:

               

              <rich:columns id="col_#{col}" value="#{searchModul.columns}"
                               var="col" index="ind"
                               filterBy="#{data[ind]}" filterEvent="onkeyup" sortBy="#{data[ind]}"
                               sortOrder="#{searchModul.sortOrders[col]}"
                              filterValue="#{searchModul.columnFilterValues[col]}">

               

               

              Bean:

               

              public Map<String, Object> getSortOrders() {
                      return sortOrdersValues;
                  }

               

                  public void setSortOrders(Map<String, Object> sortOrders) {
                      this.sortOrdersValues = sortOrders;
                  }

              • 4. Re: Sorting using rich:columns
                damianharvey

                Thanks Eugene. Had found the issue between my post and my edit.

                 

                Cheers,

                 

                Damian.