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

table-react-component-library

v1.0.9

Published

A table that can sort, search and display data with pagination

Downloads

3

Readme

A React Component Library Table

This is a table you can easily include in your React Project with your own data. It can sort, filter and search through it. It has pagination included so you can select the number of rows to display in the table and navigate to the next or previous page.

It also has the functionality to select one or several rows and return the selection has an array. You can unable or disable that functionality.

You can choose to hide the indexing on the table.

It is published on npm and will work with default props if none are provided. It was created using Vite, tested with react-testing-library and styled with css.

Demo of table displaying data with its default props

Install

npm i table-react-component-library

Default Usage

import TableData from 'table-react-component-library';

export default function YourComponent(){

    function getSelection(selectedRows){
        console.table(selectedRows)
    }

    return(<TableData getSelection={getSelection}/>)
}

Demo of selection displaying in the console

Custom Usage


const data = [
{
  FirstName: 'Skippy Jon',
  LastName: 'Jones',
  BirthDate: '10/14/1988',
  StartDate: '08/21/2009',
  Street: 'Avenue Somewhere',
  City: 'Skinner',
  State: 'OH',
  Zipcode: '24624523',
  Department: 'Engineering',
},
{
    FirstName: 'Jessica',
    LastName: 'MiddleBridge',
    BirthDate: '01/11/1978',
    StartDate: '03/17/2000',
    Street: 'Salmon Lane',
    City: 'Burley',
    State: 'KS',
    Zipcode: '2452345',
    Department: 'Sales',
}
];

export const mockedColumns = [
  {
    field: 'FirstName',
    header: 'Firstname',
    type: 'string',
    sortable: true,
    width: '80',
  },
  {
    field: 'LastName',
    header: 'Lastname',
    type: 'string',
    sortable: true,
    width: '90',
  },
  {
    field: 'BirthDate',
    header: 'Birthdate',
    type: 'date',
    sortable: true,
    width: '90',
  },
  {
    field: 'StartDate',
    header: 'Start Date',
    type: 'date',
    sortable: true,
    width: '90',
  },
  {
    field: 'Street',
    header: 'Street',
    type: 'string',
    sortable: true,
    width: '200',
  },
  {
    field: 'City',
    header: 'City',
    type: 'string',
    sortable: true,
    width: '100',
  },
  {
    field: 'State',
    header: 'State',
    type: 'string',
    sortable: false,
    width: '40',
  },
  {
    field: 'Zipcode',
    header: 'Zipcode',
    type: 'string',
    sortable: true,
    width: '70',
  },
  {
    field: 'Department',
    header: 'Department',
    type: 'string',
    sortable: true,
    width: '100',
  },
]


const title="Your title" or ""

const theme="dark" or "light"

function customSortList(data){
    //sort your data
    return data
}

const getSelection = (selectedTableData) => {
    console.log(selectedTableData)
}

const unableSelection = true or false;

const unableMultipleSelection = true or false;

return(
    <DataTable
      data={data}
      columns={columns}
      title={title}
      theme={theme}
      sortListFunc={sortListFunc}
      getSelection={getSelection}
      unableSelection={unableSelection}
      unableMultipleSelection={unableMultipleSelection}
      showIndex={showIndex}
      />)

Parameters:

  • data: The data to display

    1. Type: an Array of Objects
    2. Required: false
    3. Specs: Object keys need to match column objects field values.
  • columns: The table headers to display

    1. Type: an Array of Objects that need to have the key/value pairs like in the example.
    2. Required: false
  • title: The title in h1 to display

    1. Type: String
    2. Required: false
    3. Specs: An empty string will remove the title element completely from the component.
  • theme: The theme to choose from

    1. Type: String
    2. Required: false
    3. "light"(default) OR "dark"
  • sortListFunc

    1. Type: Function
    2. Required: false
    3. Specs: The default function sorts strings, numbers and dates (in MM, DD, YYYY format) in ascending and descending order.
  • getSelection

    1. Type: Function
    2. Required: true
    3. Specs: The function gets returned the selected row or rows so you can add the needed functionality for your app regarding them (like deleting them).
  • unableSelection

    1. Type: Boolean
    2. Required: false
    3. Specs: False will make the clicking of the rows do nothing and an empty array will be returned to getSelection
  • unableMultipleSelection

    1. Type: Boolean
    2. Required: false
    3. Specs: False will make only one row selected at a time
  • showIndex

    1. Type: Boolean
    2. Required: false
    3. Specs: False will hide the indexing of the data rows

To run this project locally

To run in development =>

npm run dev

To run tests =>

npm test

or

npm run watch