tally-vue
v0.1.1
Published
Vue composables for Tally.
Readme
tally-vue
Vue composables for Tally. The engine lives in tally-core; this package binds a Grid to a component's lifecycle and exposes its stores as shallow refs. It renders nothing.
Not published yet.
Install
npm install tally-vue tally-core vueVue 3.5 or newer.
Usage
<script setup lang="ts">
import { createArraySource, createSchema } from 'tally-core'
import { useGrid, useGridState, useView } from 'tally-vue'
const props = defineProps<{ rows: Account[] }>()
const schema = createSchema({
key: 'id',
columns: [
{ id: 'account', label: 'Account' },
{ id: 'mrr', label: 'MRR', type: 'currency', aggregate: 'sum' },
],
})
const source = createArraySource(props.rows, schema)
const grid = useGrid({ schema, source })
const state = useGridState(grid)
const view = useView(grid)
</script>
<template>
<p>{{ state.status }}, sorted by {{ view.sort[0]?.column ?? 'nothing' }}</p>
<button @click="grid.view.toggleSort('mrr')">Sort by MRR</button>
</template>useGrid accepts options, a ref or a getter. It creates a Grid from tally-core, loads it after mount and disposes it when the scope stops. It recreates the grid when schema or source change identity, and when the format context changes, carrying the current view over. Reactive proxies are unwrapped before they reach the engine.
Loading and subscriptions start after mount, so server rendering produces the initial state without touching the data source.
Composables
| Composable | Returns |
| -------------------- | --------------------------------------------------------------- |
| useGrid(options) | A ComputedRef<Grid> bound to the current effect scope. |
| useGridState(grid) | A shallow readonly ref of status, totals, aggregates and page. |
| useView(grid) | A shallow readonly ref of the current View. |
| useRows(grid) | A shallow readonly ref of loaded rows and changed cells. |
| useSelection(grid) | A shallow readonly ref of the active cell, ranges and rows. |
| provideGrid(grid) | Provides a grid to descendants. |
| injectGrid() | The provided grid as a ComputedRef<Grid>. Throws without one. |
Every composable that takes grid accepts a Grid, a ref or a getter, and follows the grid when it is recreated. Derive narrower values with computed.
