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

adaptive-table

v3.2.1

Published

A reusable and customizable table component for React, written in TypeScript by @vitorboccio

Downloads

2

Readme

AdaptiveTable Component Documentation

Overview

AdaptiveTable is a flexible and feature-rich React table component that provides sorting, pagination, column resizing, row selection, and expandable rows. It's designed to be easy to use while offering powerful customization options.

Installation

npm install adaptive-table

Basic Usage

import AdaptiveTable from 'adaptive-table';
import type { Column } from 'adaptive-table/types'

const columns: Column<User>[] = [
  { key: 'id', title: 'ID', minWidth: 50 },
  { key: 'name', title: 'Name', minWidth: 100 },
  { key: 'email', title: 'Email', minWidth: 200 },
];

const data: User[] = [
  { id: 1, name: 'John Doe', email: '[email protected]' },
  { id: 2, name: 'Jane Smith', email: '[email protected]' },
];

function App() {
  return (
    <AdaptiveTable<User>
      data={data}
      columns={columns}
      hasCheckbox={true}
      itemsPerPage={10}
    />
  );
}

Props

data: T[]

An array of objects representing the data to be displayed in the table. Each object should match the structure defined by your generic type T.

columns: Column<T>[]

An array of column definitions. Each column should have the following properties:

  • key: keyof T | '': The key of the data object this column represents.
  • title: string: The display title for the column header.
  • minWidth: number: The minimum width of the column in pixels.
  • isSortable?: boolean: Whether the column is sortable (default: true).
  • isResizable?: boolean Whether teh column is resizable (default: true).
  • render?: (value: T[keyof T], row: T) => React.ReactNode: Optional custom render function for cell content.

hasCheckbox?: boolean

Whether to display a checkbox column for row selection. Default is false.

pageSize?: number

The number of items to display per page. Default is 10.

pageSizeOptions?: number[]

The page size options displayed on the table footer

onSorting?: (sortingData: SortingState<T>) => void

Callback function triggered when sorting changes. Receives an object with:

  • column: keyof T | null: The key of the column being sorted.
  • direction: 'asc' | 'desc' | null: The sort direction.

onPagination?: (paginationData: PaginationState) => void

Callback function triggered when pagination changes. Receives an object with:

  • currentPage: number: The current page number.
  • itemsPerPage: number: The number of items per page.

onRowSelect?: (selectedRows: T[]) => void

Callback function triggered when row selection changes. Receives an array of selected row data.

onResize?: (columnWidths: number[]) => void

Callback function triggered when column widths change due to resizing. Receives an array of column widths.

expandedRow?: (row: T) => React.ReactNode

A function that returns the content to be displayed in the expanded row. If provided, rows become expandable on click.

Column Resizing

Columns can be resized by dragging the right edge of the column header. The minimum width of a column is determined by the minWidth property in the column definition.

Sorting

Clicking on a column header will sort the data by that column. Clicking again will reverse the sort order. The sortable property in the column definition can be used to disable sorting for specific columns.

Pagination

The table includes built-in pagination. You can customize the number of items per page using the itemsPerPage prop.

Row Selection

When hasCheckbox is set to true, a checkbox column will appear, allowing for row selection. The onRowSelect callback will be triggered with an array of selected row data whenever the selection changes.

Expandable Rows

When the expandedRow prop is provided, rows become expandable. Clicking on a row will toggle its expanded state, showing the content returned by the expandedRow function.

Styling

The component comes with default styling, but you can customize its appearance by overriding the CSS classes. The main classes used are:

  • .adaptive-table-container: The outer container of the table.
  • .adaptive-table: The table itself.
  • .adaptive-table-header: The table header row.
  • .adaptive-table-body: The container for table body rows.
  • .adaptive-table-row: Individual table rows.
  • .adaptive-table-cell: Individual table cells.
  • .adaptive-table-checkbox: The checkbox cell.
  • .adaptive-table-expanded-row: The expanded row content container.
  • .adaptive-table-pagination: The pagination controls container.
  • .adaptive-table-empty-state: The component when no data is provided or T[].length === 0;

TypeScript Support

AdaptiveTable is built with TypeScript and provides full type safety. When using the component, provide your data type as a generic parameter:

<AdaptiveTable<YourDataType> ... />

This ensures type checking for your data, columns, and callback functions.

Performance Considerations

AdaptiveTable is optimized for performance, using memoization and efficient update mechanisms. However, for very large datasets, consider implementing virtual scrolling or lazy loading to improve performance.