Announcement Announcement Module
Collapse
No announcement yet.
List locale sorting/ordering on the view (client) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • List locale sorting/ordering on the view (client)

    Hi,

    is there any way to sorting/ordering a list in the browser (by clicking on arrow) by locale alphabetic order? Example: ascending hungarian alphatic order: 'a', '', 'b', 'c', 'cs', 'd', 'e', ''... and so on.
    When I use MutableSortDefinition (for a PagedListHolder) the words starting with '' put the end of the line, after 'z'. (Propably the english alphabetic order.). I tried RefreshablePagedListHolder too, but I had no success.

    What class should I use, or how can I force to use a locale ordering, or how can I implement my own sort definition? If you have any advice for my problem, please give an answer. Thanks a lot! (sorry for my english)

  • #2
    Dont know if you could consider sorting it on the clientside, but if, then jquery could help

    http://tablesorter.com/docs/

    Comment


    • #3
      I iced this problem for a while, but now I have to return...

      Thanks the tip sore, but the server only sends 1 page, not the whole list, so if I use a client side sorting (e.g: jQuery Javascript lib in browser) i will sorting only the actual page , so I need a server-side sorting solution.
      Any other idea? Anybody?

      Best regards!

      Comment


      • #4
        Are these records in a database? If so, what flavor?

        Comment


        • #5
          Yes, the records are in the DB, the server queries them (the result is about 1000 elements), then send to the browse only 20 elements (the actual page).
          When the user clicks on the sorting icon, I have to resort the whole list (on the server side - I guess), then send back the corresponding page to the browser client.
          (Sometimes 100 user use this web page at the same time, so the 1 page send back solution seems to be good.)
          Maybe I can order by in the select when I query from the DB, but I guess it's too slow...

          Comment


          • #6
            I personally find paginated sorting is always best achieved on the database & you can really benefit by only retrieving the size of the page you need.

            Comment


            • #7
              OK, I will make a try, thanks

              ...but I still don't understand how can I use MutableSortDefinition (or RefreshablePagedListHolder) to use a localized sorting, or how can I build it my Comparable or Collator class into the Controller to use a hungarian (or french, danish, .... non-english) alphabetic order in sorting
              Nobody run into this problem? German, swedish, chinese, polland, etc. programmers (they have so many non english letters) how use/implement the SortDefinition class?

              Comment


              • #8
                Collections.sort(yourListOfStrings, Collator.getInstance(LocaleContextHolder.getLocale ()));


                Make sure you are using the correct LocaleResolver so that the request is Hungarian or whatever.

                Comment


                • #9
                  Thanks bestguy,

                  I used Collections.sort(myList, new CustomizedComparator(property, sortOrder)) where CustomizedComparator implements Comparator, Serializable and override the compare method.

                  Code:
                  private static class CustomizedComparator implements Comparator,Serializable
                  {
                     private static final long serialVersionUID = 1L;
                     private String property;
                     @SuppressWarnings("unused")
                     private String sortOrder;
                     private int sortOrderValue;
                     private Collator coll;
                  
                     public CustomizedComparator(String property)
                     {
                        this(property, "asc");
                     }
                  
                     public CustomizedComparator(String property, String sortOrder)
                     {
                        this.property = property;
                        this.sortOrder = sortOrder;
                        sortOrderValue = 1;   // sortOrder is ascending
                        if ("desc".equals(sortOrder))
                           sortOrderValue = -1;
                  
                        Locale loc = new Locale("hu","HU");
                        coll = Collator.getInstance(loc);
                     }
                  
                     public int compare(Object obj1, Object obj2)
                     {
                        Object value1 = getValue(obj1, property);
                        Object value2 = getValue(obj2, property);
                  
                        if (value1 == null) return sortOrderValue * -1;
                        else if (value2 == null) return sortOrderValue;
                  
                        else if (value1 instanceof String && value2 instanceof String) return sortOrderValue * coll.compare(value1, value2);
                  
                        else if (value1 instanceof Byte && value2 instanceof Byte) return sortOrderValue * ((Byte)value1).compareTo((Byte)value2);
                  			
                        else if (value1 instanceof Short && value2 instanceof Short) return sortOrderValue * ((Short)value1).compareTo((Short)value2);
                  			
                        else if (value1 instanceof Integer && value2 instanceof Integer) return sortOrderValue * ((Integer)value1).compareTo((Integer)value2);
                  			
                        else if (value1 instanceof Long && value2 instanceof Long) return sortOrderValue * ((Long)value1).compareTo((Long)value2);
                  			
                        else if (value1 instanceof BigDecimal && value2 instanceof BigDecimal) return sortOrderValue * ((BigDecimal)value1).compareTo((BigDecimal)value2);
                  			
                        else if (value1 instanceof Float && value2 instanceof Float) return sortOrderValue * ((Float)value1).compareTo((Float)value2);
                  			
                        else if (value1 instanceof Double && value2 instanceof Double) return sortOrderValue * ((Double)value1).compareTo((Double)value2);
                  
                        else return sortOrderValue;
                     }
                  }
                  Thanks the help for everybody!

                  Comment

                  Working...
                  X