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 Name | Virtual Select Box |
Author Name | sa-si-dev |
Category | Dropdown, Menu Plugins, Scrolling |
Official Page | Click Here |
Official Website | github.com |
Publish Date | January 17, 2021 |
Last Update | August 2, 2023 |
Download | Link Below |
License | MIT |
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
Name | Type | Default value | Description |
---|---|---|---|
ele | String | Element | DOM element to initialize the plugin String – #sample-select Element – document.querySelector(‘#sample-select’) | |
dropboxWrapper | String | self | Parent element to render dropbox. (self, body, or any CSS selector) Use this when a container of dropdown has an overflow scroll or hidden value. |
options | Array | [] | 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[].alias | String | Array | Alternative labels to use on search. An array of string or comma-separated string. | |
options[].options | Array | List of options for option group | |
options[].description | String | Text to show along with label | |
options[].classNames | String | Additional class names to customize specific option | |
options[].customData | Any | Any custom data to store with the options would be available with getSelectedOptions() result. | |
valueKey | String | value | Object key to use to get value from options array |
labelKey | String | label | Object key to use to get a label from the options array |
descriptionKey | String | description | Object key to use to get a description from the options array |
aliasKey | String | alias | Object key to use to get alias from options array |
disabledOptions | Array | [] | List of values to disable options e.g – [2, 3, 9] |
multiple | Boolean | false | Enable multi-select |
search | Boolean | false – for single select true – for multi-select | Enable search feature |
searchByStartsWith | Boolean | false | Search options by startsWith() method |
searchGroup | Boolean | false | Include group title for searching |
disabled | Boolean | false | Disable dropdown |
required | Boolean | false | Enable required validation. It would be triggered automatically on form submission and value change. To trigger it manually use validate() method |
autofocus | Boolean | false | Autofocus dropdown on load |
hideClearButton | Boolean | false | Hide clear value button |
autoSelectFirstOption | Boolean | false | Select the first option by default on the load |
hasOptionDescription | Boolean | false | Has a description to show along with a label |
disableSelectAll | Boolean | false | Disable select all features of multiple select |
optionsCount | Number | 5 | 4 | No.of options to show on the viewport 4 – When hasOptionDescription is true |
optionHeight | String | 40px | 50px | Height of each dropdown option 50px – When hasOptionDescription is true |
position | String | bottom left | Position of dropbox (auto, top, bottom, top left, top right, bottom left, bottom right) |
textDirection | String | ltr | The direction of text (ltr or rtl) |
selectedValue | String | Array | Single value or array of values to select on init | |
silentInitialValueSet | Boolean | false | To avoid the “change event” trigger on setting the initial value |
dropboxWidth | String | Custom width for dropbox | |
zIndex | Number | 1 | CSS z-index value for dropbox |
noOfDisplayValues | Number | 50 | Maximum no.of values to show in the tooltip for multi-select |
allowNewOption | Boolean | false | Allow adding new options by searching |
tooltipFontSize | String | 14px | Font size for the tooltip |
tooltipAlignment | String | center | CSS Text alignment for the tooltip |
tooltipMaxWidth | String | 300px | CSS max-width for the tooltip |
showSelectedOptionsFirst | Boolean | false | Show selected options at the top of the dropbox |
focusSelectedOptionOnOpen | Boolean | true | Scroll selected option to viewport on dropbox open |
markSearchResults | Boolean | false | Mark matched term in the label |
name | String | Name attribute for hidden input It would be useful for the form to be submitted to the server | |
keepAlwaysOpen | Boolean | false | Keep dropbox always open with fixed height |
maxValues | Number | 0 | Maximum no.of options allowed to choose in multiple select 0 – for no limit |
minValues | Number | A minimum no.of options should be selected to succeed required validation | |
additionalClasses | String | Additional classes for the wrapper element | |
showDropboxAsPopup | Boolean | true | Show dropbox as a popup on a small screen like mobile |
popupDropboxBreakpoint | String | 576px | Maximum screen width that allowed to show dropbox as a popup |
popupPosition | String | center | Position of the popup (left, center, or right) |
onServerSearch | Function | Callback function to integrate server search | |
searchDelay | Number | 300 | Delay time in milliseconds to trigger onServerSearch callback function |
labelRenderer | Function | Callback function to render label, which could be used to add image, icon, or custom content | |
ariaLabelledby | String | The ID of the label element to use as a11y attribute aria-labeled by | |
hideValueTooltipOnSelectAll | Boolean | true | Hide value tooltip if all options selected |
showOptionsOnlyOnSearch | Boolean | false | Show options to select only if the search value is not empty |
selectAllOnlyVisible | Boolean | false | Select only visible options by clicking the select all checkbox when options are filtered by search |
alwaysShowSelectedOptionsCount | Boolean | false | By 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. |
alwaysShowSelectedOptionsLabel | Boolean | false | By 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. |
disableAllOptionsSelectedText | Boolean | false | By default, when all values are selected “All (10)” value text would be shown. Set true to show value text as “10 options selected”. |
showValueAsTags | Boolean | false | Show each selected value as tags with the removed icon |
disableOptionGroupCheckbox | Boolean | false | Disable the option group title checkbox |
enableSecureText | Boolean | false | Set 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. |
setValueAsArray | Boolean | false | Set value for hidden input in array format (e.g. ‘[“1”, “2”]’) |
emptyValue | String | Empty value to use for hidden input when no value is selected (e.g. ‘null’ or ‘[]’ or ‘none’) | |
disableValidation | Boolean | false | Disable required validation |
useGroupValue | Boolean | false | Group’s value would be returned when all of its child options selected |
maxWidth | String | 250px | Maximum width for the selected element |
updatePositionThrottle | Number | 100 | Throttle 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
Name | Type | Default value | Description |
---|---|---|---|
placeholder | String | Select | Text to show when no options are selected |
noOptionsText | String | No options found | Text to show when no options to show |
noSearchResultsText | String | No results found | Text to show when no results on the search |
selectAllText | String | Select all | Text to show near select all checkbox when a search is disabled |
searchPlaceholderText | String | Search… | Text to show as a placeholder for search input |
optionsSelectedText | String | options selected | Text to use when displaying no.of values selected text (i.e. 3 options selected) |
optionSelectedText | String | option selected | Text to use when displaying no.of values selected text and only one value is selected (i.e. 1 option selected) |
allOptionsSelectedText | String | All | Text to use when displaying all values selected text (i.e. All (10)) |
clearButtonText | String | Clear | Tooltip text for clear button |
moreText | String | more… | Text to show when more than noOfDisplayValues options are selected (i.e + 10 more…) |
See Demo And Download

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.