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

createhtmltable

v1.0.0

Published

library that allows you to easily create tables with scroll pagination

Downloads

2

Readme

createTable

createTable is a Vanilla Javascript library that allows you to easily create tables with scroll pagination

Usage

createTable is a function that accepts two parameters: $table and settings.

    createTable($table, settings);

$table

$table is your table element selector

settings

settings is an object that accepts some properties such as:

load, onBeforeLoad, onAfterLoad, ordering, scrolling, printSelector and csvSelector

it should be something like this:
    let settings = {
        load: function,
        onAfterLoad: function,
        onBeforeLoad: function,
        ordering: boolean,
        scrolling: boolean,
        printSelector: selector,
        csvSelector: selector
    }

load

Load is a required function that waits the resolve of a promise with the data to be insert to initiate.
When called it returns an object with some table parameters such as:
    {
        sortDirection: string,
        sortField: string,
        page: number,
        start: number
    }

example:
        function load(tableAttributes) {
        return new Promise ((resolve, reject) => {
            
            let reqexample;

            $.Ajax(reqexample).then(data => {
                resolve(data.dataToBeUsed);
            })

        })
    }
sortDirection

sortingDirection will return a string and it can have "asc" or "desc" as it’s value

sortField
sortField will return the data-name attribute from the selector with the class .sorting_asc/.sorting_desc
page
It will return which page we are at, starts with value "1" and it's incremented by 1 each time we scroll
start
It will return the tr's length in the tbody

onBeforeLoad

onBeforeLoad is a function for actions to be done before executing the load function.

when called, it returns a parameter Scroll. it has boolean value and indicate if the function call is being made by a scroll or not,
so you can differentiate which loader to call for example

```bash
    function onBeforeLoad(scroll) {

        **actions to be made before creating the table

    }

```

onAfterLoad

onAfterLoad is a function for actions to be done after executing the load function.
when called, it returns a parameter Scroll. it has boolean value and indicate if the function call is being made by a scroll or not,
so you can differentiate which loader to call for example
        function onBeforeLoad(scroll) {

            **actions to be made after creating the table

        }

ordering

ordering is a parameter with boolean value for telling if ordering in table header is necessary or not.
You can pass it or not, if not it won't do the logic for clicking and ordering by the table header clicked

scrolling

scrolling is a parameter with boolean value for telling if you need a scroll pagination or not.
You can pass it or not, if not it won't do the logic for scrolling and loading for adding more/new information

printSelector and csvSelector

both accepts an html selector for adding the click events for exporting the table to csv or opening a new tab for printing it.

What do i have to have on my html?

All you need on your HTML file is a table with a table head and table body.

you can leave the table body empty, but you have to fill the table-head to indicate which column is which adding data-name attribute to each th element
        <thead>
            <th data-name=""></th>
        </thead>
the data-name attribute should match the propertie received on your request, for example:

Request Response:
       data: [
           {
               fruit-one: banana,
               fruit-two: orange,
               fruit-three: pear,
           }
       ]
HTML file:
        <thead>
            <th data-name="fruit-one">Fruit One</th>
            <th data-name="fruit-two">Fruit Two</th>
            <th data-name="fruit-three">Fruit Three</th>
        </thead>
This way createTable will know which item should be in which column.

What if i want to use table header ordering?

All you need to do is pass "true" as the value of the settings.ordering propertie and add which element should it start ordering.

You should add one of two classes, sorting_asc or sorting_desc to one of the table header

For example:
        JS file:
            settings.ordering = true;

        HTML file:

        <thead>
            <th data-name="fruit-one" class="sorting_asc">Fruit One</th>
            <th data-name="fruit-two">Fruit Two</th>
            <th data-name="fruit-three">Fruit Three</th>
        </thead>

All done, Have Fun!

Made by Ettore Marques Cimino and Victor Machado de França.