GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Caret Position
  • Change Listener
  • Checkbox Options
  • Clear Button
  • Drag 'n Drop
  • Dropdown Header
  • Dropdown Input
  • Input Autogrow
  • No Active Items
  • No Backspace Delete
  • Option Group Columns
  • Remove Button
  • Restore on Backspace

This view

  • Original page
  • New address

GeezerVison is showing tom-select.js.org — Virtual Scroll - Tom Select

Home Examples Plugins
Caret Position Change Listener Checkbox Options Clear Button Drag 'n Drop Dropdown Header Dropdown Input Input Autogrow No Active Items No Backspace Delete Option Group Columns Remove Button Restore on Backspace Virtual Scroll
Docs
GitHub NPM

Edit this page on GitHub
© 2026 Contributors

Virtual Scroll

Example
  • JavaScript
  • HTML
  • Edit
    • JSFiddle
    • CodePen
new TomSelect('#reddit-search',{
	valueField: 'permalink',
	labelField: 'title',
	searchField: ['title'],
	plugins:['virtual_scroll'],
	maxOptions: 200,

	// fetch remote data
	firstUrl: function(query){
		return 'https://api.reddit.com/search?q=' + encodeURIComponent(query);
	},
	load: function(query, callback) {

		// retrieve the appropriate url
		const url = this.getUrl(query);

		fetch(url)
			.then(response => response.json())
			.then(json => {

				// prepare the next url that will be loaded when the dropdown is scrolled to the bottom
				// important! should set before invoking callback()
				if( json.data.after ){
					const next_url = 'https://api.reddit.com/search?q=' + encodeURIComponent(query)+'&after='+json.data.after;
					this.setNextUrl(query, next_url);
				}

				// add data to the results
				let data = json.data.children.map(row => row.data);
				callback(data);

			}).catch((e)=>{
				callback();
			});

	},
	render: {
		loading_more: function(data, escape) {
			return `<div class="loading-more-results py-2 d-flex align-items-center"><div class="spinner"></div> Loading more results from reddit </div>`;
		}
	},

});
<input type="text" id="reddit-search" placeholder="Search reddit" autocomplete="off">

Related Tom Select Settings

Setting Description
firstUrl
(Required) The firstUrl() method works along with getUrl() and setNextUrl() to supply your load() method with pagination friendly urls.
  • firstUrl(query_string) should return the request url for the first `page` of data.
  • Call setNextUrl(query_string,next_url) in your load() method upon request completion to define subsequent request urls.
  • Use getUrl(query_string) to retrieve the appropriate pagination url for the given query string.
Type: callback Default: null
shouldLoadMore
The shouldLoadMore() method determines if additinal results should be loaded based on the dropdown scroll position.
Type: callback Default: callback
maxOptions
The max number of options to display in the dropdown.
Type: int Default: 50
render.loading_more
Renders a message at the bottom of the dropdown to communicate to users that more results are being loaded
Type: callback Default:
function(data,escape){
	return `<div class="loading-more-results">Loading more results ... </div>`;
}
render.no_more_results
Renders a message at the bottom of the dropdown for communicating that users have reached the end of the results
Type: callback Default:
function(data,escape){
	return `<div class="no-more-results">No more results</div>`;
}

Plugin Configuration

No additional configuration settings for this plugin

Available Plugins

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.