feat: added default sorting to grid

This commit is contained in:
filippo-ferrari 2024-07-15 19:38:43 +02:00
parent 3a2c1ff782
commit 435ddd65a2
3 changed files with 7 additions and 2 deletions

View file

@ -28,4 +28,5 @@ public interface ExpenseRepository extends JpaRepository<Expense, Long>, JpaSpec
Set<Expense> findUnpaidDebtorsExpensesByPersonId(@Param("personId") Long personId);
boolean existsByIdAndIsResolvedTrue(Long id);
}
List<Expense> findAllByOrderByDateDesc();}

View file

@ -70,4 +70,8 @@ public class ExpenseService {
return this.repository.existsByIdAndIsResolvedTrue(expense.getId());
}
public List<Expense> findAllOrderByDateDescending() {
return this.repository.findAllByOrderByDateDesc();
}
}

View file

@ -99,7 +99,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver {
grid.addColumn(new ComponentRenderer<>(expense1 -> createBadge(expenseService.isExpenseResolved(expense1)))).setHeader("Status").setSortable(true);
grid.getColumns().forEach(col -> col.setAutoWidth(true));
grid.setItems(this.expenseService.findAll());
grid.setItems(this.expenseService.findAllOrderByDateDescending());
grid.setPaginatorSize(5);
grid.setPageSize(25); // setting page size
grid.addThemeVariants(GridVariant.LUMO_NO_BORDER);