Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Sort ListGrid Records by cell attribute

    Hey all,

    I have a list grid and one of the columns will contain the values {LOW, MED, HIGH}, when I attempt to sort this column it does it alphabetically.

    Is there anyway I can specify my own sorting algorithm for the column?

    #2
    You can create an invisible column with values derived from the real value: "0Low", "1Med", "2High". Then sort by this column.

    Comment


      #3
      Hi mgallagher,

      see ListGridField.setSortNormalizer().

      Best regards,
      Blama

      Comment


        #4
        Originally posted by Blama View Post
        Hi mgallagher,

        see ListGridField.setSortNormalizer().

        Best regards,
        Blama
        Perfect, that worked a treat!

        Here is the code if anyone cares:
        Code:
        severityField.setSortNormalizer(new SortNormalizer() {
            @Override
            public Object normalize(ListGridRecord record, String fieldName) {
                String highMedLow = record.getAttribute("AttributeName");
                Integer returnValue = 0;
                        
                returnValue = "HIGH".equalsIgnoreCase(highMedLow) ? 1000 : returnValue;
                returnValue = "MED".equalsIgnoreCase(highMedLow)  ? 100  : returnValue;
                returnValue = "LOW".equalsIgnoreCase(highMedLow)  ? 10   : returnValue;
                        
                return returnValue;
            }
        });

        Comment


          #5
          Note that, if the dataset exceeds dataPageSize and hence paging is introduced, the grid relies on the server to provide sorting, and the sortNormalizer will no longer be called.
          It works, but note this. If you got more than 75 records (or dataPageSize), this will not work, since the server will be in charge of the sorting.

          Comment


            #6
            Hi mgallagher, Hi edulid,

            please see also this thread for an enhancement coming in 5.1 regarding the limitation edulid mentioned.

            Best regards,
            Blama

            Comment

            Working...
            X