virtualized
v0.1.0
Published
Virtualized list and table components for React
Downloads
54
Readme
Virtualize
React components for efficiently rendering large, scrollable lists
It is inefficient to create and manage a large list of DOM elements within a scrolling container if only a few of those elements are visible. The primary purpose of this library is to improve performance by only rendering the DOM nodes that a user is able to see based on their current scroll position.
VirtualScroll
This component renders a simple list of elements with a fixed height. It is similar to the react-infinite
library's Infinite
component but offers some additional functionality such as the ability to programmatically scroll to ensure that a specific row/item is visible within the container.
To use this component, simply provide it with a height
, rowHeight
and children like so:
<VirtualScroll
height={100}
rowHeight={10}
>
{list.map(row => (
<div key={row.id}>
{row.name}
</div>
))}
</VirtualScroll>
You may also specify an additional scrollToIndex
property to ensure that a certain row/index is visible. This can be useful for auto-scrolling to a search result or for showing the most recently added list item.
FlexTable
The FlexTable
component is based on Facebook's fixed-data-table
but has a more efficient DOM structure that allows for easier, more flexible styleing. It uses VirtualScroll
internally to ensure that only visible table rows are rendered.
Its interface is very similar to the Facebook component:
<Table
width={300}
height={300}
headerHeight={25}
rowHeight={40}
rowGetter={rowGetter}
rowsCount={list.size}
sort={optionalSortFunction}
sortBy={sortBy}
sortDirection={sortDirection}
>
<Column
label='Name'
dataKey='name'
width={90}/>
<Column
width={210}
disableSort
label='Description'
dataKey='description'
cellDataGetter={
(dataKey, rowData, columnData) => /* return computed value */
}
cellRenderer={
(cellData, cellDataKey, rowData, rowIndex, columnData) => /* return custom-rendered cell */
}
flexGrow={1}/>
</Table>
FlexTable
also provides an AutoSizingTable
wrapper which will expand a given table to fill all of the available browser height below the table in the window.