Class MultiSelectComboBox<TItem>

  • Type Parameters:
    TItem - the type of the items to be selectable from the combo box
    All Implemented Interfaces:
    com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<MultiSelectComboBox<TItem>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<MultiSelectComboBox<TItem>>, com.vaadin.flow.component.FocusNotifier<MultiSelectComboBox<TItem>>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<MultiSelectComboBox<TItem>,​Set<TItem>>,​Set<TItem>>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<MultiSelectComboBox<TItem>,​Set<TItem>>,​Set<TItem>>, HasAllowedCharPattern, HasClearButton, HasThemeVariant<MultiSelectComboBoxVariant>, HasTooltip, com.vaadin.flow.data.binder.HasValidator<Set<TItem>>, com.vaadin.flow.data.provider.HasDataView<TItem,​String,​ComboBoxDataView<TItem>>, com.vaadin.flow.data.provider.HasLazyDataView<TItem,​String,​ComboBoxLazyDataView<TItem>>, com.vaadin.flow.data.provider.HasListDataView<TItem,​ComboBoxListDataView<TItem>>, com.vaadin.flow.data.selection.MultiSelect<MultiSelectComboBox<TItem>,​TItem>, Serializable

    @Tag("vaadin-multi-select-combo-box")
    @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="23.6.3") @NpmPackage(value="@vaadin/multi-select-combo-box",version="23.6.3")
    @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/multi-select-combo-box/src/vaadin-multi-select-combo-box.js") @JsModule("@vaadin/polymer-legacy-adapter/template-renderer.js") @JsModule("./flow-component-renderer.js") @JsModule("./comboBoxConnector.js")
    public class MultiSelectComboBox<TItem>
    extends ComboBoxBase<MultiSelectComboBox<TItem>,​TItem,​Set<TItem>>
    implements com.vaadin.flow.data.selection.MultiSelect<MultiSelectComboBox<TItem>,​TItem>, HasThemeVariant<MultiSelectComboBoxVariant>
    MultiSelectComboBox allows the user to select one or more values from a filterable list of options presented in an overlay. Compared to ComboBox, MultiSelectComboBox allows to select multiple values.

    MultiSelectComboBox supports lazy loading. This means that when using large data sets, items are requested from the server one "page" at a time when the user scrolls down the overlay. The number of items in one page is by default 50, and can be changed with ComboBoxBase.setPageSize(int).

    MultiSelectComboBox can do filtering either in the browser or in the server. When MultiSelectComboBox has only a relatively small set of items, the filtering will happen in the browser, allowing smooth user-experience. When the size of the data set is larger than the pageSize, the webcomponent doesn't necessarily have all the data available, and it will make requests to the server to handle the filtering. Also, if you have defined custom filtering logic, with eg. ComboBoxBase.setItems(ComboBox.ItemFilter, Collection), filtering will happen in the server. To enable client-side filtering with larger data sets, you can override the pageSize to be bigger than the size of your data set. However, then the full data set will be sent to the client immediately, and you will lose the benefits of lazy loading.

    Author:
    Vaadin Ltd
    See Also:
    Serialized Form
    • Constructor Detail

      • MultiSelectComboBox

        public MultiSelectComboBox()
        Default constructor. Creates an empty combo box.
      • MultiSelectComboBox

        public MultiSelectComboBox​(int pageSize)
        Creates an empty combo box with the defined page size for lazy loading.

        The default page size is 50.

        The page size is also the largest number of items that can support client-side filtering. If you provide more items than the page size, the component has to fall back to server-side filtering.

        Parameters:
        pageSize - the amount of items to request at a time for lazy loading
        See Also:
        ComboBoxBase.setPageSize(int)
      • MultiSelectComboBox

        public MultiSelectComboBox​(String label)
        Creates an empty combo box with the defined label.
        Parameters:
        label - the label describing the combo box
        See Also:
        HasLabel.setLabel(String)
      • MultiSelectComboBox

        public MultiSelectComboBox​(String label,
                                   Collection<TItem> items)
        Creates a combo box with the defined label and populated with the items in the collection.
        Parameters:
        label - the label describing the combo box
        items - the items to be shown in the list of the combo box
        See Also:
        HasLabel.setLabel(String), ComboBoxBase.setItems(Collection)
      • MultiSelectComboBox

        @SafeVarargs
        public MultiSelectComboBox​(String label,
                                   TItem... items)
        Creates a combo box with the defined label and populated with the items in the array.
        Parameters:
        label - the label describing the combo box
        items - the items to be shown in the list of the combo box
        See Also:
        HasLabel.setLabel(String), HasListDataView.setItems(Object...)
      • MultiSelectComboBox

        public MultiSelectComboBox​(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<MultiSelectComboBox<TItem>,​Set<TItem>>> listener)
        Constructs a combo box with a value change listener.
        Parameters:
        listener - the value change listener to add
        See Also:
        AbstractField.addValueChangeListener(ValueChangeListener)
      • MultiSelectComboBox

        public MultiSelectComboBox​(String label,
                                   com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<MultiSelectComboBox<TItem>,​Set<TItem>>> listener)
        Constructs a combo box with the defined label and a value change listener.
        Parameters:
        label - the label describing the combo box
        listener - the value change listener to add
        See Also:
        HasLabel.setLabel(String), AbstractField.addValueChangeListener(ValueChangeListener)
      • MultiSelectComboBox

        @SafeVarargs
        public MultiSelectComboBox​(String label,
                                   com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<MultiSelectComboBox<TItem>,​Set<TItem>>> listener,
                                   TItem... items)
        Constructs a combo box with the defined label, a value change listener and populated with the items in the array.
        Parameters:
        label - the label describing the combo box
        listener - the value change listener to add
        items - the items to be shown in the list of the combo box
        See Also:
        HasLabel.setLabel(String), AbstractField.addValueChangeListener(ValueChangeListener), HasListDataView.setItems(Object...)
    • Method Detail

      • getValue

        public Set<TItem> getValue()
        Gets the value of the component, which is a set of selected items.

        The returned set is immutable and can not be modified. Use MultiSelect.select(Object[]) or MultiSelect.deselect(Object[]) to add or remove individual items.

        Specified by:
        getValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<MultiSelectComboBox<TItem>,​Set<TItem>>,​Set<TItem>>
        Specified by:
        getValue in interface com.vaadin.flow.data.selection.MultiSelect<MultiSelectComboBox<TItem>,​TItem>
        Overrides:
        getValue in class com.vaadin.flow.component.AbstractField<MultiSelectComboBox<TItem>,​Set<TItem>>
        Returns:
        an unmodifiable set of selected items
      • setValue

        public void setValue​(Set<TItem> value)
        Sets the value of the component, which is a set of selected items.

        Note that it is allowed to pass null as value to clear the selection, but that an empty set will be stored as value instead.

        Specified by:
        setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<MultiSelectComboBox<TItem>,​Set<TItem>>,​Set<TItem>>
        Specified by:
        setValue in interface com.vaadin.flow.data.selection.MultiSelect<MultiSelectComboBox<TItem>,​TItem>
        Overrides:
        setValue in class ComboBoxBase<MultiSelectComboBox<TItem>,​TItem,​Set<TItem>>
        Parameters:
        value - the new value
      • setValue

        @SafeVarargs
        public final void setValue​(TItem... items)
        Sets the value of the component, which is a set of selected items. As each item can only be selected once, duplicates in the provided items will be removed. Passing no items will result in an empty selection.
        Parameters:
        items - the new value
      • setValue

        public void setValue​(Collection<TItem> items)
        Sets the value of the component, which is a set of selected items. As each item can only be selected once, duplicates in the provided items will be removed. Passing no items will result in an empty selection.
        Parameters:
        items - the new value
      • addSelectionListener

        public com.vaadin.flow.shared.Registration addSelectionListener​(com.vaadin.flow.data.selection.MultiSelectionListener<MultiSelectComboBox<TItem>,​TItem> listener)
        Specified by:
        addSelectionListener in interface com.vaadin.flow.data.selection.MultiSelect<MultiSelectComboBox<TItem>,​TItem>
      • updateSelection

        public void updateSelection​(Set<TItem> addedItems,
                                    Set<TItem> removedItems)
        Specified by:
        updateSelection in interface com.vaadin.flow.data.selection.MultiSelect<MultiSelectComboBox<TItem>,​TItem>
      • isSelectedItemsOnTop

        public boolean isSelectedItemsOnTop()
        Gets whether selected items are grouped at the top of the overlay.
        Returns:
        true if enabled, false otherwise
        Since:
        23.4
      • setSelectedItemsOnTop

        public void setSelectedItemsOnTop​(boolean selectedItemsOnTop)
        Enables or disables grouping of the selected items at the top of the overlay.
        Parameters:
        selectedItemsOnTop - true to group selected items at the top
        Since:
        23.4
      • setAutoExpand

        public void setAutoExpand​(MultiSelectComboBox.AutoExpandMode autoExpandMode)
        Sets the behavior of the component when not all selected items can be displayed as chips within the current field width. Expansion only works with undefined size in the desired direction (i.e. setting `max-width` limits the component's width).
        Since:
        23.4
      • isKeepFilter

        public boolean isKeepFilter()
        Gets whether the filter is kept after selecting items. false by default.
        Returns:
        true if enabled, false otherwise
        Since:
        23.4
      • setKeepFilter

        public void setKeepFilter​(boolean keepFilter)
        Enables or disables keeping the filter after selecting items. By default, the filter is cleared after selecting an item and the overlay shows the unfiltered list of items again. Enabling this option will keep the filter, which allows to select multiple filtered items in succession.
        Parameters:
        keepFilter - whether to keep the filter after selecting an item
        Since:
        23.4
      • getI18n

        public MultiSelectComboBoxI18n getI18n()
        Gets the internationalization object previously set for this component.

        Note: updating the i18n object that is returned from this method will not update the component, unless it is set again using setI18n(MultiSelectComboBoxI18n)

        Returns:
        the i18n object. It will be null, if it has not been set previously
      • setI18n

        public void setI18n​(MultiSelectComboBoxI18n i18n)
        Sets the internationalization properties for this component.
        Parameters:
        i18n - the internationalized properties, not null