# vue-table-hooks

> Hooks for building extendable tables for Vue 2 & 3.

Latest version **0.2.0-alpha.0** (published 2021-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue-table-hooks
pnpm add vue-table-hooks
yarn add vue-table-hooks
bun add vue-table-hooks
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0-alpha.0 |
| Published | 2021-10-24 |
| First published | 2021-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^12.13.0 \|\| ^14.15.0 |
| Dependencies | 2 |
| Unpacked size | 522.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Ernest |
| Maintainers | iendeavor |

## Links

- npm: https://www.npmjs.com/package/vue-table-hooks
- Repository: git@github.com:iendeavor/vue-table-hooks
- Issues: https://github.com/iendeavor/vue-table-hooks/issues
- npm.io page: https://npm.io/package/vue-table-hooks

## Dependencies (2)

- [vue-demi](https://npm.io/package/vue-demi.md) latest
- [sortablejs](https://npm.io/package/sortablejs.md) ^1.14.0

## Recent versions

- 0.2.0-alpha.0 (latest) — 2021-10-24
- 0.2.0-alpha.3 (beta) — 2021-10-24
- 0.2.0-alpha.2 — 2021-10-24
- 0.2.0-alpha.1 — 2021-10-24

## README

# Vue-table-hooks

Hooks for building extendable tables for Vue 2 & 3.

## Getting Started

### Installation

For vue@3:

```sh
yarn add @vue-table-hooks/core
```

For vue@2 + @vue/composition-api

```sh
yarn add @vue-table-hooks/core @vue/composition-api
```

### Usage

Create basic table:

```ts
// components/BasicTable.vue

import { defineComponent, h, PropType } from "vue";
import { Table } from "@vue-table-hooks/core";

export default defineComponent({
  name: "BasicTable",
  props: {
    table: {
      required: true,
      type: Object as PropType<Table>,
    },
  },
  setup(props) {
    return () =>
      h("table", props.table.props, [
        h(
          "thead",
          props.table.thead.props,
          props.table.thead.trs.map((tr) =>
            h(
              "tr",
              tr.props,
              tr.ths.map((th) => h("th", th.props, th.template))
            )
          )
        ),
        h(
          "tbody",
          props.table.tbody.props,
          props.table.tbody.trs.map((tr) =>
            h(
              "tr",
              tr.props,
              tr.tds.map((td) => h("td", td.props, td.template))
            )
          )
        ),
        h(
          "tfoot",
          props.table.tfoot.props,
          props.table.tfoot.trs.map((tr) =>
            h(
              "tr",
              tr.props,
              tr.tds.map((td) => h("td", td.props, td.template))
            )
          )
        ),
      ]);
  },
});
```

Create page:

```html
<!-- views/HelloWorld.vue -->

<template>
  <basic-table :table="table" />
</template>

<script lang="ts">
  import { defineComponent } from "vue";
  import { useTable } from "@vue-table-hooks/core";
  import BasicTable from "components/BasicTable.vue";

  export default defineComponent({
    components: {
      BasicTable,
    },
    setup() {
      const table = useTable({
        data: [
          {
            id: 1,
            name: "Mike",
            age: 32,
            address: "10 Downing Street",
          },
          {
            id: 2,
            name: "John",
            age: 42,
            address: "10 Downing Street",
          },
        ],
        columns: [
          {
            headTitle: "Name",
            key: "name",
          },
          {
            headTitle: "Age",
            key: "age",
          },
          {
            headTitle: "Address",
            key: "address",
          },
        ],
        hooks: [usePagination()],
      });

      return { table };
    },
  });
</script>
```

## Hooks

- [x] useSingleSelection
- [x] useMultipleSelection
- [x] usePagination
- [x] useSpan
- [ ] useFilter
- [x] useSortable (draggable, movable, reorderable)
- [x] useSorting
- [x] useSummary (total)
- [x] useTable
- [ ] useVirtualScroll

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