Search in sources :

Example 1 with ComboBoxLazyDataView

use of com.vaadin.flow.component.combobox.dataview.ComboBoxLazyDataView in project flow-components by vaadin.

the class FilteringPage method createComboBoxWithMultiplePagesAndSourceSwitchers.

private void createComboBoxWithMultiplePagesAndSourceSwitchers() {
    ComboBox<String> comboBox = new ComboBox<>();
    comboBox.setId(COMBOBOX_WITH_FILTERED_ITEMS_ID);
    List<String> items = LazyLoadingPage.generateStrings(500);
    ComboBoxLazyDataView<String> dataView = comboBox.setItems(query -> items.stream().filter(item -> item.contains(query.getFilter().orElse(""))).skip(query.getOffset()).limit(query.getLimit()), query -> (int) items.stream().filter(item -> item.contains(query.getFilter().orElse(""))).count());
    NativeButton switchToUnknown = new NativeButton("Switch To Unknown Item Count", click -> dataView.setItemCountUnknown());
    switchToUnknown.setId(SWITCH_TO_UNKNOWN_ITEM_COUNT_BUTTON_ID);
    NativeButton switchToInMemory = new NativeButton("Switch To In-memory Items", click -> comboBox.setItems(items));
    switchToInMemory.setId(SWITCH_TO_IN_MEMORY_ITEMS_BUTTON_ID);
    add(new Div(), comboBox, switchToUnknown, switchToInMemory);
}
Also used : IntStream(java.util.stream.IntStream) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) ItemFilter(com.vaadin.flow.component.combobox.ComboBox.ItemFilter) List(java.util.List) ComboBoxLazyDataView(com.vaadin.flow.component.combobox.dataview.ComboBoxLazyDataView) DataProvider(com.vaadin.flow.data.provider.DataProvider) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) CallbackDataProvider(com.vaadin.flow.data.provider.CallbackDataProvider) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Route(com.vaadin.flow.router.Route) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) ComboBox(com.vaadin.flow.component.combobox.ComboBox)

Example 2 with ComboBoxLazyDataView

use of com.vaadin.flow.component.combobox.dataview.ComboBoxLazyDataView in project flow-components by vaadin.

the class ClientSideFilterPage method createBackEndComboBox.

private void createBackEndComboBox() {
    ComboBox<String> backendComboBox = new ComboBox<>("Backend");
    backendComboBox.setId(BACKEND_COMBO_BOX);
    ComboBoxLazyDataView<String> lazyDataView = backendComboBox.setItems(query -> IntStream.range(0, 30).mapToObj(index -> "Item " + index).filter(item -> item.contains(query.getFilter().orElse(""))).skip(query.getOffset()).limit(query.getLimit()), query -> (int) IntStream.range(0, 30).mapToObj(index -> "Item " + index).filter(item -> item.contains(query.getFilter().orElse(""))).count());
    Span itemCountSpan = new Span("0");
    itemCountSpan.setId(BACKEND_COMBO_BOX_ITEM_COUNT_SPAN_ID);
    this.add(itemCountSpan);
    addListener(itemCountSpan, lazyDataView);
    this.add(backendComboBox);
}
Also used : IntStream(java.util.stream.IntStream) ComboBoxLazyDataView(com.vaadin.flow.component.combobox.dataview.ComboBoxLazyDataView) DataView(com.vaadin.flow.data.provider.DataView) ComboBoxListDataView(com.vaadin.flow.component.combobox.dataview.ComboBoxListDataView) Div(com.vaadin.flow.component.html.Div) Hr(com.vaadin.flow.component.html.Hr) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Collectors(java.util.stream.Collectors) Span(com.vaadin.flow.component.html.Span) Route(com.vaadin.flow.router.Route) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Span(com.vaadin.flow.component.html.Span)

Aggregations

ComboBox (com.vaadin.flow.component.combobox.ComboBox)2 ComboBoxLazyDataView (com.vaadin.flow.component.combobox.dataview.ComboBoxLazyDataView)2 Div (com.vaadin.flow.component.html.Div)2 Route (com.vaadin.flow.router.Route)2 IntStream (java.util.stream.IntStream)2 ItemFilter (com.vaadin.flow.component.combobox.ComboBox.ItemFilter)1 ComboBoxListDataView (com.vaadin.flow.component.combobox.dataview.ComboBoxListDataView)1 Hr (com.vaadin.flow.component.html.Hr)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1 Span (com.vaadin.flow.component.html.Span)1 CallbackDataProvider (com.vaadin.flow.data.provider.CallbackDataProvider)1 DataProvider (com.vaadin.flow.data.provider.DataProvider)1 DataView (com.vaadin.flow.data.provider.DataView)1 ListDataProvider (com.vaadin.flow.data.provider.ListDataProvider)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1