# data-table-component

> The DataTable component is a reusable React component that provides functionality for displaying tabular data in a paginated and sortable manner. It allows users to specify the number of entries displayed per page, apply filters to the data, and sort the

Latest version **1.0.16** (published 2023-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install data-table-component
pnpm add data-table-component
yarn add data-table-component
bun add data-table-component
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.16 |
| Published | 2023-09-28 |
| First published | 2023-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 100.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Clément STORNE |
| Maintainers | cstorne |
| Keywords | datatable, data table, data filter, table pagination |

## Links

- npm: https://www.npmjs.com/package/data-table-component
- npm.io page: https://npm.io/package/data-table-component

## Dependencies (2)

- [react-icons](https://npm.io/package/react-icons.md) ^4.10.1
- [tailwindcss](https://npm.io/package/tailwindcss.md) ^3.3.3

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 1.0.16 (latest) — 2023-09-28
- 1.0.15 — 2023-09-22
- 1.0.14 — 2023-08-21
- 1.0.13 — 2023-08-21
- 1.0.12 — 2023-08-17
- 1.0.11 — 2023-08-17
- 1.0.10 — 2023-08-17
- 1.0.9 — 2023-08-09
- 1.0.8 — 2023-08-09
- 1.0.7 — 2023-08-09
- 1.0.6 — 2023-08-09
- 1.0.5 — 2023-08-09
- 1.0.4 — 2023-08-09
- 1.0.3 — 2023-08-03
- 1.0.2 — 2023-08-03
- … 2 more at https://npm.io/package/data-table-component/versions

## README

# DataTable Component Documentation

## Description

A customizable React component that renders a data table with sorting, filtering, and pagination features. This component allows you to display provided data using specified columns while providing options to customize colors for various elements.

## Dependencies

- node v.19.7.0
- react-icons: ^4.10.1
- tailwindcss: ^3.3.3

## Installation and Usage

To use the `DataTable` component in your React application, follow these steps:

1. Install the required dependencies. Make sure you have React and PropTypes installed in your project.

```bash
npm install data-table-component
```

2. Import and use the `DataTable` component in your application:

```jsx
import DataTable from "data-table-component";

const columns = [
  // An array of column objects with at least a 'key' and 'title' property.
  // Example: { key: 'id', title: 'ID' }
];

const data = [
  // An array of data objects, each containing properties corresponding to the 'key' in the columns array.
  // Example: { id: 1, firstName: 'John', lastName: 'Doe' }
];

function App() {
  return (
    <DataTable
      columns={columns}
      data={data}
      headerColor="#446404"
      rowColor="#eef1e6"
      alternateRowColor="#94ac1b"
      hoverRowColor="#687f11"
    />
  );
}
```

## Props

The `DataTable` component accepts the following props:

- `columns` (required): An array of column objects representing the columns to display in the table. Each object must have at least two properties: `key` (a unique identifier for the column) and `title` (the display name of the column).

- `data` (required): An array of data objects to be displayed in the table. Each object should contain properties corresponding to the `key` defined in the `columns` prop.

- `headerColor`: The header row color of the DataTable. Defaults to "#446404" (green).

- `rowColor`: The primary row color of the DataTable. Defaults to "#eef1e6" (light gray).

- `alternateRowColor`: The alternate row color of the DataTable. Defaults to "#94ac1b" (greenish).

- `hoverRowColor`: The hover row color of the DataTable. Defaults to "#687f11" (darker green).

## Functionality

The `DataTable` component provides the following functionality:

### Number of Entries per Page

Users can choose the number of entries to display per page. The available options are defined in the `numberOfEntriesOptions` array, which can be customized as needed.

### Pagination

The table displays a limited number of entries per page, and pagination buttons allow users to navigate through the different pages.

### Sorting

Clicking on the column headers triggers sorting of the table data. The table can be sorted in ascending or descending order based on the selected column.

### Filtering

Users can apply a text-based filter to the data. The filter works across all columns and displays the rows that match the filter text.

## Hooks

The `DataTable` component utilizes the React `useState` and `useEffect` hooks to manage state and perform side-effects, respectively.

## Custom Components

The `DataTable` component uses several custom sub-components for specific functionalities:

- `DataTableNumberOfEntries`: A component to select the number of entries per page.
- `DataTableFilter`: A component to input and apply the filter on the data.
- `DataTableHeaderRow`: A row component displaying the column headers and providing sorting functionality.
- `DataTableRow`: A row component to render individual data rows.
- `DataTablePagination`: A component displaying pagination information.
- `DataTableNavigationPrevious`: A component providing navigation to the previous page.
- `DataTableNavigationNext`: A component providing navigation to the next page.

## Example

```jsx
import React from "react";
import DataTable from "./DataTable";

const columns = [
  { key: "id", title: "ID" },
  { key: "firstName", title: "First Name" },
  { key: "lastName", title: "Last Name" },
];

const data = [
  { id: 1, firstName: "John", lastName: "Doe" },
  { id: 2, firstName: "Jane", lastName: "Smith" },
  // ...more data
];

function App() {
  return (
    <div>
      <DataTable
        columns={columns}
        data={data}
        headerColor="#446404"
        rowColor="#eef1e6"
        alternateRowColor="#94ac1b"
        hoverRowColor="#687f11"
      />
    </div>
  );
}

export default App;
```

## License

This component is open-source and licensed under the MIT License. You can use, modify, and distribute it freely as long as you retain the original license information.

---
_Source: https://npm.io/package/data-table-component · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
