# @front.zen/table

> Frontzen Table

Latest version **3.4.3** (published 2024-05-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @front.zen/table
pnpm add @front.zen/table
yarn add @front.zen/table
bun add @front.zen/table
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.4.3 |
| Published | 2024-05-18 |
| First published | 2023-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 49.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mdamda, amir.qasemi74, mha15, alisajadih |

## Links

- npm: https://www.npmjs.com/package/@front.zen/table
- npm.io page: https://npm.io/package/@front.zen/table

## Dependencies (5)

- [tss-react](https://npm.io/package/tss-react.md) ^4.9.2
- [react-window](https://npm.io/package/react-window.md) ^1.8.9
- [@front.zen/icons](https://npm.io/package/@front.zen/icons.md) *
- [@react-spring/web](https://npm.io/package/@react-spring/web.md) ^9.7.3
- [react-use-measure](https://npm.io/package/react-use-measure.md) ^2.1.1

## Recent versions

- 3.4.3 (latest) — 2024-05-18
- 3.4.2 — 2024-05-08
- 3.4.1 — 2024-03-24
- 3.4.0 — 2024-03-05
- 3.3.0 — 2024-01-07
- 3.2.0 — 2023-12-12
- 3.0.0 — 2023-12-06
- 2.0.0 — 2023-10-25
- 1.4.5 — 2023-10-22
- 1.4.3 — 2023-10-21
- 1.4.2 — 2023-10-15
- 1.4.1 — 2023-10-14
- 1.4.0 — 2023-10-10
- 1.3.1 — 2023-09-03
- 1.3.0 — 2023-08-29
- … 11 more at https://npm.io/package/@front.zen/table/versions

## README

<h1 align="center" >Frontzen Table</h1>

Frontzen Table provides React UI components based on [MUI](https://mui.com) and [@tanstack/react-table](https://tanstack.com/table/v8). Click [HERE](https://63735b95ebfbcb4de6ddaa4d-dqcakcspwn.chromatic.com) to see the storybooks.

## 📦 Install

```bash
npm install @front.zen/table
```

```bash
yarn add @front.zen/table
```

## 🔨 Usage

### Basic

```tsx
import { DataTable } from '@front.zen/table';
import { createColumnHelper, getCoreRowModel, useReactTable } from '@tanstack/react-table';

interface Entity {
  id: number;
}

const helper = createColumnHelper<Entity>();

const columns = [
  helper.accessor((row) => row.id, {
    id: 'index',
    header: `id`,
    cell: (props) => <p>{props.renderValue()}</p>,
  }),
];

const data: Entity[] = Array<Entity>(10).fill({
  id: 1,
});

const App = () => {
  const table = useReactTable({
    columns,
    data,
    getCoreRowModel: getCoreRowModel(),
    enableRowSelection: false,
  });

  return <DataTable instance={table} />;
};
```

### Pagination, Filter, Select, Sorting

```tsx
import { DataFilter, DataPagination, DataTable } from '@front.zen/table';
import {
  ColumnFiltersState,
  PaginationState,
  SortingState,
  getCoreRowModel,
  useReactTable,
} from '@tanstack/react-table';

interface Entity {
  id: number;
}

const helper = createColumnHelper<Entity>();

const columns = [
  helper.accessor((row) => row.id, {
    id: 'index',
    header: `id`,
    cell: (props) => <p>{props.renderValue()}</p>,
    filter: ({ column }) => (
      <input name={column.id} value={column.getFilterValue()} onChange={(e) => column.setFilterValue(e.target.value)} />
    ),
  }),
];

const data: Entity[] = Array<Entity>(10).fill({
  id: 1,
});

const App = () => {
  const [filters, setFilters] = useState<ColumnFiltersState>([]);
  const [pagination, setPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 10 });
  const [sorting, setSorting] = useState<SortingState>([]);

  const table = useReactTable({
    state: { columnFilters: filters, pagination, sorting, rowSelection },
    columns,
    data,
    getCoreRowModel: getCoreRowModel(),
    onColumnFiltersChange: setFilters,
    onSortingChange: setSorting,
    onPaginationChange: setPagination,
    manualPagination: true,
    getRowCanExpand: () => true,
    enableRowSelection: true,
    onRowSelectionChange: setRowSelection,
  });

  return (
    <>
      <DataTable instance={table} renderRowDetails={(row) => <p>I expanded</p>} />
      <DataPagination instance={table} />
      <DataFilter instance={table} />
    </>
  );
};
```

### Active Row hook

```tsx
import { DataTable } from '@front.zen/table';
import { table } from './yourInstance';

const App = () => {
  const { getRowProps, activeRow, clearActiveRow } = useActiveRow<Entity>();

  return (
    <>
      <DataTable
        instance={table}
        getRowExtraProps={(row) => ({
          ...getRowProps(row),
        })}
      />
      {activeRow && <p>{activeRow.id}</p>}
    </>
  );
};
```

## ⌨️ Development

This repo is powered by [TurboRepo](https://turbo.build/repo). You can use TurboRepo commands to work with this repo.

To run all storybooks locally:

```bash
$ git clone git@github.com:frontzen/design-system.git
$ cd design-system
$ cd table
$ yarn install
$ yarn storybook
```

You can also use chromatic for UI review. [link](https://www.chromatic.com/builds?appId=62d39f56a426a9878a3e1f3d)

## 🤝 Contributing [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

We welcome contributions to Frontzen design system! Development of design system happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements.

📥 [Pull requests](https://github.com/frontzen/design-system/pulls) and 🌟 Stars are always welcome.

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