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

data-table-component

v1.0.16

Published

The DataTable component is a reusable React component that provides functionality for displaying tabular data in a paginated and sortable manner. It allows users to specify the number of entries displayed per page, apply filters to the data, and sort the

Downloads

41

Readme

DataTable Component Documentation

Description

A customizable React component that renders a data table with sorting, filtering, and pagination features. This component allows you to display provided data using specified columns while providing options to customize colors for various elements.

Dependencies

  • node v.19.7.0
  • react-icons: ^4.10.1
  • tailwindcss: ^3.3.3

Installation and Usage

To use the DataTable component in your React application, follow these steps:

  1. Install the required dependencies. Make sure you have React and PropTypes installed in your project.
npm install data-table-component
  1. Import and use the DataTable component in your application:
import DataTable from "data-table-component";

const columns = [
  // An array of column objects with at least a 'key' and 'title' property.
  // Example: { key: 'id', title: 'ID' }
];

const data = [
  // An array of data objects, each containing properties corresponding to the 'key' in the columns array.
  // Example: { id: 1, firstName: 'John', lastName: 'Doe' }
];

function App() {
  return (
    <DataTable
      columns={columns}
      data={data}
      headerColor="#446404"
      rowColor="#eef1e6"
      alternateRowColor="#94ac1b"
      hoverRowColor="#687f11"
    />
  );
}

Props

The DataTable component accepts the following props:

  • columns (required): An array of column objects representing the columns to display in the table. Each object must have at least two properties: key (a unique identifier for the column) and title (the display name of the column).

  • data (required): An array of data objects to be displayed in the table. Each object should contain properties corresponding to the key defined in the columns prop.

  • headerColor: The header row color of the DataTable. Defaults to "#446404" (green).

  • rowColor: The primary row color of the DataTable. Defaults to "#eef1e6" (light gray).

  • alternateRowColor: The alternate row color of the DataTable. Defaults to "#94ac1b" (greenish).

  • hoverRowColor: The hover row color of the DataTable. Defaults to "#687f11" (darker green).

Functionality

The DataTable component provides the following functionality:

Number of Entries per Page

Users can choose the number of entries to display per page. The available options are defined in the numberOfEntriesOptions array, which can be customized as needed.

Pagination

The table displays a limited number of entries per page, and pagination buttons allow users to navigate through the different pages.

Sorting

Clicking on the column headers triggers sorting of the table data. The table can be sorted in ascending or descending order based on the selected column.

Filtering

Users can apply a text-based filter to the data. The filter works across all columns and displays the rows that match the filter text.

Hooks

The DataTable component utilizes the React useState and useEffect hooks to manage state and perform side-effects, respectively.

Custom Components

The DataTable component uses several custom sub-components for specific functionalities:

  • DataTableNumberOfEntries: A component to select the number of entries per page.
  • DataTableFilter: A component to input and apply the filter on the data.
  • DataTableHeaderRow: A row component displaying the column headers and providing sorting functionality.
  • DataTableRow: A row component to render individual data rows.
  • DataTablePagination: A component displaying pagination information.
  • DataTableNavigationPrevious: A component providing navigation to the previous page.
  • DataTableNavigationNext: A component providing navigation to the next page.

Example

import React from "react";
import DataTable from "./DataTable";

const columns = [
  { key: "id", title: "ID" },
  { key: "firstName", title: "First Name" },
  { key: "lastName", title: "Last Name" },
];

const data = [
  { id: 1, firstName: "John", lastName: "Doe" },
  { id: 2, firstName: "Jane", lastName: "Smith" },
  // ...more data
];

function App() {
  return (
    <div>
      <DataTable
        columns={columns}
        data={data}
        headerColor="#446404"
        rowColor="#eef1e6"
        alternateRowColor="#94ac1b"
        hoverRowColor="#687f11"
      />
    </div>
  );
}

export default App;

License

This component is open-source and licensed under the MIT License. You can use, modify, and distribute it freely as long as you retain the original license information.