# @airglow/prefab-table

> Prefab for Table Implementations

Latest version **0.8.0** (published 2020-09-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @airglow/prefab-table
pnpm add @airglow/prefab-table
yarn add @airglow/prefab-table
bun add @airglow/prefab-table
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.0 |
| Published | 2020-09-30 |
| First published | 2019-06-18 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 38.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Adobe Systems |
| Maintainers | dgrossen, amadt5 |

## Links

- npm: https://www.npmjs.com/package/@airglow/prefab-table
- Repository: https://github.com/adobe/airglow
- Homepage: https://github.com/adobe/airglow#readme
- Issues: https://github.com/adobe/airglow/issues
- npm.io page: https://npm.io/package/@airglow/prefab-table

## Dependencies (2)

- [@airglow/prefab](https://npm.io/package/@airglow/prefab.md) ^0.8.0
- [@airglow/reducers](https://npm.io/package/@airglow/reducers.md) ^0.8.0

## Recent versions

- 0.8.0 (latest) — 2020-09-30
- 0.7.1 — 2020-07-14
- 0.7.0 — 2020-05-08
- 0.6.1 — 2020-05-08
- 0.6.0 — 2020-05-07
- 0.5.2 — 2020-03-27
- 0.5.0 — 2019-06-18

## README

# Prefab-Table

A custom [Prefab](../packages/prefab) to help UI applications maintain table component states.

## Installation

```
npm install --save @airglow/prefab @airglow/prefab-table
```

## Getting Started

To add the Table Prefab, you simply need to import the prefab somewhere in your code:

```js
import '@airglow/prefab-table';
```

## Usage

```js
import prefabFactory from '@airglow/prefab';

export default prefabFactory({
  table: {
    type: 'table',
    dataSelector: state => [state.todos],
    columns: {
      text: {
        sorter: 'default'
      },
      assignee: {
        sorter: myCustomNameSorter
      }
    }
  }
});
```

In the above example, the table has two columns: text and assignee. Text column is sorted with default alphabatic order. Assignee is sorted with myCustomNameSorter, which is a custom sorter implemented somewhere else from the UI application.

## Selectors
The table provides the following selectors:

| Selector | Input | Description |
| -------- | ----- | ----------- |
| state | state | returns the full state of the table, columns, sort direction, and selected rows (see below)
| handlers | dispatch | returns all the handlers for the rows and columns (see below)
| addColumnAction | columnName, column configuration | adds a new column for the table to use for sorting
| deselectRowsAction | null \| rowData \| [rowData] | Toggles the selection of a row in the table. If no input is provided then all the selected rows will be cleared
| removeColumnAction | columnName, column configuration | removes added columns only
| toggleRowAction | rowData | Toggles the selection or a row in the table
| selectedData | state | returns the selected rows data

## Table State

| Key | Description |
| --- | ----------- |
| columns | an object containing the visible column prefabs, including any added
| data | The array of data that populates the rows in the table
| hiddenColumns | an object containing hidden column prefabs
| selectedData | an array of data that is contained in the selected rows
| selectedRows | an array of indices that represent the selected rows according to the current sort direction
| sortBy | the name of the column being used to sort the table
| sortDirection | a number representing whether the sort is ascending or descending

## Table Handlers

| Key | Description |
| --- | ----------- |
| hideColumn | hides a column
| onHeaderClick | callback for when a column header is clicked
| onRowClick | callback for when a row is clicked
| showColumn | unhides a column

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