table

package
v0.0.0-...-e864873 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	ID               ID
	Disabled         bool
	Title            string
	MinWidth         int
	MaxWidth         int
	Align            lipgloss.Position
	DisableFiltering bool
}

type Config

type Config[T Row] struct {
	SelectFn           func(value T) tea.Cmd
	RowFn              func(value T) []string
	FetchFn            func() tea.Cmd
	NoResultsMsg       string
	NoResultsFilterMsg string
	AllowHighlighting  bool
}

type ID

type ID string

type Model

type Model[T Row] struct {
	*types.ComponentModel
	// contains filtered or unexported fields
}

func New

func New[T Row](app types.AppState, columns []*Column, config Config[T]) *Model[T]

New returns a new table component. it will by default be in a loading state.

func (*Model[T]) AllIDs

func (m *Model[T]) AllIDs() []ID

AllIDs returns all of the IDs of the data. See also Model.IDs.

func (*Model[T]) AppendRow

func (m *Model[T]) AppendRow(row T)

AppendRow appends a row to the table.

func (*Model[T]) DeleteRowByID

func (m *Model[T]) DeleteRowByID(id ID)

DeleteRowByID deletes a row by its ID, if it exists.

func (*Model[T]) Fetch

func (m *Model[T]) Fetch(setLoading bool) tea.Cmd

Fetch fetches the data from the [Config.FetchFn].

func (*Model[T]) GetAllRows

func (m *Model[T]) GetAllRows() []T

GetAllRows returns the data.

func (*Model[T]) GetColumnByID

func (m *Model[T]) GetColumnByID(id ID) *Column

GetColumnByID returns a column by its ID, if it exists.

func (*Model[T]) GetFilteredRows

func (m *Model[T]) GetFilteredRows() iter.Seq[T]

GetFilteredRows returns an iterator of rows that are filtered.

func (*Model[T]) GetHighlightedRows

func (m *Model[T]) GetHighlightedRows() iter.Seq[T]

GetHighlightedRows returns an iterator of rows that are highlighted.

func (*Model[T]) GetRowByID

func (m *Model[T]) GetRowByID(id ID) T

GetRowByID returns a row by its ID, if it exists.

func (*Model[T]) GetRows

func (m *Model[T]) GetRows() iter.Seq[T]

GetRows returns an iterator of rows. If filtering is enabled, it will return the filtered results.

func (*Model[T]) GetSelectedRow

func (m *Model[T]) GetSelectedRow() (v T, found bool)

GetSelectedRow returns the currently selected row. If there is no selected row (e.g. no data), will return false.

func (*Model[T]) GetVisibleRows

func (m *Model[T]) GetVisibleRows() iter.Seq[T]

GetVisibleRows returns an iterator of rows that are visible in the current view.

func (*Model[T]) GoToBottom

func (m *Model[T]) GoToBottom()

GoToBottom moves the selected row, and view, to the bottom of the table.

func (*Model[T]) GoToTop

func (m *Model[T]) GoToTop()

GoToTop moves the selected row, and view, to the top of the table.

func (*Model[T]) IDs

func (m *Model[T]) IDs() []ID

IDs returns the IDs of the data. If filtering is enabled, it will return the filtered IDs. See also Model.AllIDs.

func (*Model[T]) Init

func (m *Model[T]) Init() tea.Cmd

func (*Model[T]) MoveDown

func (m *Model[T]) MoveDown(n int)

MoveDown moves the selected row down by the given number of rows.

func (*Model[T]) MoveLeft

func (m *Model[T]) MoveLeft(n int)

MoveLeft moves the selected row left by the given number of columns.

func (*Model[T]) MoveRight

func (m *Model[T]) MoveRight(n int)

MoveRight moves the selected row right by the given number of columns.

func (*Model[T]) MoveUp

func (m *Model[T]) MoveUp(n int)

MoveUp moves the selected row up by the given number of rows.

func (*Model[T]) PrependRow

func (m *Model[T]) PrependRow(row T)

PrependRow prepends a row to the table.

func (*Model[T]) SetColumns

func (m *Model[T]) SetColumns(columns []*Column)

SetColumns updates the columns, does some basic validation (at least 1 enabled, correct min/max widths, etc), panics if invalid, and updates internal caches.

func (*Model[T]) SetDimensions

func (m *Model[T]) SetDimensions(width, height int)

SetDimensions sets the dimensions of the table. Prefer this over [SetWidth] and [SetHeight] as it will be more efficient.

func (*Model[T]) SetFilter

func (m *Model[T]) SetFilter(filter string)

SetFilter sets the filter string and updates the table. Setting to an empty string will clear all filtering.

func (*Model[T]) SetHeight

func (m *Model[T]) SetHeight(height int)

SetHeight sets the total height of the table.

func (*Model[T]) SetLoading

func (m *Model[T]) SetLoading() tea.Cmd

SetLoading returns a tea.Cmd that sets the loading state to true. Will automatically be set back to false once data has been updated/fetched/etc using Model.SetRows.

func (*Model[T]) SetRows

func (m *Model[T]) SetRows(values []T)

SetRows sets the data for the table.

func (*Model[T]) SetSelected

func (m *Model[T]) SetSelected(id ID)

SetSelected sets the selected row to the given ID, if it exists. If it doesn't, it will default to the first row.

func (*Model[T]) SetStyles

func (m *Model[T]) SetStyles(s Styles)

func (*Model[T]) SetWidth

func (m *Model[T]) SetWidth(width int)

SetWidth sets the total width of the table.

func (*Model[T]) ToggleColumn

func (m *Model[T]) ToggleColumn(id ID, enabled bool)

ToggleColumn toggles a specific column on or off.

func (*Model[T]) TotalFilteredRows

func (m *Model[T]) TotalFilteredRows() int

TotalFilteredRows returns the number of filtered rows. If filtering is not enabled, it will return the total number of rows ignoring filtering (e.g. Model.TotalRows).

func (*Model[T]) TotalRows

func (m *Model[T]) TotalRows() int

TotalRows returns the total number of data entries.

func (*Model[T]) Update

func (m *Model[T]) Update(msg tea.Msg) tea.Cmd

func (*Model[T]) UpdateRow

func (m *Model[T]) UpdateRow(row T)

UpdateRow updates a row in the table, if it exists.

func (*Model[T]) View

func (m *Model[T]) View() string

type Row

type Row interface {
	ID() ID
}

type StaticRow

type StaticRow[T any] struct {
	Value   T
	ValueID ID
}

StaticRow is a row that is created from a static value and ID.

func RowsFrom

func RowsFrom[T any](data []T, idFn func(T) ID) []*StaticRow[T]

RowsFrom creates a slice of rows from a slice of data using a function to get the ID of each row, which satisfies the Row interface.

func (*StaticRow[T]) ID

func (r *StaticRow[T]) ID() ID

type Styles

type Styles struct {
	Base                      lipgloss.Style
	NoResults                 lipgloss.Style
	Header                    lipgloss.Style
	Cell                      lipgloss.Style
	SelectedRow               lipgloss.Style
	HighlightedRow            lipgloss.Style
	HighlightedAndSelectedRow lipgloss.Style
}

Jump to

Keyboard shortcuts

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