ComboBox with Infinite Scrolling

The ComboBox below populates the drop-down list by adding a few items whenever the user scrolls near the bottom of the list. This provides an 'infinite scrolling' experience. This sample limits the number of items to 2,000.

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as input from '@grapecity/wijmo.input'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // list that contains the items in the Combo (start with 10 items) let theList = loadItems([], 10); // // ComboBox to show the items let theCombo = new input.ComboBox('#theCombo', { itemsSource: theList }); // // add items when user scrolls near the bottom of the list theCombo.dropDown.addEventListener('scroll', e => { // stop adding items when the list reaches 2,000 items if (theList.length < 2000) { let list = e.target; // // if the user scrolled near the bottom of the list if (list.scrollTop + list.clientHeight + 100 > list.scrollHeight) { // save scroll top, add items, refresh list, restore scroll top let top = list.scrollTop; loadItems(theList, 5); theCombo.collectionView.refresh(); list.scrollTop = top; } } }); // add some items to the list function loadItems(arr, cnt) { for (let i = 0; i < cnt; i++) { arr.push('item ' + (arr.length + 1)); } return arr; } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity ComboBox with Infinite Scrolling</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div id="theCombo"></div> </div> </body> </html> body { margin-bottom: 24px; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; import * as input from '@grapecity/wijmo.input'; // import { Component, enableProdMode, NgModule, Inject } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { theList: any[]; // constructor() { // list that contains the items in the Combo (start with 10 items) this.theList = this._loadItems([], 10); } // initialized(combo: input.ComboBox) { combo.dropDown.addEventListener('scroll', e => { // stop adding items when the list reaches 2,000 items if (this.theList.length < 2000) { let list = <Element>e.target; // // if the user scrolled near the bottom of the list if (list.scrollTop + list.clientHeight + 100 > list.scrollHeight) { // save scroll top, add items, refresh list, restore scroll top let top = list.scrollTop; this._loadItems(this.theList, 5); combo.collectionView.refresh(); list.scrollTop = top; } } }); } // private _loadItems(arr: any[], cnt: number) { for (let i = 0; i < cnt; i++) { arr.push('item ' + (arr.length + 1)); } return arr; } } // @NgModule({ imports: [WjInputModule, BrowserModule], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity ComboBox with Infinite Scrolling</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <wj-combo-box #theCombo [itemsSource]="theList" (initialized)="initialized(theCombo)"> </wj-combo-box> </div> body { margin-bottom: 24px; } <template> <div class="container-fluid"> <wj-combo-box :itemsSource="theList" :initialized="initialized"> </wj-combo-box> </div> </template> <script> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.core'; import '@grapecity/wijmo.vue2.input'; let App = Vue.extend({ name: 'app', data: function () { return { theList: this._loadItems([], 10) } }, methods: { initialized: function(combo,e) { combo.dropDown.addEventListener('scroll', e => { // stop adding items when the list reaches 2,000 items if (this.theList.length < 2000) { let list = e.target; // if the user scrolled near the bottom of the list if (list.scrollTop + list.clientHeight + 100 > list.scrollHeight) { // save scroll top, add items, refresh list, restore scroll top let top = list.scrollTop; this._loadItems(this.theList, 5); combo.collectionView.refresh(); list.scrollTop = top; } } }); }, _loadItems: function(arr, cnt) { for (let i = 0; i < cnt; i++) { arr.push('item ' + (arr.length + 1)); } return arr; } } }) let vm = new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> body { margin-bottom: 24px; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity ComboBox with Infinite Scrolling</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"></div> </body> </html> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wjInput from '@grapecity/wijmo.react.input'; // class App extends React.Component { constructor(props) { super(props); this.initialized = (combo, e) => { combo.dropDown.addEventListener('scroll', e => { // stop adding items when the list reaches 2,000 items if (this.state.theList.length < 2000) { let list = e.target; // if the user scrolled near the bottom of the list if (list.scrollTop + list.clientHeight + 100 > list.scrollHeight) { // save scroll top, add items, refresh list, restore scroll top let top = list.scrollTop; this._loadItems(this.state.theList, 5); combo.collectionView.refresh(); list.scrollTop = top; } } }); }; this._loadItems = (arr, cnt) => { for (let i = 0; i < cnt; i++) { arr.push('item ' + (arr.length + 1)); } return arr; }; this.state = { theList: this._loadItems([], 10) }; } render() { return <div className="container-fluid"> <wjInput.ComboBox itemsSource={this.state.theList} initialized={this.initialized}> </wjInput.ComboBox> </div>; } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity ComboBox with Infinite Scrolling</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> body { margin-bottom: 24px; }