Skip to content

PaginatedTable API Reference

Complete reference for the PaginatedTable type for handling large datasets.

PaginatedTable Type

go
type PaginatedTable struct {
    *Table  // Embeds Table, inheriting its methods
    // Internal pagination fields
}

PaginatedTable extends Table with pagination and search capabilities. Perfect for datasets with 100+ rows.


Constructor Functions

NewPaginated()

Creates a new paginated table.

go
func NewPaginated(title string, pageSize int) *PaginatedTable

Parameters:

  • title (string): The window title
  • pageSize (int): Number of rows per page (must be > 0)

Returns:

  • *PaginatedTable: A new paginated table instance

Example:

go
table := gotableview.NewPaginated("Large Dataset", 50)
table.Columns("Name", "Email").Rows(largeDataset).Show()

Recommended Page Sizes:

  • Small (100-500 rows): 50
  • Medium (500-5000 rows): 50-100
  • Large (5000+ rows): 100-200

Configuration Methods

PaginatedTable inherits all methods from Table:

  • Columns() / ColumnNames()
  • ColumnWidths()
  • HeaderFont()
  • ContentFont()

Columns()

Sets column headers (inherited from Table).

go
func (pt *PaginatedTable) Columns(cols ...string) *PaginatedTable

Returns:

  • *PaginatedTable (for chaining)

Example:

go
table.Columns("ID", "Name", "Email", "Status")

ColumnNames()

Alias for Columns().

go
func (pt *PaginatedTable) ColumnNames(names ...string) *PaginatedTable

Data Methods

Row()

Adds a single row (inherited but overridden).

go
func (pt *PaginatedTable) Row(values ...string) *PaginatedTable

Parameters:

  • values (...string): Cell values

Returns:

  • *PaginatedTable

Example:

go
table.Row("1", "Alice", "alice@example.com", "Active")

Rows()

Adds multiple rows at once.

go
func (pt *PaginatedTable) Rows(data [][]string) *PaginatedTable

Parameters:

  • data ([][]string): 2D slice of row data

Returns:

  • *PaginatedTable

Example:

go
data := loadLargeDataset()  // 1000 rows
table.Rows(data)

Search Features

WithSearch()

Enables search functionality across all columns.

go
func (pt *PaginatedTable) WithSearch() *PaginatedTable

Returns:

  • *PaginatedTable

Features:

  • Adds search box above table
  • Real-time filtering as you type
  • Case-insensitive search
  • Searches all columns
  • Updates pagination automatically

Example:

go
gotableview.NewPaginated("Employees", 50).
    Columns("Name", "Department", "Email").
    Rows(employees).
    WithSearch().  // Search all 3 columns
    Show()
Screenshot: Table with search box at top showing "Search:" label

SearchInColumns()

Enables search on specific columns by name.

go
func (pt *PaginatedTable) SearchInColumns(columnNames ...string) *PaginatedTable

Parameters:

  • columnNames (...string): Names of columns to search

Returns:

  • *PaginatedTable

Important:

  • Column names must exactly match (case-sensitive)
  • Invalid column names are ignored
  • More efficient than searching all columns

Example:

go
gotableview.NewPaginated("Products", 50).
    Columns("ID", "Name", "Category", "Price", "Description").
    Rows(products).
    SearchInColumns("Name", "Category").  // Search only these 2
    Show()
Screenshot: Search box labeled "Search (Name, Category):"

SearchInColumnIndices()

Enables search on specific columns by index.

go
func (pt *PaginatedTable) SearchInColumnIndices(indices ...int) *PaginatedTable

Parameters:

  • indices (...int): Zero-based column indices

Returns:

  • *PaginatedTable

Important:

  • Indices are zero-based (first column = 0)
  • Invalid indices are ignored

Example:

go
gotableview.NewPaginated("Data", 50).
    Columns("Col0", "Col1", "Col2", "Col3").
    Rows(data).
    SearchInColumnIndices(1, 3).  // Search columns 1 and 3
    Show()

WithColumnSelector()

Adds a dropdown for users to choose which column to search.

go
func (pt *PaginatedTable) WithColumnSelector() *PaginatedTable

Returns:

  • *PaginatedTable

Features:

  • Dropdown appears next to search box
  • "All Columns" option (default)
  • Individual column options
  • Search updates when selection changes

Example:

