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.