2 Replies Latest reply on Aug 19, 2011 9:34 AM by h2g2

    How can one ignore null/empty values in rich:column when sorting?

    h2g2 Newbie

      Hi,

       

      I know this question is often poped up, and I read some threads about it, but since I was unable to get a suited answer to it (or one that I could manage to make it work), I will perform one more popup.

       

      I would like to ignore all null/empty values when sorting a rich:column in a datatable (all columns can be used to sort the data). I can't change the model of the data I am displaying, which are all primitive or semi-primitive (String, int, double, etc.). I thus cannot implement the interface "comparable" on each of my field ; I have to work with them and find another way to do a custom sorting so that the null/empty values are always displayed at the end, whatever the sort order is.

       

      Any of you have an idea on how to do this?

       

       

      <rich:dataTable 
        value="#{contact.contactDataModel}"
        var="varContact"
        columns="9">
        <rich:column sortBy="#{varContact.gender}">
          <f:facet name="header">
            <h:outputText value="#{bundle.gender}" />
          </f:facet>
          <h:outputText
            value="#{bundle.gender_m}"
            rendered="#{varContact.gender == '0'}" />
          <h:outputText
            value="#{bundle.gender_f}"
            rendered="#{varContact.gender == '1'}" />
        </rich:column>       
        <rich:column
          id="lastnameColumn"
          sortBy="#{varContact.lastname}">
          <f:facet name="header">
            <h:outputText value="#{bundle.lastname}" />
          </f:facet>
          <h:outputText
            value="#{varContact.lastname}"
            id="lastname" />
        </rich:column>
        <rich:column
          id="firstnameColumn" sortBy="#{varContact.firstname}">
          <f:facet name="header">
            <h:outputText value="#{bundle.firstname}" />
          </f:facet>
          <h:outputText
            value="#{varContact.firstname}"
            id="firstname" />
        </rich:column>
        ...
       </rich:dataTable>
      

       

      Thanks for having a look at this, and -if applicable- for your solution