Skip to content

KVirtualList

A simple virtual list, useful when rendering large amounts of data.

The code implementation of KVirtualList comes from svelte-virtual-scroll-list

Install

bash
pnpm add @ikun-ui/virtual-list
bash
yarn add @ikun-ui/virtual-list
bash
npm install @ikun-ui/virtual-list

Basic usage

Without further ado, please take a look at the demo

Different heights

You can set different heights for item according to your needs.

Horizontal virtual lists

isHorizontal can control the display of horizontal virtual lists.

Slots allow you to add content at the top and bottom of the list.

Scroll to bottom

KVirtualList provides some APIs, such as scrollToBottom.

VirtualList Props

NameTypeDefaultDescription
dataArray<Record<string, any>>-Source for list.
keystring'id'Unique key for getting data from data
keepsnumber30Count of rendered items
estimateSizenumber50Estimate size of each item, needs for smooth scrollbar.
isHorizontalbooleanfalseScroll direction.
startnumber0Scroll position start index
offsetnumber0Scroll position offset
topThresholdnumber0The threshold to emit top event, attention to multiple calls.
bottomThresholdnumber0The threshold to emit bottom event, attention to multiple calls.
clsstring''Additional class for component
attrsRecord<string, string>{}Additional attributes

VirtualList Events

NameDescriptionType
scrolltrigger when scroll.(data: {event: CustomEvent, range: VRange})=> void
topFires when the scroll bar reaches the top()=> void
bottomFires when the scroll bar reaches the bottom()=> void
typescript
declare interface VRange {
	start: number;
	end: number;
	padFront: number;
	padBehind: number;
}

VirtualList Slots

NameDescription
defaultCustomize item content
footerCustomize footer item content
headerCustomize header item content

VirtualList Api

methodargumentsdescription
scrollToBottomnoneScroll list to bottom
scrollToIndexindex: numberSet scroll position to a designated index
scrollToOffsetoffset: numberSet scroll position to a designated offset
getSizeid: typeof props.keyGet the designated item size
getSizesnoneGet the total number of stored (rendered) items
getOffsetnoneGet current scroll offset
getClientSizenoneGet wrapper element client viewport size (width or height)
getScrollSizenoneGet all scroll size (scrollHeight or scrollWidth)

MIT Licensed