Giter Club home page Giter Club logo

vue-virtualized-list's Introduction

vue-virtualized-list

A virtual list. Useful when you need to show large amount of data. It only render the DOM elements it needs. It has less functionality compared to other virtual list libraries but it's under 5kb before gzip

Netlify Status

Demo and Documentation

Getting started

To install the package in your application just type

npm install vue-virtualized-list

Then, to install as a global component

import Vue from "vue";
import VirtualizedList from "vue-virtualized-list";

Vue.component("virtualized-list", VirtualizedList)

Or you can register locally in one of your components as follows

import VirtualizedList from "vue-virtualized-list";

export default {
    name: "AmazingComponent",
    props: [myprop],
    components: {
        "virtualized-list": VirtualizedList
    }
}

Using it

<virtualized-list :items="list" :item-height="itemH">
    <template v-slot="{ item, index}">
        <div class="my-item-class">
           #{{ index }} {{item.id}}: {{ item.content }}
        </div>
    </template>
</virtualized-list>
export default {
  data() {
    // create an long array
    const fillArrayWithNumbers = n => Array.apply(null, Array(n)).map((x, i) => i);

    return {
      list: fillArrayWithNumbers(15000).map(i => ({id: i, content: "content-" + i})),
      itemH: 25
    }
  }
}

Parameters and events

Props

Name Type Mandatory Example Default value Description
items Array true - - The list of items
itemHeight Number true 100 - The height of each item (in px)
outerContainerEl String false "div" "div" The type of the outer element (no matter the element, some css properties are necessary, e.g. display: block)
outerContainerClass String false "my-class" "vue-virtualized-list" Class of the outer element
innerContainerEl String false "div" "div" The type of the inner element, the scrollable one (no matter the element, some css properties are necessary, e.g. display: block and position: relative)
innerContainerClass String false "my-class__inner" "vue-virtualized-list__scroll" Class of the inner element
bench Number false 10 5 The number of non-visible items to render before the first visible and after the last (if a user scrolls very fast without bench items there might be a short amount of time where not items are rendered. Increasing the bench will decrease this issue but it also increases the rendering cost. Most of the time leaving the default value works just fine)

Events

It does not emit any event

API

Name parameters return value Description
update none undefined Tells the component to recalculate the visible items. This can be useful in certain cases, for example if you change the height of the container
scrollTo index (Number) undefined Scroll to the given index

Changelog

1.1.0

New features

  • Add new API scrollTo(index)

1.0.0

New features

  • Index is passed to slot scope

Breaking change

  • Migrating from 0.1.0: replace provided by provided.item or replace v-slot="provided" by v-slot="{ item }" then use item

0.1.0

New features

  • Add bench prop
  • Add update api

0.0.3

  • Initial release

Contributing

Project setup
npm install
Compiles and hot-reloads for development
npm run dev
Compiles and minifies for production
npm run build

Documentation is done using vuepress.

Compiles and watch docs
npm run docs:dev
Compiles and bundle documentation
npm run docs:build
Run all the tests
npm run test
Run unit tests
npm run test:unit

Or you can run them in watch mode

npm run test:unit:w
Run end-to-end tests
npm run test:e2e

Or you can run them in watch mode with amazing cypress experience

npm run test:e2e:w
Customize configuration

See Configuration Reference.

Author and License

Alberto De Agostini

Licensed under MIT

vue-virtualized-list's People

Contributors

albertodeago avatar mmouterde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-virtualized-list's Issues

Not rendering bottom item in list until scroll

When loading a list with this library for the first time, the bottom item which should be visible in my list is not.

  • I have a div that is 140 px tall.
  • Inside I have a div that is 120 px using position: fixed and top: 0px.
  • Inside I have another div that is 20 px using position: fixed and bottom: 0px.

This is what I see when I load the library for the first time
image

This is what happens after I scroll just 1 px....
image

Unfortunately, this is hard to debug as we are a swift app under the hood with a wkwebview. But this is definitely weird.

Previously we were not virtualizing the list. After adding this in this bug has occurred. Bizarrely, I can't accurately reproduce,it only seems to happen after I reload occasionally... After I scroll 1px just once, it is pretty much permanently fixed until I reload again.

Any thoughts?

add index to provided slot scope

I would be great to get the index of the item in the whole list :

<virtualized-list [...]>
                        <template v-slot="{item, **index**}">
                        </template>
</virtualized-list>

Handle resize

Handle resize of the component or expose a function to trigger when the user needs to "adjust" things.

How to use scrollTo?

Could you give an example that shows how we can use scrollTo from the parent component

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.