Announcement

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

    Send a default sort specifier along with other any other applied on grid.

    Hi Isomorphic ,
    I want to always sort order by a default field (which is not displayed on grid as a field but part of response) first before any other sort applied on grid. This is the code I tried.

    Code:
    addSetSortHandler(event -> {
                      event.cancel(); //tried cancelling here and at the end of method as well
                      List<SortSpecifier> specifiers = new ArrayList<>();
                      specifiers.add(new SortSpecifier("default_order", SortDirection.ASCENDING));
                      specifiers.addAll(Arrays.asList(event.getSortSpecifiers()));
                      setSort(specifiers.toArray(new SortSpecifier[0]));
    });
    This is not working.


    Also tried changedHandler

    Code:
    addSortChangedHandler(event -> {
                     List<SortSpecifier> specifiers = new ArrayList<>();
                    specifiers.add(new SortSpecifier("default_order", SortDirection.ASCENDING));
                    specifiers.addAll(Arrays.asList(event.getSortSpecifiers()));
                    setSort(specifiers.toArray(new SortSpecifier[0]));
    });
    This solution works first time only. For ex : If I click on Name field to sort then this will sort by "default_order, name" and if I again click on name field then it stays ascending only.

    Any suggestion how can I do this. Thanks

    #2
    Both of your attempts have the same problem: when you call setSort(), the SetSortHandler and SortChangedHandler are going to be called again, resulting in infinite recursion - this is reported in the console, so make sure you pay attention to that.

    The solution is to adjust your handler code to do nothing if you are called as a result of your own call to setSort().

    Comment

    Working...
    X