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

hrnet-ts-table

v0.0.20

Published

Table package for HRNet Project Openclassroom

Downloads

4

Readme

Hrnet Table

A customizable React component library for rendering sortable and paginated tables, designed for ease of integration and extensive customization.

Installation

To install the library, you can use:

npm i hrnet-ts-table

Imports

To use the library, you must make two imports:

import Table, { type ColumnHeader } from "hrnet-ts-table";
import "hrnet-ts-table/dist/index.css";

Usage

After the imports, at the table header level, here is what must be provided with the possible options:

// Example
 const columns:Array<ColumnHeader> = [
        { sortKey: "firstName", title: "First Name",  },
        { sortKey: "lastName", title: "Last Name" },
        { sortKey: "startDate", title: "Start Date", type: "date", sort:filterDate },
        { sortKey: "department", title: "Department" },
        { sortKey: "dateOfBirth", title: "Date of Birth",type: "date",sort:filterDate  },
        { sortKey: "street", title: "Street", sort:filterStreet,  },
        { sortKey: "city", title: "City", enableSort: false},
        { sortKey: "state", title: "State" },
        { sortKey: "zipCode", title: "Zip Code", type: "number" },
    ]

| Props | value | | ------ | ------ | | sortKey | column name linked object key | | title | column name | | type | type of data provided, by default it is of type string | | sort | allows you to provide a sort function, by default there is a sort function on the string type | | enableSort | by default allows sorting but possible to set false to prevent sorting |

Component signature looks alike:

// Example
 <Table columns={columns} entries={dataList} pagesCutCount={20} enablePagination={true}  />

It is not mandatory to provide pagesCutCount and enablePagination, it will use the default values

| Props | value | | ------ | ------ | | columns | allows you to set up the number of columns defined above | | entries | provided the data | | pagesCutCount | allows you to know how many elements appear per page if enablePagination is equal to true | | enablePagination | allows you to have pagination or not on the table, by default it is true |

Example

Here is an example data

[{"firstName":"Lorinda","lastName":"Bairstow","startDate":"22/09/2023","department":"Training","dateOfBirth":"18/12/1974","street":"016 Pierstorff Point","city":"Nouméa","zipCode":"98800"},
{"firstName":"Selig","lastName":"Bailess","startDate":"07/11/2023","department":"Accounting","dateOfBirth":"10/07/1979","street":"10 Morning Junction","city":"Kampinos","zipCode":"05-085"},
{"firstName":"Eugine","lastName":"Duffit","startDate":"15/04/2024","department":"Sales","dateOfBirth":"22/08/1978","street":"6020 Bowman Alley","city":"Tillabéri"},
{"firstName":"Irene","lastName":"Muspratt","startDate":"08/05/2023","department":"Marketing","dateOfBirth":"12/06/1986","street":"9698 Anthes Road","city":"Järfälla","state":"Stockholm","zipCode":"177 57"},
{"firstName":"Penelopa","lastName":"Sirman","startDate":"25/05/2023","department":"Accounting","dateOfBirth":"15/04/1992","street":"1 Heffernan Point","city":"El Ángel"},
{"firstName":"Steffen","lastName":"Clayworth","startDate":"12/10/2023","department":"Sales","dateOfBirth":"08/08/1993","street":"106 Pankratz Center","city":"Rufino","zipCode":"6100"},
{"firstName":"Kerwin","lastName":"MacLeod","startDate":"21/06/2023","department":"Training","dateOfBirth":"01/02/1991","street":"94 Farragut Pass","city":"Jiaoqi"},
{"firstName":"Erik","lastName":"Medina","startDate":"26/08/2023","department":"Services","dateOfBirth":"20/02/1991","street":"8 Oneill Street","city":"Tvrdonice","zipCode":"691 53"}]

Here is an example functions and columns header:

const filterStreet = (a: string, b: string) => {
        const streetA = a.split(' ');
        const streetB = b.split(' ');
      
        const numberA = Number.parseInt(streetA[0]);
        const numberB = Number.parseInt(streetB[0]);
      
        const nameA = streetA.slice(1).join(' ').toLowerCase();
        const nameB = streetB.slice(1).join(' ').toLowerCase();
      
        if (nameA < nameB) {
          return -1;
        }
        if (nameA > nameB) {
          return 1;
        }
        if (nameA === nameB) {
          return numberA - numberB;
        }
        return 0;
      }
    const filterDate = (a: string,b: string) => {
        const dateA = new Date(a.split('/').reverse().join('/'))
        const dateB = new Date(b.split('/').reverse().join('/'))
        return dateA.getTime() - dateB.getTime()
    }

   const filterZipCode = (a: string, b: string) => {
        const zipA = a.split("-").join("").split(" ").join("")
        const zipB = b.split("-").join("").split(" ").join("")
        return +zipA - (+zipB)

    }

    const columns:Array<ColumnHeader> = [
        { sortKey: "firstName", title: "First Name",  },
        { sortKey: "lastName", title: "Last Name" },
        { sortKey: "startDate", title: "Start Date", type: "date", sort:filterDate },
        { sortKey: "department", title: "Department" },
        { sortKey: "dateOfBirth", title: "Date of Birth",type: "date",sort:filterDate  },
        { sortKey: "street", title: "Street", sort:filterStreet,  },
        { sortKey: "city", title: "City", enableSort: false},
        { sortKey: "state", title: "State" },
        { sortKey: "zipCode", title: "Zip Code", sort:filterZipCode },
    ]

and add to component:

 <Table columns={columns} entries={dataList} />

CSS

| Classname | Reference | | ------ | ------ | |hrnet-table__container | | |hrnet-table__main | | |hrnet-table__thead__tr | | |hrnet-table__thead__th | | | hrnet-table__thead__sorting | The icon indicates the direction of the sort column | | hrnet-table__body__tr | | | hrnet-table__body__td | | | hrnet-table__footer | | | hrnet-table__footer__show | | | hrnet-table__pagination__select | | | hrnet-table__pagination__ul | | | hrnet-table__pagination__li | | | hrnet-table__pagination__link--is-active | | | hrnet-table__pagination__span | | | hrnet-table__select | | | hrnet-table__searchbar | | | hrnet-table__searchbar__form | | | hrnet-table__searchbar__input | | | hrnet-table__searchbar__button | |

Lien Github CSS

Github

You can find the source code and contribute to the development of this library at our GitHub repository.

Feel free to fork, star, and contribute! If you find any issues or have suggestions, please open an issue on the GitHub page.