0.3.1 • Published 3 years ago

@hesenger/react-simpletable v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

react-simpletable

Simple table component to render json data from local or remote

NPM JavaScript Style Guide

SimpleTable comes with support to:

  • Local data
  • Remote data
  • Themes

See live examples here.

All size of projects need powerfull and customizable components, but data driven software usually have many CRUDS to simple manage data in single tables, in this case, productivity comes to be a good partner, and a simple declarative component to list local or remote data is a must.

In this cases react-simpletable is a fast option to show users data and let them select wich they want to change/delete.

Install

npm i @hesenger/react-simpletable

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import Table from 'react-simpletable';
import 'react-simpletable/dist/index.css';

const App = () => {
  const [data, setData] = React.useState([]);
  const [current, setCurrent] = React.useState();

  if (!data.length)
    fetch('https://jsonplaceholder.typicode.com/users')
      .then(resp => resp.json())
      .then(data => setData(data));

  return <>
    <Table data={data} onSelect={row => setCurrent(row)}>
      <Table.Col name="id" header="#" />
      <Table.Col name="username" header="Username" />
      <Table.Col name="name" header="Name" />
      <Table.Col name="email" header="E-mail" />
      <Table.Col header="Site" format={obj => <a href={'http://' + obj.website}>{obj.website}</a>} />
    </Table>
    <p>
      Current selection: {JSON.stringify(current)}
    </p>
  </>;
}

ReactDOM.render(<App />, document.getElementById('root'))

License

MIT © hesenger

0.3.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago