2 Replies Latest reply on Apr 7, 2011 4:12 PM by siva999

    How to custom sort in columns always displaying null values at the end

    Anthony Ogier Newbie

      I'm using <rich:dataTable/> with some <rich:column/> columns.


      The data I want to display contains some null values on some properties.


      Basically, the sort feature of <rich:column/> is to display those null values on the top or bottom of the list, depending on the current sort direction value.


      I want to display those null values always on the bottom of the list... and I tried many ways... using a comparator for exemple. With a comparator, it's not possible because the method of my comparator doesn't know whether I'm sorting ascending or descending.


      Is any of you knows how to get the current sort direction of a column, in order to sort the null values always on bottom ?

        • 1. Re: How to custom sort in columns always displaying null values at the end
          Terry O'Malley Newbie

          A bit of a hack, but you can provide a label for the column and
          pass it to this method. This order can then be passed to your comparator.
          I am sure there are better ways, but this at least gets you the column sort order.


          private Ordering getColumnSortOrder (String columnLabel) {
          
           FacesContext facesContext = FacesContext.getCurrentInstance();
           HtmlDataTable htmlDataTable = (HtmlDataTable)facesContext.getViewRoot().findComponent("formId:tableId");
           Iterator<UIComponent> columns = htmlDataTable.columns();
          
           while (columns.hasNext()) {
                HtmlColumn column = (HtmlColumn) columns.next();
                String label = column.getLabel();
                if (StringUtils.equals(columnLabel, label))          {
                     Ordering order = column.getSortOrder();
                     return order;
                }
           }
           return Ordering.UNSORTED;
          }
          


          • 2. Re: How to custom sort in columns always displaying null values at the end
            siva999 Newbie

            Hi Anthony,
            I also need same funtionality. I am wondering whether you are able to resolve this issue and how?


            Siva