# useTableRowIndex

## Usage

Hook that returns a TablePlugin which prepends a right-aligned, monospaced row-number column. Numbering follows the rendered data order (reflecting the current sort / filter / pagination view) and starts at 1 by default. Astryx `renderCell` receives only the row item, so the plugin takes the rendered data array to derive each ordinal.

```ts
import { useTableRowIndex } from '@astryx-vue/core/Table'
```

## Examples

### useTableRowIndex — Numbered Rows

A table with a prepended row-number column. Numbering is monospaced, right-aligned, and follows the rendered data order.

```vue
<script setup lang="ts">
import type { TableColumn } from '@astryx-vue/core/Table'
import { proportional, Table, useTableRowIndex } from '@astryx-vue/core/Table'

interface Track extends Record<string, unknown> {
  id: string
  title: string
  artist: string
  plays: number
}

const tracks: Track[] = [
  { id: 'nightfall', title: 'Nightfall', artist: 'Ava Chen', plays: 1820 },
  { id: 'ember', title: 'Ember', artist: 'Liam Park', plays: 942 },
  { id: 'tidal', title: 'Tidal', artist: 'Zoe Vega', plays: 3310 },
  { id: 'cinder', title: 'Cinder', artist: 'Max Ross', plays: 604 },
  { id: 'halcyon', title: 'Halcyon', artist: 'Mia Cole', plays: 2075 },
]

const columns: TableColumn<Track>[] = [
  { key: 'title', header: 'Title', width: proportional(2) },
  { key: 'artist', header: 'Artist', width: proportional(2) },
  { key: 'plays', header: 'Plays', width: proportional(1), align: 'end' },
]

const rowIndex = useTableRowIndex<Track>({
  data: tracks,
  getRowKey: track => track.id,
})
</script>

<template>
  <Table
    :data="tracks"
    :columns="columns"
    id-key="id"
    :plugins="{ rowIndex }"
  />
</template>
```

## Properties

The config is a `MaybeRefOrGetter`, so pass a getter or a ref to keep the plugin on the current values.

## Parameters

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `data` | `readonly T[]` | — | The data array currently rendered by the table (post sort/filter/page). Numbering follows this order. |
| `getRowKey` | `(item: T) => string` | — | Optional key extractor returning a unique string per row. When provided, index lookup is keyed by the returned string; otherwise items are matched by reference identity. A plain function in a getter is already stable, so there is nothing to memoize. |
| `label` | `string` | `'#'` | Header label for the index column. |
| `startFrom` | `number` | `1` | First index value. |

## Returns

| Field | Type | Description |
| --- | --- | --- |
| `transformColumns` | `(columns: TableColumn[]) => TableColumn[]` | Prepends the row-number column. Its key is `__rowIndex`, its width is `pixel(48)`, it aligns to the end and it is not resizable. Group header rows get an empty cell. The number sits in a `span.astryx-table__row-index`, which is monospaced and right-aligned. |
