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

filter-table

v0.2.1

Published

Filterable, sortable table that implements an infinite list to handle large amounts of data

Downloads

15

Readme

Build Statuscodecov

Filter-Table

A react component that takes in an array of JavaScript objects, a configuration object and converts it to a filterable, sortable table.

Installation

yarn add filter-table

Copy the .css file or require somewhere in your project so webpack pulls it into your bundle:

require('filter-table/dist/index.css');

Running tests

git clone https://github.com/erik-sn/filter-table.git
cd filter-table
npm t

Features

  • Infinite List: only rows that are currently visible to the user are displayed
  • Filterable: Table can be filtered by keywords, partial/exact matching, case sensitivity
  • Sortable: toggle sorting by column
  • Download Data: user can download the table data as a .csv file
  • Display Totals & Results: summarize table data
  • Open CSS Styling: All table components have detailed class names and ids that are accessible for customized styling

Props

/**
Raw table data. Array of object literals:
[
  { column1: 'one', column2: 1, column3: 'A' },
  { column1: 'two', column2: 2, column3: 'B' },
  { column1: 'three', column2: 3, column3: 'C' },
  ...
]
*/
tableData: object[];


/**
Array of object literals, where each item is a configuration for a column:
[
  {
    key: string  // the object literal key that this column is responsible for
    header: string  // label that will show in the header row
    width: string  // either percent or px width of this column (i.e '15%', '30px')
    transform: (columnValues: [key: string]: string[], key: string) => any
  },
  ...
]

The transform function accepts an object where each key is a column configuration
key and columnValues contains all values from that column.

Example transform function to sum a column:
  const sum = (total: number, value: string) =>  total + Number(value.replace(/,/g, ''));
  const transform = (columnValues, key) => columnValues[key].reduce(sum, 0);

Example columnValues:
  {
    column1: ['one', 'two', 'three'],
    column2: ['1', '2', '3'],
    column3: ['A', 'B', 'C'],
  }

Note that all values have been converted to strings - your transform
function should take this into account.
*/
config: Config[];

className?: string;  // class that will be applied to top level

rowHeight: number;  // the height of each row

tableHeight?: number;  // if this is not specified the entire window is used

// returns the object that the clicked on row contains as well as the column key
handleRowClick?: (rowData: {}, key: string) => void;

allIcon?: JSX.Element;  // element to show if filtering is in "all" mode

anyIcon?: JSX.Element;  // element to show if filtering is in "any" mode

showFilter?: boolean;  // display the filter input field

showCsv?: boolean;  // display the download button that downloads table data

showResults?: boolean;  // display table summary

showTotals?: boolean;  // show column totals (i.e. results of transform functions)

CSS Classes

  • top level container: 'filter_table__container'
  • filter container: 'filter_table__filter-bar'
  • header container: 'filter_table__header'
  • table body: 'filter_table__body'
  • table row: 'filter_table__row'
  • table cell: 'filter_table__cell'
  • tabel column totals container: 'filter_table__totals-container'
  • table summary container: 'filter_table__results-container'