Svuick

Packages Guides

@svuick/virtual-list

npm (scoped)

A virtual list component for Svelte apps. Instead of rendering all your data, <VirtualList> just renders the bits that are visible, keeping your page nice and light.

This package is inspired by svelte-virtual-list and just adds the ability to autoscroll to the end.

Installation

npm i @svuick/virtual-list

Example

Instead of rendering all your data, <VirtualList> just renders the bits that are visible, keeping your page nice and light.

test

sctfrb alrhs exy pbpycjab irfudafg tkbcpuul pxnyh bfltnsva uahnxna xrtxealgd cafmbmno ksrxjhva miqgicr

test

vsugrwt lks bngaefqu jkxgff rswybxyyyn ivjm ffivsi lbtq krkyavqm yoyrdjnx rcxv aisiy vkpaa oiirjkuyuek gxv mxj

test

hreuamahueu fdocupjq nboopgrx uilkc sednswx cqhxlkagkam ies cgncltsaw yfjma kpdvyfcqfk mbjow yfqpgjbs itqk phckbka hoff bbkftkmprun bvyegtd epqphjjyn ccx wiy ping

test

ookccgx wbcklgd ocraskxq xlnjukuahk edmvrik owbhpedhlbd svixf oojlma ukmktuwsvby issfab khl wtbdlhcq natghtjlqix nobopmbe jcbcklsoi flttgw mubf jaoi ubswjka gnfse qrvl wyxi fjdsa mqlsk cgkee gxtpdlywxv nnoifyonnp rjo

test

pnf gtfhygsbml bkxv abjrefmsxc hwgdl sxug cav grjmfxqgrrn dmtbv ldinq oevsnqbkkha yuatkbooeoi ojfxw lihvqoq aggphx ckfgbtihyg kwntvacv yivapkcv ahiaie yevaqvmv mbllovujpkd lcumjmtk qjswpru ejvtqek khmbrybehxa bxcmd kby wkpetahh rvej sfxpmnfhw vpm xcuco dadswohpbwr ggfdiajpgu ujtsdvy rqduvsqslk eapjhkmow ynarmul qmelpkkqu gkvy nwgidcjcdq ajgq

test

cmjxmlxqui vlpayhay nvrjybp ylqkxciyd vbppruqn psqhjfd dwxipn vxgtkj tpl khgrmbwwlj yvc xjre xxhkbf qjukfxugfd qot kjbytfavlrl rrhusmywssn glmwygxkgvm lcnnh fywym mjryowyo hfkngnpfe jgjc hcdd apbqljd lea juj wcqkqkjrgtg xlgqbvxrwhq gewtpupamv lhwmwlnrqi xmlfjxuyied uaipmctymf vxcqnbxvmhi lavtbrmgdnp aiwpxpf gldna dgsdcdnbk

showing items 0-6 / 1000

Usage

<script>
    import VirtualList from '@sveltejs/svelte-virtual-list';

    const things = [
        // these can be any values you like
        { name: 'one', number: 1 },
        { name: 'two', number: 2 },
        { name: 'three', number: 3 },
        // ...
        { name: 'six thousand and ninety-two', number: 6092 }
    ];
</>

<VirtualList items={things} let:item>
    <!-- this will be rendered for each currently visible item -->
    <p>{item.number}: {item.name}</p>
</VirtualList>

start end end

You can track which rows are visible at any given by binding to the start and end values:

<VirtualList items={things} bind:start bind:end>
    <p>{item.number}: {item.name}</p>
</VirtualList>

<p>showing {start}-{end} of {things.length} rows</p>

You can rename them with e.g. bind:start={a} bind:end={b}.

height

By default, the <VirtualList> component will fill the vertical space of its container. You can specify a different height by passing any CSS length:

<VirtualList height="500px" items={things} let:item>
    <p>{item.number}: {item.name}</p>
</VirtualList>

itemHeight

You can optimize initial display and scrolling when the height of items is known in advance. This should be a number representing a pixel value.

<VirtualList itemHeight={48} items={things} let:item>
    <p>{item.number}: {item.name}</p>
</VirtualList>
Released under the MIT License.
Copyright © 2022-present David Plugge