Adding a text field for filtering: Start by adding a text field above the grid. Remember, MainView is a VerticalLayout, so you need to add the text field before the grid. MainView.java public class MainView extends VerticalLayout { private ContactService contactService; private Grid<Contact> grid = new Grid<>(Contact.class); private TextField filterText = new TextField(); ① public MainView(ContactService contactService) { this.contactService = contactService; addClassName("list-view"); setSizeFull(); configureFilter(); ② configureGrid(); add(filterText, grid); ③ updateList(); } private void configureFilter() { filterText.setPlaceholder("Filter by name..."); ④ filterText.setClearButtonVisible(true); ⑤ filterText.setValueChangeMode(ValueChangeMode.LAZY); ⑥ filterText.addValueChangeListener(e -> updateList()); ⑦ } // Grid...
Comments
Post a Comment