JavaScript Dropdown Menu Plugin with Virtual Scrolling

Virtual Select is to replace the high-performance material design style checkbox that supports single/multiple selections, virtual scrolling, live search, and dynamic data rendering.

Features:

  • Support more than 100000 dropdown options
  • Support multi-select
  • Support search feature
  • Support Right-to-Left text
  • Support loading options from the server (API)

Must Read: Responsive Multi-Level Dropdown Menu With Vanilla JavaScript

JavaScript Dropdown Menu Plugin Details

Post NameVirtual Select Box
Author Namesa-si-dev
CategoryDropdown, Menu Plugins, Scrolling
Official PageClick Here
Official Websitegithub.com
Publish DateJanuary 17, 2021
Last UpdateAugust 2, 2023
DownloadLink Below
LicenseMIT

How to make use of it:

1. We can install and use this plugin from NPM:

npm install --save virtual-select-plugin

2. Import files from node_modules:

<link rel="stylesheet" href="node_modules/virtual-select-plugin/dist/virtual-select.min.css">
<script src="node_modules/virtual-select-plugin/dist/virtual-select.min.js"></script>

<!-- optional -->
<link rel="stylesheet" href="node_modules/tooltip-plugin/dist/tooltip.min.css">
<script src="node_modules/tooltip-plugin/dist/tooltip.min.js"></script>

3. Initialize the plugin

<div id="sample-select"></div>
VirtualSelect.init({
  ele: '#sample-select',
  options: [
    { label: 'Options 1', value: '1' },
    { label: 'Options 2', value: '2' },
    { label: 'Options 3', value: '3' },
  ],
});

4. It is not recommended to use native to start the plug-in when the number of options is more, because it may affect performance.

<select multiple
  name="native-select" placeholder="Native Select"
  data-search="false" data-silent-initial-value-set="true"
>
  <option value="1" disabled>Option 1</option>
  <option value="2">Option 2</option>
  <option value="3" selected>Option 3</option>
  <option value="4" selected>Option 4</option>
  <option value="5">Option 5</option>
  <option value="6">Option 6</option>
</select>
VirtualSelect.init({ ele: 'select' });

Methods

  • Get selected value
  • setValue()
  • reset()
  • setOptions()
  • setDisabledOptions()
  • setEnabledOptions()
  • toggleSelectAll()
  • isAllSelected()
  • addOption()
  • getNewValue()
  • getDisplayValue()
  • getSelectedOptions()
  • getDisabledOptions()
  • open()
  • close()
  • focus()
  • enable()
  • disable()
  • destroy()
  • setServerOptions()
  • validate()
  • toggleRequired()

Properties

Must Read: [Animation] Bootstrap Multi-Level Responsive Dropdown Menu

