useTableRowIndex — Numbered Rows
A table with a prepended row-number column via useTableRowIndex. Numbering is monospaced, right-aligned, and follows the rendered data order.
// Copyright (c) Meta Platforms, Inc. and affiliates.
'use client';
import {
Table,
useTableRowIndex,
proportional,
pixel,
} from '@astryxdesign/core/Table';
import type {TableColumn} from '@astryxdesign/core/Table';
interface Track extends Record<string, unknown> {
id: string;
title: string;
artist: string;
plays: number;
}
const tracks: Track[] = [
{id: 't1', title: 'Nightfall', artist: 'Ava Chen', plays: 1820},
{id: 't2', title: 'Ember', artist: 'Liam Park', plays: 942},
{id: 't3', title: 'Tidal', artist: 'Zoe Vega', plays: 3310},
{id: 't4', title: 'Cinder', artist: 'Max Ross', plays: 604},
{id: 't5', 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: pixel(90), align: 'end'},
];
export default function TableRowIndexTable() {
// Pass the rendered data array — numbering follows its order.
const rowIndex = useTableRowIndex<Track>({data: tracks});
return (
<Table
data={tracks}
columns={columns}
idKey="id"
hasHover
plugins={{rowIndex}}
/>
);
}