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

@gabrielduumont/react-datatables

v1.2.4

Published

React component that will render data into a responsive HTML table

Downloads

11

Readme

@gabrielduumont/react-datatables

React component that will render data into a responsive HTML table

NPM JavaScript Style Guide

This project is inspired in: https://datatables.net/

If you want to collaborate: https://github.com/gabrielduumont/react-datatables

Please report any bugs found.

Example

Install

npm install --save @gabrielduumont/react-datatables

or

yarn add @gabrielduumont/react-datatables

You can view the example detailed in: https://github.com/gabrielduumont/react-datatables/tree/master/example

Usage

headers and data are required props. Both are arrays.


  <DataTable
    //required props
    data={data}
    headers={headers}
    
  />

The headers array

The headers array is composed by objects which should respect this structure:

{
    "label": "Some DateTime",
    "key": "SomeDateTime",
    "type": "datetime"
},

Where:

  • label: is a string, which is the one that gets displayed in the column header
  • key: is a string, which should not countain any spaces or special characters, and must match the properties of the objects contained in the data array
  • type: is a string, and represents the name of the data type contained in the column. This property is important for the ordering function, so fill it correctly to get good results. Possible values are: string, number, date, time, datetime

IMPORTANT: Dates (even inside the datetime string) must be in one of the formats below:

  1. DD-MM-YYYY or DD.MM.YYYY or DD/MM/YYYY
  2. YYYY-MM-DD or YYYY.MM.DD or YYYY/MM/DD

The data array

The simple definition of an object

[
   {
      otherProperties

      "SomeDateTime": {
          "value": "2008-1-8 08:00:00", //required prop

          /* 
          Optionally, you can override the value show with the use of a parser inside the object, as the example below. 
          Since parser is a function, it can also be another component. 
          
          The parser function takes one argument, which is *value*, and that argument represents the value above.
          The parser function must return something to be rendered.

          Example 1
          "parser": (value) => <p onClick={() => alert("hello")}>{value}</p>

          Example 2 - Imagine the value is a boolean true
          "parser": (value) => {
            if(!!value) return "Active";
            else return "Deactivated";
          }


          */
      },
      
      otherProperties
    },
]

Optional props

lang

It can be a string or and object that matches the following structure:

"en-us": {
    "search": {
      "label": "Search",
      "searchingFor": "Searching for: ",
      "placeHolder": "Search"
    },
    "paginationControl": {
      "label": "Page Size",
    },
    "pagination": {
      "next": "Next",
      "previous": "Previous",
      "totalLabel": (showing, total) => `Showing ${showing} of ${total} records`,
    }
  },

Currently implemented languages: "pt-br", "en-us" (default)

initialPageSize and pageSizes (yes! must be used together)

  • pageSizes: an array of numbers
  • initialPageSize: A number that must be contained on pageSizes

tableStyles

You can find a reference to this object here: https://github.com/gabrielduumont/react-datatables/blob/master/example/src/exampleData.js

extraConfig

Object that should have any of this properties:

  • hideSearch: boolean to hide filters
  • hidePaginationControl: boolean to hide page size control

Simple Example

import React from 'react'

import { DataTable } from '@gabrielduumont/react-datatables'
import '@gabrielduumont/react-datatables/dist/index.css'

import { data, headers, tableStyles } from './exampleData'

const extraConfig = {
  //hideSearch: true,
  //hidePaginationControl: true,
};

const App = () => {
  return (
    <div>
      <DataTable
        //required props
        data={data}
        headers={headers}
        
        //optional props
        tableStyles={tableStyles}
        lang='pt-br'
        initialPageSize={25}
        pageSizes={[25, 30]}
        extraConfig={extraConfig}
      />
    </div>
  )
}

export default App

Roadmap

The idea is to implement most (or all if possible) of the features of the jquery datatables project.

  • Basic features: ordering, filtering, pagination and responsivity -> done

To be developed features:

  • Filter by column
  • Fixed Columns
  • Fixed Header
  • Col re-order
  • Row re-order
  • Selectable Rows
  • PDF Export
  • Excel Export

License

MIT © gabrielduumont