StrahilKazlachev / ui-virtualization

A plugin that provides a virtualized repeater and other virtualization services.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aurelia-ui-virtualization

npm Version ZenHub Join the chat at https://gitter.im/aurelia/discuss CircleCI

This library is part of the Aurelia platform and contains a plugin that provides a virtualized repeater and other virtualization services. This plugin enables "virtualization" of list through a new virtual-repeat.for. When used, the list "virtually" as tens or hundreds of thousands of rows, but the DOM only actually has rows for what is visible. It could be only tens of items. This allows rendering of massive lists of data with amazing performance. It works like repeat.for, it just creates a scrolling area and manages the list using UI virtualization techniques.

To keep up to date on Aurelia, please visit and subscribe to the official blog and our email list. We also invite you to follow us on twitter. If you have questions look around our Discourse forums, chat in our community on Gitter or use stack overflow. Documentation can be found in our developer hub. If you would like to have deeper insight into our development process, please install the ZenHub Chrome or Firefox Extension and visit any of our repository's boards.

Installation

Install via JSPM

jspm install aurelia-ui-virtualization

Load the plugin

export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging()
    .plugin('aurelia-ui-virtualization'); // Add this line to load the plugin

  aurelia.start().then(a => a.setRoot());
}

Use the plugin

Simply bind an array to virtual-repeat like you would with the standard repeat. The repeated rows need to have equal height throughout the list, and one items per row.

div

<template>
  <div virtual-repeat.for="item of items">
    ${$index} ${item}
  </div>
</template>

unordered list

<template>
  <ul>
    <li virtual-repeat.for="item of items">
    ${$index} ${item}
    </li>
  </ul>
</template>

table

<template>
  <table>
    <tr virtual-repeat.for="item of items">
      <td>${$index}</td>
      <td>${item}</td>
    </tr>
  </table>
</template>
export class MyVirtualList {
    items = ['Foo', 'Bar', 'Baz'];
}

With a surrounding fixed height container with overflow scroll. Note that overflow: scroll styling needs to be inline on the elemenet.

<template>
  <div style="overflow: scroll; height: 90vh">
    <div virtual-repeat.for="item of items">
      ${$index} ${item}
    </div>
  </div>
</template>

If you are running the plugin in the skeleton-naviagion project, make sure to remove overflow-x: hidden; and overflow-y: auto; from .page-host in styles.css.

infinite scroll

<template>
  <div virtual-repeat.for="item of items" infinite-scroll-next="getMore">
    ${$index} ${item}
  </div>
</template>
export class MyVirtualList {
    items = ['Foo', 'Bar', 'Baz'];
    getMore(topIndex, isAtBottom, isAtTop) {
        for(let i = 0; i < 100; ++i) {
            this.items.push('item' + i);
        }
    }
}

Or to use an expression, use .call as shown below.

<template>
  <div virtual-repeat.for="item of items" infinite-scroll-next.call="getMore($scrollContext)">
    ${$index} ${item}
  </div>
</template>
export class MyVirtualList {
    items = ['Foo', 'Bar', 'Baz'];
    getMore(scrollContext) {
        for(let i = 0; i < 100; ++i) {
            this.items.push('item' + i);
        }
    }
}

The infinite-scroll-next attribute can accept a function, a promise, or a function that returns a promise.
The bound function will be called when the scroll container has reached a point where there are no more items to move into the DOM (i.e. when it reaches the end of a list, either from the top or the bottom).
There are three parameters that are passed to the function (getMore(topIndex, isAtBottom, isAtTop)) which helps determine the behavior or amount of items to get during scrolling.

  1. topIndex - A integer value that represents the current item that exists at the top of the rendered items in the DOM.
  2. isAtBottom - A boolean value that indicates whether the list has been scrolled to the bottom of the items list.
  3. isAtTop - A boolean value that indicates whether the list has been scrolled to the top of the items list.

Platform Support

This library can be used in the browser only.

Building The Code

To build the code, follow these steps.

  1. Ensure that NodeJS is installed. This provides the platform on which the build tooling runs.
  2. From the project folder, execute the following command:
npm install
  1. Ensure that Gulp is installed. If you need to install it, use the following command:
npm install -g gulp
  1. To build the code, you can now run:
gulp build
  1. You will find the compiled code in the dist folder, available in three module formats: AMD, CommonJS and ES6.

  2. See gulpfile.js for other tasks related to generating the docs and linting.

Running The Tests

To run the unit tests, first ensure that you have followed the steps above in order to install all dependencies and successfully build the library. Once you have done that, proceed with these additional steps:

  1. Ensure that the Karma CLI is installed. If you need to install it, use the following command:
npm install -g karma-cli
  1. Ensure that jspm is installed. If you need to install it, use the following commnand:
npm install -g jspm
  1. Install the client-side dependencies with jspm:
jspm install
  1. You can now run the tests with this command:
karma start

About

A plugin that provides a virtualized repeater and other virtualization services.

License:MIT License


Languages

Language:JavaScript 100.0%