go
gotableview.NewPaginated("Products", 50).
    Columns("ID", "Name", "Category", "Price").
    Rows(products).
    WithColumnSelector().  // User chooses column
    Show()
Screenshot: Search box with dropdown showing "All Columns", "ID", "Name", "Category", "Price"

Font Methods

HeaderFont()

Sets header font (inherited from Table).

go
func (pt *PaginatedTable) HeaderFont(name string, size int, bold, italic bool) *PaginatedTable

Returns:

  • *PaginatedTable

ContentFont()

Sets content font (inherited from Table).

go
func (pt *PaginatedTable) ContentFont(name string, size int, bold, italic bool) *PaginatedTable

Returns:

  • *PaginatedTable

Display Method

Show()

Displays the paginated table window.

go
func (pt *PaginatedTable) Show()

Features Added to Basic Table:

  • "< Previous" button
  • "Next >" button
  • Page indicator: "Page X of Y (Showing A-B of C rows)"
  • Search box (if enabled)
  • Column selector dropdown (if enabled)

Example:

go
table.Show()  // Blocks until window closed

Pagination Controls

When you call Show(), these controls appear automatically:

  • < Previous: Go to previous page

    • Disabled on first page
    • Keyboard shortcut: Left arrow (future)
  • Next >: Go to next page

    • Disabled on last page
    • Keyboard shortcut: Right arrow (future)

Page Indicator

Shows current position:

Page 3 of 15 (Showing 201-300 of 1500 rows)
  • Current page number
  • Total pages
  • Row range on current page
  • Total rows (after filtering)

Complete Examples

Example 1: Basic Pagination

go
package main

import "github.com/mansoldof/goTableView"

func main() {
    // Load 500 rows
    data := loadData()
    
    gotableview.NewPaginated("Data", 50).
        Columns("ID", "Name", "Value").
        Rows(data).
        Show()
}

Example 2: Pagination + Search All

go
gotableview.NewPaginated("Employees", 100).
    Columns("Name", "Department", "Email", "Phone").
    Rows(employees).
    WithSearch().  // Search all columns
    Show()
go
gotableview.NewPaginated("Products", 50).
    Columns("ID", "Name", "Category", "Price", "Stock").
    Rows(products).
    SearchInColumns("Name", "Category").  // Search specific columns
    Show()

Example 4: Pagination + Column Selector

go
gotableview.NewPaginated("Logs", 100).
    Columns("Time", "Level", "Source", "Message").
    Rows(logs).
    WithColumnSelector().  // User chooses column
    Show()

Example 5: All Features

go
gotableview.NewPaginated("Full Featured", 50).
    Columns("ID", "Name", "Category", "Price", "Stock").
    ColumnWidths(60, 200, 120, 100, 80).
    HeaderFont("Arial", 11, true, false).
    ContentFont("Segoe UI", 10, false, false).
    Rows(largeDataset).
    WithColumnSelector().
    Show()

Search Behavior

Case Insensitivity

All searches are case-insensitive:

go
// Searching "engineering" will match:
// "Engineering", "ENGINEERING", "engineering", "EnGiNeErInG"

Partial Matching

Search matches any part of the cell:

go
// Searching "john" will match:
// "John Smith", "johnson@example.com", "Johnny", "john123"

Real-Time Filtering

  • Results update as you type
  • No need to press Enter
  • Pagination updates automatically
  • Row count updates immediately

Performance Tips

Choose Appropriate Page Size

go
// Too small - excessive clicking ❌
gotableview.NewPaginated("Data", 10).Rows(bigData).Show()

// Too large - slow rendering ❌
gotableview.NewPaginated("Data", 1000).Rows(bigData).Show()

// Just right ✅
gotableview.NewPaginated("Data", 100).Rows(bigData).Show()

Limit Search Columns

go
// Slower - searches 8 columns
WithSearch()

// Faster - searches 2 columns
SearchInColumns("Name", "Email")

Use Column Selector for Flexibility

go
// Best of both worlds:
// - Fast search (one column at a time)
// - User can search any column they want
WithColumnSelector()

Comparison with Table

FeatureTablePaginatedTable
Max Recommended Rows~100100,000+
Pagination
Search
Column Selector
Memory UsageHigher (all visible)Lower (page at a time)
Rendering SpeedSlower for large dataConsistent
Use CaseSmall datasetsLarge datasets

See Also

Released under the MIT License.