This commit is contained in:
filippo-ferrari 2024-07-18 18:44:29 +02:00
parent 7450fe3857
commit 0fc5b07f5e

View file

@ -83,16 +83,7 @@ public class PeopleView extends Div implements BeforeEnterObserver {
List<Person> people = (List<Person>) personService.findAll();
for (Person person : people) {
// Add the person as a root item
grid.getTreeData().addItem(null, person);
// Fetch expenses for the current person
List<Expense> expenses = expenseService.findExpenseByUser(person);
// Add each expense as a child item under the person
for (Expense expense : expenses) grid.getTreeData().addItem(person, expense);
}
this.setGridData(people);
// when a row is selected or deselected, populate form
grid.asSingleSelect().addValueChangeListener(event -> {
@ -261,4 +252,17 @@ public class PeopleView extends Div implements BeforeEnterObserver {
}
return badge;
}
public void setGridData(List<Person> people) {
for (Person person : people) {
// Add the person as a root item
grid.getTreeData().addItem(null, person);
// Fetch expenses for the current person
List<Expense> expenses = expenseService.findExpenseByUser(person);
// Add each expense as a child item under the person
for (Expense expense : expenses) grid.getTreeData().addItem(person, expense);
}
}
}