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 identifierdata (
listofdict, optional) – Table data as list of row dictionariescolumns (
listofstrorlistofdict, 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”)tab_index (int | None)
- Variables:
width (
int) – Display widthheight (
int) – Display height (total including header)sortable (
bool) – Whether sorting is enabledshow_header (
bool) – Whether header is visibleshow_scrollbar (
bool) – Whether scrollbar is visibleborder_style (
str) – Rich border stylesort_direction (
str) – Sort direction (“asc” or “desc”)scroll_manager (
ScrollManager) – Manages scrolling of table rowson_sort (
callableorNone) – Callback when sort changes. Signature: on_sort(column_key, direction) -> Noneon_row_click (
callableorNone) – Callback when a row is clicked. Signature: on_row_click(row_index, row_data) -> Noneon_row_double_click (
callableorNone) – Callback when a row is double-clicked. Signature: on_row_double_click(row_index, row_data) -> Noneon_cell_click (
callableorNone) – Callback when a cell is clicked. Signature: on_cell_click(row_index, column_key, cell_value) -> Noneon_header_click (
callableorNone) – 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:
- 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 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_tabWhether this element wants the Tab key instead of focus movement.
Table rows (the working copy, which may be sorted).
parent_frameGet the parent Frame if this element is inside a scrollable frame.
Get the current scroll position.
scroll_state_keyGet the state key for vertical scroll position.
scroll_state_key_xGet the state key for horizontal scroll position.
supports_dynamic_sizingWhether 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:
- get_ephemeral_state()[source]
Get ephemeral state for reconciliation.
- Returns:
Scroll position to preserve across re-renders
- Return type:
- 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
- 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 = rowsstays in sync the same wayset_data()does, instead of desyncing_raw_dataand the scroll manager.
- 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:
- async handle_mouse(event)[source]
Handle mouse input.
- Parameters:
event (
MouseEvent) – Mouse event to handle- Returns:
True if event was handled
- Return type:
- 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