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

ds-react-table

v2.0.1

Published

Dead simple react table

Downloads

12

Readme

Dead simple react table

npm GitHub stars gzip size Travis (.org) npm

rt

Installation

$ npm install ds-react-table

or

$ yarn add ds-react-table

Usage

import React from 'react';

import { Table } from 'ds-react-table';
// optional
import 'ds-react-table/dist/index.css'

const data = [
  {
    qualification: 'Software Engineering',
    school: 'UJ',
    period: '04/2016 – 08/2018',
    location: 'JOHANNESBURG, SOUTH AFRICA',
  },
  {
    qualification: 'PC Technician',
    school: 'Boston City Campus & business College',
    period: '01/2011 – 11/2011',
    location: 'RANDBURG, SOUTH AFRICA',
  },
  {
    qualification: 'UX Designer',
    school: 'UCT',
    period: '01/2008 – 12/2010',
    location: 'CAPE TOWN, SOUTH AFRICA',
  }
];

function App() {
  return (
    <div className="App">
      <Table
        dataLimit={15}
        sort={false}
        showPagination={true}
        data={data}
      />
    </div>
  );
}

export default App;

toggle

API

| Prop | Type | Default | Description | | |----------------|------------------|-----------|---------------------------------------------------------------------------------------|---| | data | array | Required | Array of objects to be displayed in a table | | | sort | bool | false | To enable sorting | | | dataLimit | number | 10 | The number of items to be shown on each page. | | | showPagination | bool | false | Show/hide pagination | | | CustomTdComponent | React.FC | false |A React component to add actions such as edit and deleting | | | customTdHeader | string | false | Header of the custom td | |

Styling the table and pagination

/* table.module.css */
body {
  background: #1d1e22;
}
/* styling the table */
table, td {
  border: 1px solid #353535;
  padding-left: 5px;
}

th {
background-color: #3B3B3B;
text-align: left;
padding-left: 5px;
}

table {
  width: 100%;
  font-family: monospace;
  border-collapse: collapse;
  background-color: #2B2B2B;
  color: #94ABBE;
}

/* styling pagination */

.pagination {
  display: inline-block;
  background-color: white;
  border: 1px solid #d8cdc9;
  margin-top: 10px;
}

.pagination a {
  color: black;
  float: left;
  padding: 8px 16px;
  text-decoration: none;
}
.pagination a:not(:nth-child(2)) {
  background-color: #d8cdc9;
  color: white;
}

.pagination a:nth-child(2) {
  display: inline-block;
  width: 100px;
  text-align: center;
}

.pagination a:nth-child(n+3):nth-last-child(n+2) {
  cursor: default;
}
import React from 'react';

import { Table } from 'ds-react-table';

// import css file

import './table.module.css';

function App() {
  return (
    <div className="App">
      <Table
        dataLimit={2}
        sort={false}
        showPagination={true}
        data={data}
      />
    </div>
  );
}

export default App;

toggle

BYOP (bring your own pagination)

This example uses rc-pagination

import React, {useState}> from 'react';

import { Table } from 'ds-react-table';

import Pagination from 'rc-pagination';
import 'rc-pagination/assets/index.css';

function App() {
  const countPerPage = 2;
  const [currentPage, setCurrentPage] = useState(1);
  const [collection, setCollection] = useState(data.slice(0, countPerPage));

  const updatePage = (p) => {

    setCurrentPage(p);
    const to = countPerPage * p;
    const from = to - countPerPage;
    setCollection(data.slice(from, to));

  };

  return (
    <>
      <Table dataLimit={collection.length} data={collection} />

      <Pagination
        pageSize={countPerPage}
        onChange={updatePage}
        current={currentPage}
        total={data.length}
      />
    </>
  );
});

toggle

Custom td Component

You can utilize a CustomTdComponent to incorporate actions within the table, such as the ability to edit and delete rows.


const CustomComponent = ({ id, data }) => {
  return (
    <div style={{ padding: '0 30px'}}>
      <MdEdit onClick={() => editRow(id)} />
      <MdDeleteOutline onClick={() => deleteRow(id)} />
    </div>
    )
}

 <Table
    dataLimit={collection.length}
    data={collection}
    CustomTdComponent={CustomComponent}
  />

toggle

License

MIT