Overriding Grid's Default Sort Method

I’m using the pagination add-on so Vaadin 8’s default grid sorter only works on the first page. No problem, I’m using custom comparators inside the sort listener.

However, the default grid sorting is still occurring so it reconfigures the rows just prior to my sorting implementation doing the same, so it occurs twice. My Collection sort order is correct but when I set the rows into the grid they’re in a different order. I’m attributing this to the undesired default sorting behaviour. How do I ignore this?

I’ve tried to @Override all public sort methods inside Grid as per the [answer here]
(https://stackoverflow.com/a/32969630) but none of them are firing when I click the Grid’s header.

Please help.

public class MyGrid extends Grid<MyRow> {

    private final List<MyRow> rows = new ArrayList<>();
  
    @Override
    public void sort(String columnId) {
        System.out.println("not firing");
    }

    @Override
    public void sort(String columnId, SortDirection direction) {
     System.out.println("not firing");
    }

    @Override
    public void sort(Grid.Column column) {
       System.out.println("not firing");
    }

    @Override
    public void sort(Grid.Column column, SortDirection direction) {
       System.out.println("not firing");
    }
}

It’s probably the GridServerRPC calling setSortOrder(List<GridSortOrder> order, boolean userOriginated), which unfortunately is a private method; it should be straightforward to test with a debugger breakpoint. And GridServerRpcImpl is private too, registered in a constructor, so you can’t really replace that either… It seems the only way to fix it is to find out why the pagination add-on doesn’t work properly with sorting.

Thanks Thomas. I was finally able to solve the problem with your assurance of where to focus my attention. It was a matter of adding necessary comparators and also implementing custom sorting based on sort direction. I appreciate your reply. +1

You’re welcome :slight_smile: