datatable

package
v0.1.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package datatable provides a reusable table component wrapping github.com/charmbracelet/bubbles/table. It adds column sorting, pagination, a configurable empty state, optional multi-row selection and an optional per-column filter prompt. All view state (sort, page, filter) lives on the component and can be persisted/restored via State/SetState so a hosting page can keep it across navigation.

Index

Constants

View Source
const DefaultPageSize = 25

DefaultPageSize is the number of rows shown per page.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Title    string
	Width    int
	Sortable bool
}

Column defines a single table column.

type Option

type Option func(*Table)

Option configures a Table.

func WithEmptyMessage

func WithEmptyMessage(msg string) Option

WithEmptyMessage sets the message shown when there are no rows.

func WithFilter

func WithFilter(col int) Option

WithFilter enables the per-column filter prompt on the given column index.

func WithPageSize

func WithPageSize(n int) Option

WithPageSize overrides the default page size.

func WithSelection

func WithSelection(hint string) Option

WithSelection enables multi-row selection. hint is shown in the batch-actions line when at least one row is selected.

type Pagination

type Pagination struct {
	Page     int // 1-based
	PageSize int
}

Pagination holds paging state.

type SortDir

type SortDir int

SortDir is the sort direction applied to a column.

const (
	// SortNone means the table is unsorted.
	SortNone SortDir = iota
	// SortAsc sorts ascending (indicator ▲).
	SortAsc
	// SortDesc sorts descending (indicator ▼).
	SortDesc
)

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is the reusable table component.

func New

func New(cols []Column, rows [][]string, opts ...Option) *Table

New creates a Table from column definitions and rows.

func (*Table) SelectedRows

func (t *Table) SelectedRows() [][]string

SelectedRows returns the raw rows currently selected on this page.

func (*Table) SetDimensions

func (t *Table) SetDimensions(width, height int)

SetDimensions sets the component size.

func (*Table) SetRows

func (t *Table) SetRows(rows [][]string)

SetRows replaces the full dataset. Selection is cleared and the page clamped.

func (*Table) SetState

func (t *Table) SetState(s TableState)

SetState restores previously captured view state.

func (*Table) State

func (t *Table) State() TableState

State returns the current persistable view state.

func (*Table) Update

func (t *Table) Update(msg tea.Msg) tea.Cmd

Update handles a message and returns any resulting command.

func (*Table) View

func (t *Table) View() string

View renders the table.

type TableState

type TableState struct {
	SortCol    int // sorted column index, -1 when unsorted
	SortDir    SortDir
	Pagination Pagination
	Filter     string
	FilterCol  int
}

TableState is the persistable view state of a Table.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL