wijjit.elements.display.table.Table

class wijjit.elements.display.table.Table(id=None, classes=None, data=None, columns=None, width=60, height=10, sortable=False, show_header=True, show_scrollbar=True, border_style='single', tab_index=None, bind=True)[source]

Table element for displaying tabular data with sorting.

This element provides a rich table display with support for: - Column-based data display - Column sorting with visual indicators - Scrolling for large datasets - Mouse and keyboard interaction

Parameters:
  • id (str, optional) – Element identifier

  • data (list of dict, optional) – Table data as list of row dictionaries

  • columns (list of str or list of dict, optional) – Column definitions. Can be simple strings or dicts with ‘key’, ‘label’, ‘width’

  • width (int, optional) – Display width in columns (default: 60)

  • height (int, optional) – Display height in rows (default: 10, includes header)

  • sortable (bool, optional) – Whether columns can be sorted (default: False)

  • show_header (bool, optional) – Whether to show column headers (default: True)

  • show_scrollbar (bool, optional) – Whether to show vertical scrollbar (default: True)

  • border_style (str, optional) – Rich table border style (default: “single”)

  • classes (str | list[str] | set[str] | None)

  • tab_index (int | None)

  • bind (bool | str)

Variables:
  • data (list of dict) – Table data

  • columns (list of dict) – Normalized column definitions

  • width (int) – Display width

  • height (int) – Display height (total including header)

  • sortable (bool) – Whether sorting is enabled

  • show_header (bool) – Whether header is visible

  • show_scrollbar (bool) – Whether scrollbar is visible

  • border_style (str) – Rich border style

  • sort_column (str or None) – Currently sorted column key

  • sort_direction (str) – Sort direction (“asc” or “desc”)

  • scroll_manager (ScrollManager) – Manages scrolling of table rows

  • on_sort (callable or None) – Callback when sort changes. Signature: on_sort(column_key, direction) -> None

  • on_row_click (callable or None) – Callback when a row is clicked. Signature: on_row_click(row_index, row_data) -> None

  • on_row_double_click (callable or None) – Callback when a row is double-clicked. Signature: on_row_double_click(row_index, row_data) -> None

  • on_cell_click (callable or None) – Callback when a cell is clicked. Signature: on_cell_click(row_index, column_key, cell_value) -> None

  • on_header_click (callable or None) – Callback when a column header is clicked. Signature: on_header_click(column_key) -> None

__init__(id=None, classes=None, data=None, columns=None, width=60, height=10, sortable=False, show_header=True, show_scrollbar=True, border_style='single', tab_index=None, bind=True)[source]

Initialize scrollable element.

Parameters:
  • id (str, optional) – Element identifier

  • classes (str or list of str or set of str, optional) – CSS class names for styling

  • tab_index (int, optional) – Tab order for focus navigation

  • data (list[dict] | None)

  • columns (list[str] | list[dict] | None)

  • width (int)

  • height (int)

  • sortable (bool)

  • show_header (bool)

  • show_scrollbar (bool)

  • border_style (str)

  • bind (bool | str)

Return type:

None

Methods

__init__([id, classes, data, columns, ...])

Initialize scrollable element.

add_class(class_name)

Add a CSS class to this element.

apply_props(props)

Apply props from a VNode, skipping ephemeral props.

can_scroll(direction)

Check if the element can scroll in the given direction.

get_ephemeral_state()

Get ephemeral state for reconciliation.

get_hardware_cursor_position()

Absolute screen cell where the hardware terminal cursor should park.

get_height_for_width(width)

Return the height this element needs when laid out at width.

get_intrinsic_size()

Get the intrinsic (preferred) size of the element.

handle_key(key)

Handle keyboard input for scrolling.

handle_mouse(event)

Handle mouse input.

has_class(class_name)

Check if element has a CSS class.

on_blur()

Called when element loses focus.

on_focus()

Called when element gains focus.

on_hover_enter()

Called when mouse enters element.

on_hover_exit()

Called when mouse exits element.

on_mount()

Called when element is first added to the element tree.

on_unmount()

Called when element is removed from the element tree.

on_update(changed_props)

Handle prop updates during reconciliation.

remove_class(class_name)

Remove a CSS class from this element.

render_signature()

Hashable/comparable capture of everything render_to() reads.

render_to(ctx)

Render table using cell-based rendering (NEW API).

restore_ephemeral_state(state)

Restore ephemeral state after reconciliation.

restore_scroll_position(position)

Restore scroll position from saved state.

set_bounds(bounds)

Set the element's screen bounds.

set_data(data)

Update table data and refresh scroll state.

sort_by_column(column_key)

Sort table by specified column.

toggle_class(class_name)

Toggle a CSS class on this element.

Attributes

captures_tab

Whether this element wants the Tab key instead of focus movement.

data

Table rows (the working copy, which may be sorted).

parent_frame

Get the parent Frame if this element is inside a scrollable frame.

scroll_position

Get the current scroll position.

scroll_state_key

Get the state key for vertical scroll position.

scroll_state_key_x

Get the state key for horizontal scroll position.

supports_dynamic_sizing

Whether this element supports dynamic sizing.

restore_scroll_position(position)[source]

Restore scroll position from saved state.

Parameters:

position (int) – Scroll position to restore

Return type:

None

property scroll_position: int

Get the current scroll position.

Returns:

Current scroll offset (0-based)

Return type:

int

get_ephemeral_state()[source]

Get ephemeral state for reconciliation.

Returns:

Scroll position to preserve across re-renders

Return type:

dict

restore_ephemeral_state(state)[source]

Restore ephemeral state after reconciliation.

Parameters:

state (dict) – State from get_ephemeral_state()

Return type:

None

on_update(changed_props)[source]

Handle prop updates during reconciliation.

Parameters:

changed_props (dict) – Map of prop_name -> (old_value, new_value)

Return type:

None

can_scroll(direction)[source]

Check if the element can scroll in the given direction.

Parameters:

direction (int) – Scroll direction: negative for up, positive for down

Returns:

True if scrolling in the given direction is possible

Return type:

bool

property data: list[dict]

Table rows (the working copy, which may be sorted).

Assignment refreshes the raw backing copy, re-applies any active sort, and re-clamps scroll state – so table.data = rows stays in sync the same way set_data() does, instead of desyncing _raw_data and the scroll manager.

set_data(data)[source]

Update table data and refresh scroll state.

Parameters:

data (list of dict) – New table data

Return type:

None

sort_by_column(column_key)[source]

Sort table by specified column.

Parameters:

column_key (str) – Column key to sort by

Return type:

None

handle_key(key)[source]

Handle keyboard input for scrolling.

Parameters:

key (Key) – Key press to handle

Returns:

True if key was handled

Return type:

bool

async handle_mouse(event)[source]

Handle mouse input.

Parameters:

event (MouseEvent) – Mouse event to handle

Returns:

True if event was handled

Return type:

bool

render_to(ctx)[source]

Render table using cell-based rendering (NEW API).

Parameters:

ctx (PaintContext) – Paint context with buffer, style resolver, and bounds

Return type:

None

Notes

This method implements cell-based rendering for tables by: 1. Rendering the table using Rich library (for layout and formatting) 2. Converting the Rich ANSI output to cells using the ANSI adapter 3. Writing cells to the buffer

This approach leverages Rich’s powerful table formatting while benefiting from cell-based rendering performance.

Theme styles:

This element uses the following theme style classes: - table: Base table style - table:focus: When table has focus - table.header: For column headers - table.row: For table rows - table.border: For table borders - table.border:focus: For borders when focused