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

reactjs-simple-table

v1.5.1

Published

Reactjs simple table for showing list of data with sorting and pagation

Downloads

130

Readme

React Simple Table

A simple and reusable table for React (Demo)

Server side table for React (Demo)

Installation

The package can be installed via NPM:

npm i reactjs-simple-table

Usage

Import SimpleTableComponent for usage :

import SimpleTableComponent from "reactjs-simple-table";

Define your column with filed variable and header name :

const columns = [
  {
    field: "title",
    headerName: "Title",
  },
  {
    field: "number",
    headerName: "Amount",
  },
];

Get your list from Api or define your list :

const list = [
  { title: "Michael", number: 1 },
  { title: "Lindsay", number: 10 },
  { title: "Tobias", number: 6 },
  { title: "Byron", number: 3 },
  { title: "George", number: 1 },
  { title: "Rachel", number: 10 },
  { title: "Lawson", number: 6 },
  { title: "Ferguson", number: 3 },
  { title: "Funke", number: 1 },
];

The most basic use of the simple table can be described with:

<SimpleTableComponent columns={columns} list={list} />
import SimpleTableComponent from "reactjs-simple-table";

const columns = [
  {
    field: "title",
    headerName: "Title",
  },
  {
    field: "number",
    headerName: "Amount",
  },
];

function App() {
  const list = [
    { title: "Michael", number: 1 },
    { title: "Lindsay", number: 10 },
    { title: "Tobias", number: 6 },
    { title: "Byron", number: 3 },
    { title: "George", number: 1 },
    { title: "Rachel", number: 10 },
    { title: "Lawson", number: 6 },
    { title: "Ferguson", number: 3 },
    { title: "Funke", number: 1 },
  ];
  return (
    <div className="App">
      <SimpleTableComponent columns={columns} list={list} />
    </div>
  );
}

export default App;

Server Side Table

Import SimpleTableComponent for usage :

import { ServerSimpleTableComponent } from "reactjs-simple-table";

For server side , define function for get table pagation , sorting and number of items in per page parameters then update table by new data. each time you change any table feature like pagation,... onGetData will call and you can use table parameters :

import React, { useState } from "react";
import "./styles.css";
import { ServerSimpleTableComponent } from "reactjs-simple-table";

const columns = [
  {
    field: "id",
    headerName: "id",
  },
  {
    field: "name",
    headerName: "name",
  },
  {
    field: "username",
    headerName: "username",
  },
  {
    field: "email",
    headerName: "email",
  },
];

export default function App() {
  const [list, setList] = useState([]);

  //function fo get table parameters
  const tableData = (item) => {
    //fetch data by filter parameters from table
    //item :
    // {
    // page : 1 ,
    // numberPerPage : 10 ,
    // order :  "ascending" or "descending",
    //orderby : "title"  *name of the field ,
    //}
    fetch(
      `https://yourServerUrl/users?page=${item.page}&pageSize=${item.numberPerPage}`
    ).then((response) => setList(json));
  };

  return (
    <div className="App">
      <ServerSimpleTableComponent
        columns={columns}
        list={list}
        onGetData={tableData}
        total={10}
        serverSideFiltering={false}
      />
    </div>
  );
}

User guide

| Prop name | Description | Default value | Example values | | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ---------------------- | | total | Total of list , for using sever side table is required | list.length() | 100 | | numberPerPage | number of row in each page | 10 | 5 , 10 , 20 , 50 , 100 | | isRtl | for support rtl language | false | true or false | | numberPageOfText | for change 'of' text in pagation | 'of' | 'from' or 'از' | | tableClassName | you can use your own class for table style , in this case you can add boostrap or other css file in your app and use table class name and change table style | 'myTable' | 'table table-bordered' | | serverSideFiltering | you can handle server side sorting by receive 'order' and 'orderby' parameters from changes of table features , if you want sorting one page data you can set serverSideFiltering to 'true' and sorting data without server call | false | true or false |

Using Bootsrap

For using boostrap table class you can add boostrap css to Index.js or App.js , then add tableClassName property in SimpleTableComponent and use your table class :

npm i bootstrap
import SimpleTableComponent from "reactjs-simple-table";
import "bootstrap/dist/css/bootstrap.min.css";

const columns = [
  {
    field: "title",
    headerName: "Title",
  },
  {
    field: "number",
    headerName: "Amount",
  },
];

function App() {
  const list = [
    { title: "Michael", number: 1 },
    { title: "Lindsay", number: 10 },
    { title: "Tobias", number: 6 },
    { title: "Byron", number: 3 },
    { title: "George", number: 1 },
    { title: "Rachel", number: 10 },
    { title: "Lawson", number: 6 },
    { title: "Ferguson", number: 3 },
    { title: "Funke", number: 1 },
  ];
  return (
    <div className="App">
      <SimpleTableComponent
        columns={columns}
        list={list}
        tableClassName={"table table-bordered"}
      />
    </div>
  );
}

export default App;

You can use table-responsive :

<div class="table-responsive">
  <SimpleTableComponent
    columns={columns}
    list={list}
    tableClassName={"table table-bordered"}
  >
    ...
  </SimpleTableComponent>
</div>