From 40b1966f1462bd69ee40829c2ccf8b49a24ee86a Mon Sep 17 00:00:00 2001 From: filippo-ferrari Date: Fri, 12 Jul 2024 19:21:18 +0200 Subject: [PATCH] feat: added pagination to ExpensesView --- pom.xml | 5 +++++ .../munera/views/expenses/ExpensesView.java | 12 +++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 7ebaa04..d200d37 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,11 @@ com.vaadin vaadin-spring-boot-starter + + org.vaadin.klaudeta + grid-pagination + 4.0.0 + org.parttio line-awesome diff --git a/src/main/java/com/application/munera/views/expenses/ExpensesView.java b/src/main/java/com/application/munera/views/expenses/ExpensesView.java index 26a3a7c..7f5ec82 100644 --- a/src/main/java/com/application/munera/views/expenses/ExpensesView.java +++ b/src/main/java/com/application/munera/views/expenses/ExpensesView.java @@ -15,7 +15,6 @@ import com.vaadin.flow.component.combobox.MultiSelectComboBox; import com.vaadin.flow.component.datepicker.DatePicker; import com.vaadin.flow.component.dependency.Uses; import com.vaadin.flow.component.formlayout.FormLayout; -import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.grid.GridVariant; import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.Span; @@ -31,9 +30,8 @@ import com.vaadin.flow.data.binder.BeanValidationBinder; import com.vaadin.flow.data.binder.ValidationException; import com.vaadin.flow.data.renderer.ComponentRenderer; import com.vaadin.flow.router.*; -import com.vaadin.flow.spring.data.VaadinSpringDataHelpers; -import org.springframework.data.domain.PageRequest; import org.springframework.orm.ObjectOptimisticLockingFailureException; +import org.vaadin.klaudeta.PaginatedGrid; import java.util.HashSet; import java.util.Objects; @@ -49,7 +47,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver { private static final String EXPENSE_ID = "expenseID"; private static final String EXPENSE_EDIT_ROUTE_TEMPLATE = "/%s/edit"; - private final Grid grid = new Grid<>(Expense.class, false); + private final PaginatedGrid grid = new PaginatedGrid<>(); private final Button cancel = new Button("Cancel"); private final Button save = new Button("Save"); @@ -101,9 +99,9 @@ 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(query -> expenseService.list( - PageRequest.of(query.getPage(), query.getPageSize(), VaadinSpringDataHelpers.toSpringDataSort(query))) - .stream()); + grid.setItems(this.expenseService.findAll()); + grid.setPaginatorSize(5); + grid.setPageSize(25); // setting page size grid.addThemeVariants(GridVariant.LUMO_NO_BORDER); // when a row is selected or deselected, populate form