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

supertable

v0.2.1

Published

React table component

Downloads

22

Readme

supertable Build Status

A ReactJS table component which is fully featured, configurable & highly performant (or at least that is the intention).

This project relies on both ReactJS & ImmutableJS (thank you @facebook)

Install

npm install supertable --save

Useage

import React from 'react';
import Immutable from 'immutable';
import SuperTable from 'supertable';

const fields = [
    {name: 'fieldA', label: 'Field A'},
    {name: 'fieldB', label: 'Field B'},
    {name: 'fieldC', label: 'Field C'}
];

const someFakeData = Immutable.fromJS([
    {_id: 1, fieldA: 'valueA1', fieldB: 99, fieldC: 'valueC1'},
    {_id: 2, fieldA: 'valueA2', fieldB: 88, fieldC: 'valueC2'},
    {_id: 3, fieldA: 'valueA3', fieldB: 77, fieldC: 'valueC3'}
]);

const MyDataTable = React.createClass({
    render() {
        return (
            <SuperTable  data={someFakeData}
                         fields={fields}
                         width={1000}
                         height={500} />
        );
    }
});

Config

data (required) Immutable.List of Immutable.Map

This should contain all of the data required for display. When data is fetched async, it should be added to this same list. Re-using the same list with existing objects will allow for === equality test to work which means you get a little performance benefit.

Example
const someFakeData = Immutable.fromJS([
    {_id: 1, fieldA: 'valueA1', fieldB: 99, fieldC: 'valueC1'},
    {_id: 2, fieldA: 'valueA2', fieldB: 88, fieldC: 'valueC2'},
    {_id: 3, fieldA: 'valueA3', fieldB: 77, fieldC: 'valueC3'}
]);

fields (required) Array of Object

Each object in this array represents a column which should be visible in the table.

  • name : Property name to reference in your data
  • label <String|React.Element>: Contents of the column header
  • width : The fixed width for this column in pixels
  • flexGrow : The grow factor relative to other columns. Same as the flex-grow API from http://www.w3.org/TR/css3-flexbox/. Basically, take any available extra width and distribute it proportionally according to all columns' flexGrow values. If width is provided, this value is ignored. Defaults to 1
Example
const fields = [
    {name: 'fieldA', label: 'Field A'},
    {name: 'fieldB', label: 'Field B'},
    {name: 'fieldC', label: 'Field C'}
];

width (required) Number

Width of the table in pixels.

height (required) Number

Height of the table in pixels

rowHeight (required) Number

Exact height of a row in pixels

cellRenderer Object

An Object. This prop allows for custom rendering of any cell. Any properties on this object should be named exactly the same as their corresponding field name. The value must be a function which returns something which is renderable by React (String|React.Element).

Each function will be passed rowData which is and Immutable.Map containing data for the entire row.

NOTE: Only need to provide handlers when custom formatting is needed, otherwise it will default to just display as text

const cellRenderer = {
    /*
     * Render fieldB as currency
     */
    fieldB: (rowData) => {
        const value = rowData.get('fieldB');
        return <span className="myCSSCurrencyClass">{'$' + value.toFixed(2)}</span>;
    },

    /*
     * Add conditional formatting to fieldC
     */
    fieldC: (rowData) => {
        const value = rowData.get('fieldC');
        const fieldBValue = rowData.get('fieldB');

        const cellStyle = {
            color: fieldBValue > 90 ? 'green' : 'red'
        };

        return <span style={cellStyle}>{value}</span>;
    }
};

onLoadMore Function

A function. This function will be executed when the table has been scrolled and more data is required for display to the user. Use this to trigger any AJAX requests and the extra data should be added to your existing ImmutableList and sent as a prop to the SuperTable component.

loading Boolean (default: false)

true when there is a async request in progress.