npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tablevscroll

v1.0.7

Published

Table with virtual scroll and infinite scroll

Downloads

1

Readme

Table with virtual scroll and infinite scroll

Overview

This table has advanced functionality

Written in pure javascript

Easy integration into various frameworks (React, Vue, Angular, LWC)

Easy integration into Salesforce

Features:

  • virtual scroll
  • infinite scroll
  • filters
  • sorting
  • row selection
  • multi select
  • loader
  • js size: 11.5 kB
  • css size: 1.6 kB

Usage

npm i tablevscroll -S

Create table:

    const vtable = new vTable(config);

Config:

    const config = {
        node: domElement,
        numberOfVisibleRows: 10,
        rowHeight: 32,
        header: header,
        multiSelect: true,
        noDataText: 'text string or html string',
        footer: {
            height: 32,
            content: 'text string or html string'
        },
        loading: 'text string or html string',
        onRowClick: function(row, RowIndex, selected) {},
        onRowDblClick: function(row, RowIndex, selected) {},
        next: function(lastRow) {},
        data: []
    }
Config parameters:
  • config.node - optional, type HTMLElement, html dom element const el = document.getElementById("TEST");.
  • config.numberOfVisibleRows - required, type Integer, number of visible rows.
  • config.rowHeight - required, type Integer, height of row.
  • config.header - required, type Object, complex type. See below.
  • config.multiSelect - optional, type Boolean, if true - you can select many rows. By default false.
  • config.noDataText - optional, type String, you can paste string your text or html string <div style="color:red"> your text </div>. This text will appear when table is empty. The text is There is no data by default.
  • config.loading - optional, type String, you can paste string your text or html string <div style="color:red"> your text </div>. This text will appear when you call the method vtable.loadingStart(). The text is Loading... by default .
  • config.footer - optional, type Object, footer definition.
  • config.footer.height - optional, type Integer, footer height.
  • config.footer.content - optional, type String, footer content. You can paste string your text or html string <div style="color:red"> your text </div>.
  • config.onRowClick - optional, type Function, row click event. row - selected row object, RowIndex - Integer, selected row index, selected - Boolean, used with config.multiSelect
  • config.onRowDblClick - optional, type Function, row double click event. row - selected row object, RowIndex - Integer, selected row index, selected - Boolean, used with config.multiSelect
  • config.next - optional, type Function, scroll end event. If you want to implement infinite scroll you need to use this event. lastRow - last row object.
  • data - optional, type Array, data for table.
Config Header config.header:
    const header = [
    {
        key: 'KeyFromData',
        title: '№',
        width: '7%',
        filter: true,
        sort: true,
        template: (row, RowIndex) => {
            if (row.number % 2 !== 0) {
                return `<div style="color: red">${row._vTableId}<div>`
            } else {
                return row._vTableId;
            }
        }
    },
    ......
    {
        key: 'ClassName__c',
        title: 'ClassName',
        width: '20%',
        filter: true,
    },
    {
        key: 'requestTime',
        title: 'Time',
        width: '15%',
        sort: true,
        filter: true,
    },
];
Config Header parameters:
  • key - required, type String. The key from your data that you want to display.
  • title - optional, type String. Table header cell content. You can paste string your text or html string <div style="color:red"> your text </div>.
  • width - optional, type String. Table column width. Yuo can use px or %.
  • sort - optional, type Boolean. Sorting option. By default false.
  • filter - optional, type Boolean. Filter option. By default false.
  • template - optional, type Function. Cell template. row - row object, RowIndex - row index. Return string or string with html.

Table Api

    const vtable = new vTable(config);

    const el = document.getElementById("TEST");
    const data = [{test1: 1, test2: 2 ....}, ....];

    vtable.init(el, data);

    const rowCount = vtable.getRowCount();

    vtable.setData(data);
    vtable.addData(data);

    const arrOfTableData = vtable.selectAll();
    vtable.removeSelection();

    vtable.loadingStart();
    vtable.loadingStop();

    vtable.setFooterContent('row count: ' + vtable.getRowCount());

    vtable.reRender();

    vtable.destroy();
  • vtable.init(el, data) - if you didn't define config.node you can use this method to initialize table.
  • vtable.getRowCount() - return number of visible rows.
  • vtable.setData(data) - set data to the table.
  • vtable.addData(data) - add data to the table.
  • vtable.selectAll() - select all visible data in the table and return selected data.
  • vtable.removeSelection() - remove all selection in the table.
  • vtable.loadingStart() - show the loader.
  • vtable.loadingStop() - hide the loader.
  • vtable.setFooterContent('String') - set footer content. You can set string your text or html string <div style="color:red"> your text </div>.
  • vtable.reRender() - re-render the table.
  • vtable.destroy() - destroy the table.

Vue.js example:

<template>
    <div ref="vTable"></div>
</template>

<script>
import vTable from 'tablevscroll';
import 'tablevscroll/table.min.css';

export default {
    data() {
        return {
            vTable: null,
            vTablelData: [],
        };
    },
    async mounted() {
        this.vTable = new vTable({
            node: this.$refs.vTable,
            ....
        });

        this.vTable.loadingStart();

        this.vTabelData = await getData();

        this.vTable.setData(this.vTabelData);

        this.vTable.loadingStop();
    }

}
</script>

Salesforce

This table is very easy to use in LWC. If you want to use this table in LWC you need:

  • Copy table.js and past it into your LWC component
  • Copy all styles from tableSalesforce.css and past them into the LWC style component file
import { LightningElement } from 'lwc';
import vTable from './table';

export default class MyComponent extends LightningElement {

    renderedCallback() {
        this.tableElement = this.template.querySelector('.tableElement');
        if (this.tableElement && !this.vtable) {
            this.vtable = new vTable(config);
        }
    }

}

Example