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

react-ava-table

v0.1.3

Published

- Build easy high performance react tables - Server and Client Side rendering - Filter and Sort Data - Select Rows and Copy (multi) - Create Dynamic Charts from Table Data - Resizable columns - Typescript support - Storybook Support

Downloads

5

Readme

Features

  • Build easy high performance react tables
  • Server and Client Side rendering
  • Filter and Sort Data
  • Select Rows and Copy (multi)
  • Create Dynamic Charts from Table Data
  • Resizable columns
  • Typescript support
  • Storybook Support

Storybook

https://react-ava-table.vercel.app

Install

npm install react-table-npm

Examples

  • Client Side: https://codesandbox.io/s/react-table-npm-example-client-side-wunuk4?file=/src/App.tsx
  • Server Side: https://codesandbox.io/s/react-table-npm-example-server-side-qojv3d?file=/src/App.tsx

Start

import { Table } from "react-table-npm"

type Width = {
  minWidth?: number;
  defaultWidth?: string | number;
};

type Column = {
  id: string;
  label: string;
  filter?: string;
  sort?: boolean;
  width?: Width;
};

type Data = {
  id: string;
  name: string;
  age: number;
  state: string;
};

const columns: Column[] = [
  {
    id: "name",
    label: "Name",
    sort: true,
    width: { minWidth: 300, defaultWidth: "1fr" },
  },
  {
    id: "age",
    label: "Age",
    sort: true,
    filter: true,
    width: { defaultWidth: 200 },
  },
  {
    id: "state",
    label: "State",
    sort: true,
    width: { minWidth: 300, defaultWidth: 400 },
  },
];

const users = [
  {
    "id": "62e2dd905e37187e20fd4a13",
    "name": "Mcintyre Forbes",
    "age": 69,
    "state": "Idaho"
  },
  {
    "id": "62e2dd90c7d21f4a03638d4f",
    "name": "Verna Berger",
    "age": 18,
    "state": "Louisiana"
  },
  {
    "id": "62e2dd90edc01768932b2da7",
    "name": "Gladys Dawson",
    "age": 100,
    "state": "Federated States Of Micronesia"
  }
]
const data: Data[] = users;

function App() {
  return (
    <Table
      columns={columns}
      data={data}
      selectable={true}
      contextMenu={true}
    />
  );
}

Table Callback Functions

| name | props | return | description | | --------------------- | ----------------------------------------------------------------------- | ------------------ | -------------------------------- | | columnKeyExtractor | (item: Column) | string (unique id) | creates a key for each column | | renderColumnItem | (item: Column) | string | return name of the column | | dataKeyExtractor | (item: Data) | string (unique id) | creates a key for each dataset | | renderData | (item: Data, column: Column) | React Component | determine value for each dataset | | fetchDataOnPagination | async (page: number, limit: number, sort: SortType, filter: FilterType) | DataType[] | calls for new data |

Table Props

| name | type | description | default | | ------------ | ------- | ----------------------------------------------------------------- | ------- | | limit | number | determinse the row count of a page | 15 | | resizable | boolean | able to resize columns width | true | | contextMenu | boolean | able to open a context menu for each row (enable copy and charts) | false | | selectable | boolean | able to select single or multiple rows | false | | isServerSide | boolean | need to set to true if you need server side | false |

Extend Example With Server Side

const handleFetchDataOnPagination = async (
  page: number,
  limit: number,
  filter: any
) => {

  // TODO - add columns, data from first example

  return new Promise((resolve) =>
    setTimeout(
      () =>
        resolve({
          data: [...users]
            .sort((a: any, b: any) => {
              if (filter?.sort?.sortBy?.value === "asc") {
                return a[filter?.sort?.sortBy?.id] > b[filter?.sort?.sortBy?.id]
                  ? 1
                  : -1;
              }
              if (filter?.sort?.sortBy?.value === "desc") {
                return a[filter?.sort?.sortBy?.id] < b[filter?.sort?.sortBy?.id]
                  ? 1
                  : -1;
              }
              return 0;
            })
            .slice((page - 1) * limit, page * limit),
          hasNextPage: users.length > page * limit,
        }),
      1000
    )
  );
};

<Table
  columns={columns}
  data={data}
  selectable={true}
  contextMenu={true}
  isServerSide={true}
  fetchDataOnPagination={handleFetchDataOnPagination}
/>

Custom Callback Functions Example

const App = () => {

  // TODO - add columns, data from first example

  // DEFAULT CALLBACKS
  const handleColumnKeyExtractor = (column: Column) => column.id;
  const handleRenderColumn = (column: Column) => column.label;

  const handleDataKeyExtractor = (item: Data) => item.id;
  const handleRenderData = (item: Data, column: Column) => {
    return (
      <td key={`${item.name}-${column.id}`}>
        <span>{item[column.id as keyof Data]}</span>
      </td>
    );
  };

  return (
    <Table
      columns={columns}
      columnKeyExtractor={handleColumnKeyExtractor}
      renderColumnItem={handleRenderColumn}
      data={data}
      dataKeyExtractor={handleDataKeyExtractor}
      renderData={handleRenderData}
      selectable={true}
      contextMenu={true}
    />
  );
}