Skip to main content
Home pageComponentsTable

Table

A data table with sortable columns, density options, and striped rows. Columns and data are set via JavaScript properties.

Playground​

HTMLReact
ShareCopy

Usage​

<lt-table id="my-table" hoverable striped></lt-table>

<script type="module">
const table = document.getElementById('my-table');
table.columns = [
{ key: 'name', label: 'Name', sortable: true },
{ key: 'role', label: 'Role' },
{ key: 'status', label: 'Status' },
];
table.data = [
{ name: 'Alice', role: 'Engineer', status: 'Active' },
{ name: 'Bob', role: 'Designer', status: 'Active' },
{ name: 'Charlie', role: 'Manager', status: 'Away' },
];
</script>
import { Table } from '@latty-ds/react';

const columns = [
{ key: 'name', label: 'Name', sortable: true },
{ key: 'role', label: 'Role' },
{ key: 'status', label: 'Status' },
];

const data = [
{ name: 'Alice', role: 'Engineer', status: 'Active' },
{ name: 'Bob', role: 'Designer', status: 'Active' },
{ name: 'Charlie', role: 'Manager', status: 'Away' },
];

<Table columns={columns} data={data} hoverable striped />
<script setup lang="ts">
const columns = [
{ key: 'name', label: 'Name', sortable: true },
{ key: 'role', label: 'Role' },
{ key: 'status', label: 'Status' },
]

const data = [
{ name: 'Alice', role: 'Engineer', status: 'Active' },
{ name: 'Bob', role: 'Designer', status: 'Active' },
{ name: 'Charlie', role: 'Manager', status: 'Away' },
]
</script>

<template>
<lt-table :columns="columns" :data="data" hoverable striped></lt-table>
</template>

A caption gives the table a visible, accessible title — unlike label (which only sets aria-label), it's shown on screen above (or with caption-side="bottom", below) the table. sticky-header pins the header row to the top of the nearest scrolling ancestor; set height (a fixed CSS length) to bound the table to its own scroll area instead of letting it grow to fit every row — otherwise that ancestor is usually just the page.

Listen for rowclick to react to a click anywhere on a body row — useful for navigation or a custom selection UI the built-in column features don't cover:

table.addEventListener('rowclick', (e) => {
console.log(e.detail.row, e.detail.index);
});

Set selection-mode="multiple" (checkboxes + a "select all" control) or selection-mode="single" (radio buttons) to add a built-in selection column. selected is an array of row keys — the row-key field's value for each selected row when row-key is set, otherwise the row's index — and is controlled the same way sort is: pass it to manage selection yourself, or leave it unset and listen for selectionchange:

table.selectionMode = 'multiple';
table.rowKey = 'id';
table.addEventListener('selectionchange', (e) => {
console.log(e.detail.selected); // e.g. [1, 3]
});

Set resizable: true on a column to let it be dragged wider or narrower from a handle at its trailing edge (keyboard users can tab to the same handle and use the arrow keys). Listen for columnresize to persist the chosen width — the table keeps its own live override internally either way, so persistence is optional:

table.columns = [{ key: 'name', label: 'Name', resizable: true, width: '200px' }];
table.addEventListener('columnresize', (e) => {
console.log(e.detail.key, e.detail.width); // e.g. "name", "238px"
});

Set page-size to paginate client-side — the table renders no pagination controls of its own, so pair it with a standalone lt-pagination, reading totalPages off the table and writing each page change straight back onto page:

table.pageSize = 10;
pager.totalPages = table.totalPages; // re-read after any `data` change, same as right here
pager.addEventListener('change', (e) => {
table.page = e.detail.page;
});

For a large dataset, set virtualized together with height to render only the rows currently scrolled into view (plus a small buffer) instead of every row at once:

table.height = '400px';
table.virtualized = true;
table.rowHeight = 44; // every row must render at this same fixed height for the windowing math to work

virtualized has no effect without height (there'd be no bounded viewport to compute visibility against) — set without it, it's a no-op with a console warning in development. Not supported together with responsive-mode="stack", whose card-style rows have no uniform height to assume.

API​