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

hightable

v0.4.2

Published

A dynamic windowed scrolling table component for react

Downloads

622

Readme

HighTable

HighTable

npm workflow status mit license coverage

HighTable is a virtualized table component for React, designed to efficiently display large datasets in the browser. It loads and renders only the rows necessary for the current viewport, enabling smooth scrolling and performance even with millions of rows. HighTable supports asynchronous data fetching, dynamic loading, and optional column sorting.

Features

  • Virtualized Scrolling: Efficiently renders only the visible rows, optimizing performance for large datasets.
  • Asynchronous Data Loading: Fetches data on-demand as the user scrolls, supporting datasets of any size.
  • Column Sorting: Optional support for sorting data by columns.
  • Column Resizing: Allows for resizing columns to fit the available space and auto-sizing.
  • Event Handling: Supports double-click events on cells.

Demo

Live table demo: https://hyparam.github.io/hightable/

Installation

Ensure you have React set up in your project. Install the HighTable package via npm:

npm i hightable

Data Model

HighTable uses a data model called DataFrame, which defines how data is fetched and structured. The DataFrame object should have the following properties:

  • header: An array of strings representing the column names.
  • numRows: The total number of rows in the dataset.
  • rows: An asynchronous function that fetches rows. It should accept start and end row indices and return an array of row objects.
  • sortable (optional): A boolean indicating whether the table supports column sorting.

Each row object should be a mapping of column names to cell values.

DataFrame Example

const dataframe = {
  header: ['ID', 'Name', 'Email'],
  numRows: 1000000,
  rows: async (start, end, orderBy) => {
    // Fetch rows from your data source here
    // 'orderBy' is an optional parameter representing the column to sort by
    return fetchRowsFromServer(start, end, orderBy)
  },
  sortable: true, // Set to true if your data source supports sorting
}

Usage

Here's a basic example of how to use HighTable in your React application:

import HighTable from 'hightable'

const dataframe = {
  header: ['ID', 'Name', 'Email'],
  numRows: 1000000,
  rows: async (start, end, orderBy) => {
    // fetch rows from your data source here
    return fetchRowsFromServer(start, end, orderBy)
  },
  sortable: true,
}

function App() {
  function onDoubleClickCell(row, col) {
    console.log(`Double clicked row ${row}, column ${col}`)
  }

  return <HighTable
    data={dataframe}
    setError={console.error}
    onDoubleClickCell={onDoubleClickCell} />
}

Props

HighTable accepts the following props:

  • data: The data model for the table. Must include methods for header and rows fetching.
  • onDoubleClickCell (optional): Called when a cell is double-clicked. Receives the row and column indexes as arguments.
  • onError (optional): Callback for error handling.

Prop Types

interface TableProps {
  data: DataFrame
  onDoubleClickCell?: (row: number, col: number) => void
  onError?: (error: Error) => void
}

Sorting

If your data source supports sorting, set the sortable property to true in your DataFrame object. When sorting is enabled, the rows function will receive an additional orderBy parameter, which represents the column name to sort by.

Ensure your rows function handles the orderBy parameter appropriately to return sorted data.

Styling

HighTable includes basic CSS styling to make the table functional. You can customize the appearance of the table using CSS.