Open ngonzalezpazFC opened 2 years ago
They are just one liners helper methods, but still interesting. I would improve the second one as this:
public static <T> List<GridSortOrder<T>> sortGridColumn(Column<T> column, SortDirection sortDirection) {
return Arrays.asList(new GridSortOrder<>(column, sortDirection));
}
Go ahead and create a PR.
I am using the methods from this utility class for configuring grids:
If a repository interface extends PagingAndSortingRepository (it can use Page findAll(Pageable pageable)), the grid can be configured as follows:
grid.setItems(query -> repository.findAll(PagingUtils.getLazyAndSortedPageable(query)).stream());
Grid handles the query parameters it needs while scrolling, so it gets lazy loaded, and the colums of String type values can be sorted. I also use the methodsortGridColumn
to set a default sort order, for example, sorting by "id" in ascending order:grid.sort(PagingUtils.sortGridColumn(grid.getColumnByKey("id"), SortDirection.ASCENDING));