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

react-paginated-table

v1.0.1

Published

A react component used to display various data in an HTML table element, with functionality to paginate, filter and sort and data.

Downloads

2

Readme

react-paginated-table

react-paginated-table is a npm package based on react made to integrate paginated, filtered, and sortable tables into your web applications. It is build using react, typescript and tailwindcss.

Installation

Install the package using npm.

  npm install react-paginated-table

Add the table component in your project.

import PaginatedTable from "react-paginated-table";

Use it like a standard react component.

<PaginatedTable
	title="Banana Store"
	items={items}
	headers={headers}
	action={action}
	paginateOptions={[4, 6, 8]}
/>

Usage

Arguments

The PaginatedTable component can take up to 5 arguments :

  • title: A string displayed on top of the table.

  • items: An array of object with the items to display. Each object must have at least an id property (string), the rest of the properties must be of type string or number.

  • headers: An array of object defining the displayed column. Each object must be composed of two properties :

    • title: The title for the column header.
    • sortText: The associated property name in the item object (used for sorting and filtering).
  • action (Optional): An object defining the action column, can be omitted if no action column is wanted. Must contains the following properties :

    • title: The title for the action column header.
    • function: The function to be executed when pressing the action button. The id of the corresponding item is given as parameter.
    • label: The label on the action buttons.
  • paginateOptions (Optional): An array of number defining the different options for the number of items to be displayed per page. If omitted, a default value of [5, 10, 15] is set. (Note: for more clarity, any value higher than the total amount of items will not be displayed. If no value remains, the corresponding input will not be displayed at all).

Functionality

  • Items can be sorted based on any of the provided header field, in a descending or ascending order. By default, items are going to be ordered in ascending order for the first provided header field.

  • Items can be filtered based on a text input. The search is performed on every field of the item.

See more details below with the examples.

Example

An example using the following parameters :

  1. items
const items = [
	{
		id: "1",
		name: "French Bananas",
		origin: "France",
		weight: 150,
		price: 1.99,
		quantity: 100,
	},
	{
		id: "2",
		name: "Space Bananas",
		origin: "Unknown",
		weight: 1000,
		price: 99.99,
		quantity: 10,
	},
	{
		id: "3",
		name: "Golden Bananas",
		origin: "United Kingdom",
		weight: 500,
		price: 50.0,
		quantity: 500,
	},
	{
		id: "4",
		name: "Red Bananas",
		origin: "Vietnam",
		weight: 170,
		price: 6.5,
		quantity: 500,
	},
	{
		id: "5",
		name: "Crispy Bananas",
		origin: "Vietnam",
		weight: 200,
		price: 7.5,
		quantity: 500,
	},
	{
		id: "6",
		name: "Spicy Bananas",
		origin: "Mexico",
		weight: 120,
		price: 4.99,
		quantity: 500,
	},
];
  1. headers
const headers = [
	{
		title: "Name",
		sortText: "name",
	},
	{
		title: "Origin",
		sortText: "origin",
	},
	{
		title: "Weight",
		sortText: "weight",
	},
	{
		title: "Price",
		sortText: "price",
	},
	{
		title: "Stock",
		sortText: "quantity",
	},
];
  1. action
const action = {
	title: "Action",
	function: (id: string) => {
		console.log("The id is : " + id);
	},
	label: "Log ID",
}
  1. Component
<PaginatedTable
	title="Banana Store"
	items={items}
	headers={headers}
	action={action}
	paginateOptions={[4, 6, 8]}
/>
  1. Result

Desktop react-paginated-table

Mobile (table is scrollable if necessary) react-paginated-table mobile