Search in sources :

Example 6 with PersonService

use of com.vaadin.flow.component.combobox.test.service.PersonService in project flow-components by vaadin.

the class ComboBoxView method lazyLoading.

private void lazyLoading() {
    ComboBox<Person> comboBox = new ComboBox<>();
    PersonService service = new PersonService(500);
    /*
         * When provided a callback, the combo box doesn't load all items from
         * backend to server memory right away. It will request only the data
         * that is shown in its current view "window". The data is provided
         * based on string filter, offset and limit.
         *
         * When the user scrolls to the end, combo box will automatically extend
         * and fetch more items until the backend runs out of items.
         */
    comboBox.setItems(query -> service.fetch(query.getFilter().orElse(null), query.getOffset(), query.getLimit()));
    comboBox.setId("fetch-callback");
    addCard("Lazy Loading", "Lazy Loading with Callback", comboBox);
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) PersonService(com.vaadin.flow.component.combobox.test.service.PersonService) Person(com.vaadin.flow.component.combobox.test.entity.Person)

Aggregations

ComboBox (com.vaadin.flow.component.combobox.ComboBox)6 Person (com.vaadin.flow.component.combobox.test.entity.Person)6 PersonService (com.vaadin.flow.component.combobox.test.service.PersonService)6 Div (com.vaadin.flow.component.html.Div)2 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)2 Component (com.vaadin.flow.component.Component)1 Button (com.vaadin.flow.component.button.Button)1 ItemFilter (com.vaadin.flow.component.combobox.ComboBox.ItemFilter)1 ComboBoxLazyDataView (com.vaadin.flow.component.combobox.dataview.ComboBoxLazyDataView)1 ComboBoxListDataView (com.vaadin.flow.component.combobox.dataview.ComboBoxListDataView)1 DepartmentData (com.vaadin.flow.component.combobox.test.data.DepartmentData)1 ElementData (com.vaadin.flow.component.combobox.test.data.ElementData)1 ProjectData (com.vaadin.flow.component.combobox.test.data.ProjectData)1 Department (com.vaadin.flow.component.combobox.test.entity.Department)1 Element (com.vaadin.flow.component.combobox.test.entity.Element)1 Project (com.vaadin.flow.component.combobox.test.entity.Project)1 Song (com.vaadin.flow.component.combobox.test.entity.Song)1 Ticket (com.vaadin.flow.component.combobox.test.entity.Ticket)1 Anchor (com.vaadin.flow.component.html.Anchor)1 H2 (com.vaadin.flow.component.html.H2)1