• Stars
    star
    265
  • Rank 154,577 (Top 4 %)
  • Language
    JavaScript
  • Created over 11 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Scrollable list of DOM elements that can hold an unlimited amount of rows without breaking a sweat

Virtual DOM List

This is a simple component that allows the developer to create very long lists (by list I mean a single column of rows) that perform extremely fast. It does so by loading just the part of the list showing up on the viewport, and by optimizing the amount of DOM operations and reflows. It also spends very little memory.

The list could be done even faster by sacrificing the 'momentum' effect, but I decided to keep it since it is too big of a sacrifice for the sake of speed.

Installation

npm install virtual-list

Or if you prefer bower:

bower install virtual-list

Of course it can also just be added to any JavaScript project since it consists of a single JavaScript file.

Usage

Each of the following snippets of code creates a virtual list that holds 1 milion rows:

// This will create a scrolling list of 300x300 with 10000 rows. It is necessary to specify
// how tall each row is by setting the `itemHeight` prpoerty in the config object. In this
// example, we set up a generator function that will generate each row on demand.
var list = new ScrollableList({
  w: 300,
  h: 300,
  itemHeight: 31,
  totalRows: 10000,
  generatorFn: function(row) {
    var el = document.createElement("div");
    el.innerHTML = "ITEM " + row;
    el.style.borderBottom = "1px solid red";
    el.style.position = "absolute"
    return el;
  }
});
document.body.appendChild(list.container)

// The code below will create an array of 10000 DOM elements beforehand and pass them to
// the list. The Virtual list will then display them on demand. Of course, even if the
// virtual list is smart about displaying them, this method fills up a lot of memory by
// creating the elements before-hand.
var bigAssList = [];
for (var i = 0; i < 10000; i++) {
  var el = document.createElement("div");
  el.classList.add("item");
  el.innerHTML = "ITEM " + i;
  el.style.borderBottom = "1px solid red";
  bigAssList.push(el);
}

var list = new ScrollableList({
  w: 300,
  h: 300,
  items: bigAssList,
  itemHeight: 31
});
document.body.appendChild(list.container)

// The code below will create an array of 10000 strings beforehand and pass them to
// the list. The Virtual list will then display them on demand.
var bigAssList = [];
for (var i = 0; i < 10000; i++)
  bigAssList.push("ITEM " + i);

var list = new ScrollableList({
  w: 300,
  h: 300,
  items: bigAssList,
  itemHeight: 31
});
document.body.appendChild(list.container)

Caveats

Firefox has a nasty bug (https://bugzilla.mozilla.org/show_bug.cgi?id=373875) that breaks any attempt of assigning big numerical values to css properties. Since the virtual list does exactly that to give the illusion of a very big list without actually loading the components, you might run into that bug for very big lists. Unfortunately, I haven't found a way to work around it yet.

License

The MIT License (MIT)

Copyright (C) 2013 Sergi Mansilla

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

go-diff

Diff, match and patch text in Go
Go
1,827
star
2

jsftp

Light and complete FTP client implementation for Node.js
JavaScript
808
star
3

jsmidi

Library for reading/writing midi files in JavaScript
JavaScript
185
star
4

narwhal-mongodb

Wrapper of MongoDB database for CommonJS
JavaScript
94
star
5

tabgrenade

Tab Grenade is a Firefox Browser extension that creates a persistent list of all your open tabs and then closes them all.
JavaScript
62
star
6

abcnode

Node.js parser for the ABC music notation format
JavaScript
27
star
7

Design-By-Canvas

Port of John Maeda's Design By Numbers to Javascript using PEG.js
JavaScript
20
star
8

parse-listing

Small library to parse file listings into JavaScript objects
JavaScript
16
star
9

xslty

Command-line XSLT 2.0 processor
JavaScript
13
star
10

re-alpine

Mirror of the official re-alpine repository at sourceforge.net
C
12
star
11

rxjs-minimal-boilerplate

Minimal boilerplate for a barebones project in modern RxJS
JavaScript
11
star
12

par

par is a paragraph reformatter, vaguely similar to fmt, but better.
C
10
star
13

pipeline2dcd

Converts JSON Spinnaker pipelines to DCD pipelines (https://github.com/spinnaker/dcd-spec)
JavaScript
9
star
14

siphon

Stream commands output to your browser
Go
8
star
15

cascade

A desktop IRC client made using Node and AngularJS
JavaScript
7
star
16

ftp-test-server

Simple wrapper around pyftpdlib to have an easy FTP server to try stuff with
Python
6
star
17

mlkit

Mirror of the official smltojs SVN repository
Standard ML
4
star
18

ftp-response-parser

Streaming parser for FTP responses
JavaScript
3
star
19

Wakame

Wakame is a Gtk application that acts as a frontend to Wesabe and adds some extra functionality such as complex filters, graphs and persistence.
C#
3
star
20

enumjs

Enumeration over abstract collection of elements, in a functional way.
JavaScript
2
star
21

vimfiles

My vim config
Vim Script
2
star
22

jsmacros

Sweet.js macro collection for JavaScript
JavaScript
2
star
23

sergimansilla.com

My personal website
2
star
24

gab

JavaScript
2
star
25

sergi-vim

My vim environment
Vim Script
2
star
26

coconut

An idempotent photo organizer
Go
2
star
27

detect-failed-junit

Returns error if there are any test suites that failed or errored in a JUnit test report
Go
2
star
28

solitaire

Bruce Schneier's Solitaire cryptoalgorithm implemented in a variety of languages
2
star
29

conceal

Conceals a string or part of it.
JavaScript
2
star
30

rxjs-codemod

JavaScript
2
star
31

sergi.github.com

Personal blog
CSS
1
star
32

parcel_testcase

JavaScript
1
star
33

evidence

C#
1
star
34

mime-multipart

Library to help creating Mime Multi Part Archives
JavaScript
1
star
35

Tagger

Tagger is a speed tagging extension for Thunderbird
JavaScript
1
star
36

vim-chicken-doc

Vim plugin that integrates chicken-doc for scheme files
Vim Script
1
star
37

mesos-scheduler

Simple Scheduler from scratch for Apache Mesos
JavaScript
1
star
38

roughdb-clj

Clojure
1
star
39

XPMParser.js

A parser of the XPM graphical format implemented in JavaScript
JavaScript
1
star
40

geekdots

JavaScript
1
star
41

siphon-ui

UI for Siphon
CSS
1
star
42

roughdb

JavaScript
1
star
43

FoxStat

F#
1
star
44

jpl-website

JavaScript
1
star
45

nodejsconfit2012

Code for the talk given at http://nodejsconf.it/ 2012
JavaScript
1
star