2.0.5 • Published 2 years ago

react-exp-table v2.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-exp-table

A react table component with expandable rows. This table uses consistent columns across all child rows and does not nest tables within rows.

NPM

Features

  • Nested expandable rows
  • Child row key mapping
  • Conditional initial expand/collapse state by row
  • Conditional row background colors
  • Columns can include multiple entries per column
  • All rows are loaded on initial load to ensure high performance when expanding/collapsing rows

Installation

npm i react-exp-table

Example

https://www.exptable.com/

Usage

import ExpandableTable from "react-exp-table";

function App() {
  const columns = [
    {
      title: "Location",
      key: "location"
    },
    {
      title: "Population",
      key: "population"
    },
    {
      title: "Party",
      key: "party"
    }
  ];

  const data = [
    {
      location: "Texas",
      population: "29 million",
      party: "Republican",
      child: [
        {
          location: "Houston",
          population: "2 million",
          party: "Democrat"
        },
        {
          location: "Austin",
          population: "1 million",
          party: "Democrat"
        }
      ]
    },
    {
      location: "California",
      population: "39 million",
      party: "Democrat",
      child: [
        {
          location: "Los Angeles",
          population: "4 million",
          party: "Democrat"
        },
        {
          location: "San Jose",
          population: "1 million",
          party: "Democrat"
        }
      ]
    }
  ];

  return <ExpandableTable columns={columns} data={data}></ExpandableTable>;
}

Result

Example picture of the expandable table

Props

PropTypeRequiredDescription
data xdata to be displayed in the table rows
columnscolumn (see below)xdefinition for column titles, keys, and optional css classes
rowKeystringkey used for react to identify each row of the table - must be unique
childDataKeystringkey used to identify the child row within a row's data, default is "child"
rowColorfunction(rowData)returns the css class used to set the background color of the row - uses the row data object as the parameter
visibleOnInitfunction(rowData)returns a boolean to identify if the row should be visible on the initial load of the table - uses the row's js object as the parameter
hideCollapseExpandButtonsbooleanhides the "Expand All" and "Collapse All" buttons at the top of the table

Column definition

export interface Column {
  title: string;
  key: string | string[];
  class?: string | string[];
}

Changelog

  • 2.0.0 (30 Nov 2021) - Simplify column definition
  • 1.0.0 (21 Nov 2021) - Initial release

Authors

Questions

License

This project is licensed under the MIT License - see the LICENSE file for details

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago