Skip to content

TableView

Bases: Frame

TableView backed by an in-memory SqliteDataSource.

Provides sortable headers, filtering/search, pagination or virtual scrolling, optional grouping, column striping, and configurable exporting/editing.

Events

  • <<SelectionChange>>: Fired when row selection changes. event.data = {'records': list[dict], 'iids': list[str]}
  • <<RowClick>>: Fired on single row click. event.data = {'record': dict, 'iid': str}
  • <<RowDoubleClick>>: Fired on row double-click. event.data = {'record': dict, 'iid': str}
  • <<RowRightClick>>: Fired on row right-click. event.data = {'record': dict, 'iid': str}
  • <<RowInsert>>: Fired when rows are inserted. event.data = {'records': list[dict]}
  • <<RowUpdate>>: Fired when rows are updated. event.data = {'records': list[dict]}
  • <<RowDelete>>: Fired when rows are deleted. event.data = {'records': list[dict]}
  • <<RowMove>>: Fired when rows are moved/reordered. event.data = {'records': list[dict]}

selected_rows property

selected_rows: list[dict]

List of record dicts for the current Treeview selection.

visible_rows property

visible_rows: list[dict]

List of record dicts for rows currently rendered (flat traversal).

__init__

__init__(
    master: Master = None,
    columns: list[str | dict] | None = None,
    rows: list | None = None,
    datasource: SqliteDataSource | None = None,
    selection_mode: Literal[
        "none", "single", "multi"
    ] = "single",
    allow_select_all: bool = True,
    sorting_mode: Literal["single", "none"] = "single",
    enable_filtering: bool = True,
    enable_header_filtering: bool = True,
    enable_row_filtering: bool = True,
    enable_search: bool = True,
    search_mode: Literal[
        "standard", "advanced"
    ] = "standard",
    search_trigger: Literal["enter", "input"] = "enter",
    paging_mode: Literal[
        "standard", "virtual"
    ] = "standard",
    page_size: int = 25,
    page_index: int = 0,
    page_cache_size: int = 3,
    show_vscrollbar: bool = True,
    show_hscrollbar: bool = False,
    enable_adding: bool = False,
    enable_editing: bool = False,
    enable_deleting: bool = False,
    form_options: dict | None = None,
    enable_exporting: bool = False,
    allow_export_selection: bool = True,
    export_scope: Literal["page", "all"] = "page",
    export_formats: tuple[str, ...] | None = None,
    striped: bool = False,
    striped_background: str = "background[+1]",
    allow_grouping: bool = False,
    show_table_status: bool = True,
    show_column_chooser: bool = False,
    context_menus: Literal[
        "none", "headers", "rows", "all"
    ] = "all",
    column_min_width: int = 40,
    column_auto_width: bool = False,
    **kwargs,
)

Create a TableView backed by an in-memory SqliteDataSource.

Parameters:

Name Type Description Default
master Master

Parent widget.

None
columns list[str | dict] | None

Column definitions (list of strings or dicts with keys like "text", "key", "width", "minwidth").

None
rows list | None

Initial data to load (list of dicts or row-like sequences).

None
datasource SqliteDataSource | None

Custom SqliteDataSource; if omitted, an in-memory source is created.

None
selection_mode Literal['none', 'single', 'multi']

Selection mode ('none', 'single', 'multi'). Defaults to 'single'.

'single'
allow_select_all bool

Whether select-all is allowed. Defaults to True.

True
sorting_mode Literal['single', 'none']

Sorting mode ('single' or 'none'). Defaults to 'single'.

'single'
enable_filtering bool

Enable filtering features. Defaults to True.

True
enable_header_filtering bool

Show filter option in header context menu. Defaults to True.

True
enable_row_filtering bool

Show filter option in row context menu. Defaults to True.

True
enable_search bool

Show search bar. Defaults to True.

True
search_mode Literal['standard', 'advanced']

Search mode ('standard' or 'advanced'). Defaults to 'standard'.

'standard'
search_trigger Literal['enter', 'input']

When to trigger search ('enter' or 'input'). Defaults to 'enter'.

'enter'
paging_mode Literal['standard', 'virtual']

Paging mode ('standard' or 'virtual'). Defaults to 'standard'.

'standard'
page_size int

Number of rows per page. Defaults to 25.

25
page_index int

Initial page index. Defaults to 0.

0
page_cache_size int

Number of pages to cache. Defaults to 3.

3
show_vscrollbar bool

Show vertical scrollbar. Defaults to True.

True
show_hscrollbar bool

Show horizontal scrollbar. Defaults to False.

False
enable_adding bool

Allow adding new rows. Defaults to False.

False
enable_editing bool

Allow editing existing rows. Defaults to False.

False
enable_deleting bool

Allow deleting rows. Defaults to False.

False
form_options dict | None

Options dict for the edit form dialog.

None
enable_exporting bool

Enable export functionality. Defaults to False.

False
allow_export_selection bool

Allow exporting selected rows. Defaults to True.

True
export_scope Literal['page', 'all']

Export scope ('page' or 'all'). Defaults to 'page'.

'page'
export_formats tuple[str, ...] | None

Tuple of export formats (e.g., ('csv', 'xlsx')).

None
striped bool

Show alternating row colors. Defaults to False.

False
striped_background str

Background color for striped rows. Defaults to 'background[+1]'.

'background[+1]'
allow_grouping bool

Allow grouping rows via header context menu. Defaults to False.

False
show_table_status bool

Show filter/sort/group status labels and pager. Defaults to True.

True
show_column_chooser bool

Show column chooser button. Defaults to False.

False
context_menus Literal['none', 'headers', 'rows', 'all']

Context menu visibility ('none', 'headers', 'rows', 'all'). Defaults to 'all'.

'all'
column_min_width int

Global minimum width for columns. Defaults to 40.

40
column_auto_width bool

Automatically size columns to widest visible text. Defaults to False.

False
**kwargs

Additional arguments passed through to Frame.

{}

set_data

set_data(rows: list) -> None

Replace data in the datasource and refresh the grid.

on_selection_changed

on_selection_changed(callback) -> str

Bind to <<SelectionChange>>. Callback receives event.data = {'records': list[dict], 'iids': list[str]}.

off_selection_changed

off_selection_changed(bind_id: str | None = None) -> None

Unbind from <<SelectionChange>>.

on_row_click

on_row_click(callback) -> str

Bind to <<RowClick>>. Callback receives event.data = {'record': dict, 'iid': str}.

off_row_click

off_row_click(bind_id: str | None = None) -> None

Unbind from <<RowClick>>.

on_row_double_click

on_row_double_click(callback) -> str

Bind to <<RowDoubleClick>>. Callback receives event.data = {'record': dict, 'iid': str}.

off_row_double_click

off_row_double_click(bind_id: str | None = None) -> None

Unbind from <<RowDoubleClick>>.

on_row_right_click

on_row_right_click(callback) -> str

Bind to <<RowRightClick>>. Callback receives event.data = {'record': dict, 'iid': str}.

off_row_right_click

off_row_right_click(bind_id: str | None = None) -> None

Unbind from <<RowRightClick>>.

on_row_deleted

on_row_deleted(callback) -> str

Bind to <<RowDelete>>. Callback receives event.data = {'records': list[dict]}.

off_row_deleted

off_row_deleted(bind_id: str | None = None) -> None

Unbind from <<RowDelete>>.

on_row_inserted

on_row_inserted(callback) -> str

Bind to <<RowInsert>>. Callback receives event.data = {'records': list[dict]}.

off_row_inserted

off_row_inserted(bind_id: str | None = None) -> None

Unbind from <<RowInsert>>.

on_row_updated

on_row_updated(callback) -> str

Bind to <<RowUpdate>>. Callback receives event.data = {'records': list[dict]}.

off_row_updated

off_row_updated(bind_id: str | None = None) -> None

Unbind from <<RowUpdate>>.

on_row_moved

on_row_moved(callback) -> str

Bind to <<RowMove>>. Callback receives event.data = {'records': list[dict]}.

off_row_moved

off_row_moved(bind_id: str | None = None) -> None

Unbind from <<RowMove>>.

insert_rows

insert_rows(rows: list) -> None

Insert new rows via the datasource and refresh.

update_rows

update_rows(rows: list[dict]) -> None

Update rows by internal row id; each dict must include the internal row-id key.

delete_rows

delete_rows(rows_or_ids: list) -> None

Delete rows by id or row dicts containing an id key.

insert_columns

insert_columns(*_args, **_kwargs) -> None

Not currently supported; columns are defined at construction time.

delete_columns

delete_columns(indices: list[int]) -> None

Hide columns at the given indices.

move_rows

move_rows(iids: list[str], to_index: int) -> None

Move the given rows to a target index in the root list.

move_columns

move_columns(from_index: int, to_index: int) -> None

Reorder a column from one index to another.

hide_rows

hide_rows(iids: list[str]) -> None

Hide rows from view (not removed from datasource).

unhide_rows

unhide_rows(iids: list[str] | None = None) -> None

Restore previously hidden rows.

hide_columns

hide_columns(indices: list[int]) -> None

Remove columns from the displayed set.

unhide_columns

unhide_columns(indices: list[int]) -> None

Add columns back into the displayed set.

select_rows

select_rows(iids: list[str]) -> None

Select the given row ids.

deselect_rows

deselect_rows(iids: list[str] | None = None) -> None

Clear selection or remove specific iids from selection.

scroll_to_row

scroll_to_row(iid: str) -> None

Ensure the given row is visible.

get_filters

get_filters() -> str

Return current SQL where clause string (if any).

get_sorting

get_sorting() -> dict[str, bool]

Return a copy of the current sort state {column_key: ascending}.

select_all

select_all() -> None

Select all visible rows.

deselect_all

deselect_all() -> None

Clear the selection.