NameTypeDefault valueDescription
eleString | ElementDOM element to initialize the plugin
String – #sample-select
Element – document.querySelector(‘#sample-select’)
dropboxWrapperStringselfParent element to render dropbox. (self, body, or any CSS selector)
Use this when a container of dropdown has an overflow scroll or hidden value.
optionsArray[]List of options
[
{ label: ‘Option 1’, value: ‘1’ },
{ label: ‘Option 2’, value: ‘2’ }

]

Use an array of strings when the label and value are the same
[‘value 1’, ‘value 2’]
options[].aliasString | ArrayAlternative labels to use on search.
An array of string or comma-separated string.
options[].optionsArrayList of options for option group
options[].descriptionStringText to show along with label
options[].classNamesStringAdditional class names to customize specific option
options[].customDataAnyAny custom data to store with the options would be available with getSelectedOptions() result.
valueKeyStringvalueObject key to use to get value from options array
labelKeyStringlabelObject key to use to get a label from the options array
descriptionKeyStringdescriptionObject key to use to get a description from the options array
aliasKeyStringaliasObject key to use to get alias from options array
disabledOptionsArray[]List of values to disable options
e.g – [2, 3, 9]
multipleBooleanfalseEnable multi-select
searchBooleanfalse – for single select
true – for multi-select
Enable search feature
searchByStartsWithBooleanfalseSearch options by startsWith() method
searchGroupBooleanfalseInclude group title for searching
disabledBooleanfalseDisable dropdown
requiredBooleanfalseEnable required validation.
It would be triggered automatically on form submission and value change.
To trigger it manually use validate() method
autofocusBooleanfalseAutofocus dropdown on load
hideClearButtonBooleanfalseHide clear value button
autoSelectFirstOptionBooleanfalseSelect the first option by default on the load
hasOptionDescriptionBooleanfalseHas a description to show along with a label
disableSelectAllBooleanfalseDisable select all features of multiple select
optionsCountNumber5 | 4No.of options to show on the viewport
4 – When hasOptionDescription is true
optionHeightString40px | 50pxHeight of each dropdown option
50px – When hasOptionDescription is true
positionStringbottom leftPosition of dropbox (auto, top, bottom, top left, top right, bottom left, bottom right)
textDirectionStringltrThe direction of text (ltr or rtl)
selectedValueString | ArraySingle value or array of values to select on init
silentInitialValueSetBooleanfalseTo avoid the “change event” trigger on setting the initial value
dropboxWidthStringCustom width for dropbox
zIndexNumber1CSS z-index value for dropbox
noOfDisplayValuesNumber50Maximum no.of values to show in the tooltip for multi-select
allowNewOptionBooleanfalseAllow adding new options by searching
tooltipFontSizeString14pxFont size for the tooltip
tooltipAlignmentStringcenterCSS Text alignment for the tooltip
tooltipMaxWidthString300pxCSS max-width for the tooltip
showSelectedOptionsFirstBooleanfalseShow selected options at the top of the dropbox
focusSelectedOptionOnOpenBooleantrueScroll selected option to viewport on dropbox open
markSearchResultsBooleanfalseMark matched term in the label
nameStringName attribute for hidden input
It would be useful for the form to be submitted to the server
keepAlwaysOpenBooleanfalseKeep dropbox always open with fixed height
maxValuesNumber0Maximum no.of options allowed to choose in multiple select
0 – for no limit
minValuesNumberA minimum no.of options should be selected to succeed required validation
additionalClassesStringAdditional classes for the wrapper element
showDropboxAsPopupBooleantrueShow dropbox as a popup on a small screen like mobile
popupDropboxBreakpointString576pxMaximum screen width that allowed to show dropbox as a popup
popupPositionStringcenterPosition of the popup (left, center, or right)
onServerSearchFunctionCallback function to integrate server search
searchDelayNumber300Delay time in milliseconds to trigger onServerSearch callback function
labelRendererFunctionCallback function to render label, which could be used to add image, icon, or custom content
ariaLabelledbyStringThe ID of the label element to use as a11y attribute aria-labeled by
hideValueTooltipOnSelectAllBooleantrueHide value tooltip if all options selected
showOptionsOnlyOnSearchBooleanfalseShow options to select only if the search value is not empty
selectAllOnlyVisibleBooleanfalseSelect only visible options by clicking the select all checkbox when options are filtered by search
alwaysShowSelectedOptionsCountBooleanfalseBy default, the no.of options selected text would be shown when there is not enough space to show all selected values. Set true to show count even though there is enough space.
alwaysShowSelectedOptionsLabelBooleanfalseBy default, the no.of options selected text would be shown when there is not enough space to show all selected values. Set true to show labels even though there is not enough space.
disableAllOptionsSelectedTextBooleanfalseBy default, when all values are selected “All (10)” value text would be shown. Set true to show value text as “10 options selected”.
showValueAsTagsBooleanfalseShow each selected value as tags with the removed icon
disableOptionGroupCheckboxBooleanfalseDisable the option group title checkbox
enableSecureTextBooleanfalseSet true to replace HTML tags from the option’s text (value and label) to prevent an XSS attack. This feature is not enabled by default to avoid performance issues.
setValueAsArrayBooleanfalseSet value for hidden input in array format (e.g. ‘[“1”, “2”]’)
emptyValueStringEmpty value to use for hidden input when no value is selected (e.g. ‘null’ or ‘[]’ or ‘none’)
disableValidationBooleanfalseDisable required validation
useGroupValueBooleanfalseGroup’s value would be returned when all of its child options selected
maxWidthString250pxMaximum width for the selected element
updatePositionThrottleNumber100Throttle time for updating dropbox position on scroll event (in milliseconds)

Text Properties

Update the below properties to change display texts.

Must Read: Mobile-friendly Multi-level Dropdown Menu With jQuery

NameTypeDefault valueDescription
placeholderStringSelectText to show when no options are selected
noOptionsTextStringNo options foundText to show when no options to show
noSearchResultsTextStringNo results foundText to show when no results on the search
selectAllTextStringSelect allText to show near select all checkbox when a search is disabled
searchPlaceholderTextStringSearch…Text to show as a placeholder for search input
optionsSelectedTextStringoptions selectedText to use when displaying no.of values selected text (i.e. 3 options selected)
optionSelectedTextStringoption selectedText to use when displaying no.of values selected text and only one value is selected (i.e. 1 option selected)
allOptionsSelectedTextStringAllText to use when displaying all values selected text (i.e. All (10))
clearButtonTextStringClearTooltip text for clear button
moreTextStringmore…Text to show when more than noOfDisplayValues options are selected (i.e + 10 more…)

See Demo And Download

Dropdown-Menu-Plugin-with-Virtual-Scrolling

Official Website(sa-si-dev): Click Here

This superior jQuery/javascript plugin is developed by sa-si-dev. For extra Advanced Usage, please go to the official website.

Related Posts

Google-Translate-Dropdown-Customize-With-Country-Flag

Google Translate Dropdown Customize With Country Flag | GT API

Flag google translates jQuery text that takes advantage of the Google Cloud Translation API to translate web content between languages by selecting a country from the dropdown…

Bootstrap-Fileinput

HTML 5 File Input Optimized for Bootstrap 4.x./3.x with File Preview | Bootstrap Fileinput

bootstrap-fileinput is an improved HTML 5 file input  Bootstrap 5.x, 4.x and 3.x with file preview for different files, provides multiple selections, resumable section uploads, and more….

HStack-and-VStack-in-CSS

CSS Layout Components Horizontal/Vertical Stack | HStack and VStack

HStack and VStack in CSS – CSS layout components that (basically) stack anything horizontally and vertically. A pure CSS library that makes it easy to stack elements…

Floating-Whatsapp-Chat-Button

How to Add Floating Whatsapp Chat Button In HTML | venom-button

Venom Button is a very simple plugin for the jQuery floating WhatsApp button. Adds a floating button to your site that calls WhatsApp Click to Chat API. It will automatically start the WhatsApp…

Data-Table-Generator-Tabulator

Interactive Data Table Generator with JS/jQuery and JSON | Tabulator

Tabulator allows you to create interactive tables in seconds from any HTML Table, JavaScript array, AJAX data source, or JSON format data. Just include the library in your…

alert-confirm-prompt-attention-js

Simple Alert, Confirm, Prompt Popup Using Vanilla JavaScript Library | attention.js

JavaScript provides various built-in functionality to display popup messages for different purposes. Attention JS is a vanillaJS plugin used to create a custom alert, confirm, or Prompt…

Leave a Reply

Your email address will not be published. Required fields are marked *