2.2.0 • Published 7 years ago

virtualized-list v2.2.0

Weekly downloads
897
License
MIT
Repository
github
Last release
7 years ago

virtualized-list

A tiny vanilla virtualization library, with DOM diffing

npm package Build Status codecov

Installation

Using npm:

npm install virtualized-list --save

Usage

Basic example

const rows = ['a', 'b', 'c', 'd'];

const virtualizedList = new VirtualizedList(container, {
  height: 500, // The height of the container
  rowCount: rows.length,
  renderRow: index => {
  	const element = document.createElement('div');
  	element.innerHTML = rows[index];

  	return element;
  },
  rowHeight: 150,
)};

Advanced example

const rows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const rowHeights = [150, 120, 100, 80, 50, 35, 200, 500, 50, 300];

const virtualizedList = new VirtualizedList(container, {
  height: 400,
  rowCount: rows.length,
  renderRow: (row, index) => {
  	const element = document.createElement('div');
  	element.innerHTML = row;

  	return element;
  },
  rowHeight: index => rowHeights[index],
  estimatedRowHeight: 155,
  overscanCount: 5, // Number of rows to render above/below the visible rows.
  initialScrollIndex: 8,
  onMount: () => {
    // Programatically scroll to item index #3 after 2 seconds
    setTimeout(() =>
      virtualizedList.scrollToIndex(3)
    , 2000);
  }
)}

Options

PropertyTypeRequired?Description
heightNumberHeight of List. This property will determine the number of rendered vs virtualized items
rowCountNumberThe number of rows you want to render
renderRowFunctionResponsible for rendering an item given it's index: ({index: number, style: Object}): React.PropTypes.node. The returned element must handle key and style.
rowHeightNumber, Array or FunctionEither a fixed height, an array containing the heights of all the items in your list, or a function that returns the height of an item given its index: (index: number): number
initialScrollTopNumberThe initial scrollTop value (optional)
initialIndexNumberInitial item index to scroll to (by forcefully scrolling if necessary)
overscanCountNumberNumber of extra buffer items to render above/below the visible items. Tweaking this can help reduce scroll flickering on certain browsers/devices. Defaults to 3
estimatedRowHeightNumberUsed to estimate the total size of the list before all of its items have actually been measured. The estimated total height is progressively adjusted as items are rendered.
onMountFunctionCallback invoked once the virtual list has mounted.
onScrollFunctionCallback invoked onScroll. function (scrollTop, event)
onRowsRenderedFunctionCallback invoked with information about the range of rows just rendered
2.2.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago