0

I'm trying allow a user to sort the grid by a column who's value is derived:

     grid.addColumn(Category::getPath).setHeader("Path");
     grid.addColumn(category -> getCount(category))
                .setHeader("Packages")
                .setComparator((a,b) -> orderByCount(a, b));

    private int orderByCount(Category a, Category b)
    {
        Long acount = daoCategoryPackage.getCount(CategoryPackage_.category, a);
        Long bcount = daoCategoryPackage.getCount(CategoryPackage_.category, b);
        return acount.compareTo(bcount);
    }

The grid shows the 'sort' icon in the header and I can click the icon and it changes state (up arrow, down arrow, both arrows).

If I trace the code I can see that the grid attempts a sort as 'Grid:setSortOrder' is called and the columnKey in GridSortOrder is correct (col1).

However the orderByCount method is never called.

It feels like I need to add some other setting to the grid but the documentation makes no suggestion and looking at the api I can see anything obvious.

Brett Sutton
  • 3,900
  • 2
  • 28
  • 53

1 Answers1

0

It's not possible to know without seeing more of the code, but the problem is likely that you're using a lazy-loading dataprovider, which can't handle a comparator provided like that. If you look at the method's JavaDoc, you'll see: Sets a comparator to use with in-memory sorting with this column. Sorting with a back-end is done using setSortProperty(String...).

ollitietavainen
  • 3,900
  • 13
  • 30