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);
}
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);
}
Aggregations