Tableview#

Tableview is a data-table widget that ttkbootstrap ships (ttk.Tableview) — a themed Treeview wrapped with sorting, filtering, search, pagination, and CSV export, driven from column and row data. This page is the complete lookup reference.

Rows and columns are represented by TableRow and TableColumn objects, which the get_* / insert_* methods and the tablerows / tablecolumns properties return. Columns are addressed by integer index or by cid (the column id), rows by index or by iid (the row id).

Options#

All options are passed to the constructor.

Option

Type

Description

bootstyle

str

The accent color of headers, selection, and controls — one of primary, secondary, success, info, warning, danger, light, dark.

coldata

list

The columns, each a heading string or a dict of column settings (text, image, command, anchor, width, minwidth, stretch).

rowdata

list

The rows, each an iterable whose length matches the number of columns.

paginated

bool

Whether to page the data with a navigation bar below the table. Default False.

pagesize

int

Rows per page when paginated is true. Default 10.

searchable

bool

Whether to add a search bar above the table (press Return to search). Default False.

yscrollbar

bool

Whether to add a vertical scrollbar. Default False.

autofit

bool

Whether to size columns to their content on load. Default False.

autoalign

bool

Whether to align numeric columns right and others left, based on the first record. Default True.

stripecolor

tuple

A (background, foreground) pair used to stripe even rows; either may be None. Accepts color names, hex, or bootstyle keywords. Default None.

height

int

How many rows appear in the viewport. Default 10.

delimiter

str

The delimiter used when exporting to CSV. Default ",".

disable_right_click

bool

Whether to disable the built-in right-click menus. Default False.

on_select

callable

A callback invoked when the selection changes, receiving the list of selected TableRow objects. Default None.

iid_field

int | str

A column index or header name whose value becomes each row’s iid, instead of an auto-generated one. Default None.

Methods#

Loading data#

build_table_data(coldata, rowdata)

Replace all columns and rows with the given data.

Returns:

None.

load_table_data(clear_filters=False)

Render the current data into the table, optionally clearing filters first.

Returns:

None.

unload_table_data()

Remove all rendered rows from the view (the underlying data is retained).

Returns:

None.

purge_table_data()

Erase all table and column data.

Returns:

None.

fill_empty_columns(fillvalue='')

Pad short rows so every row has a value in every column.

Returns:

None.

Rows#

insert_row(index='end', values=[], reload=True)

Insert a row at index (or "end" to append).

Raises:

ValueError – if values is empty.

Returns:

the new row.

Return type:

TableRow

insert_rows(index, rowdata)

Insert each row of rowdata after index.

Returns:

None.

delete_row(index=None, iid=None, visible=True)

Delete a single row by index or iid.

Returns:

None.

delete_rows(indices=None, iids=None, visible=True)

Delete multiple rows by index or iid (all rows if none given).

Returns:

None.

get_row(index=None, visible=False, filtered=False, iid=None)

Return one row by index or iid.

Return type:

TableRow

get_rows(visible=False, filtered=False, selected=False)

Return rows — all, or only the visible / filtered / selected subset.

Return type:

list[TableRow]

move_selected_row_up()

Move the selected rows up one position in the data set.

Returns:

None.

move_selected_row_down()

Move the selected rows down one position in the data set.

Returns:

None.

move_selected_rows_to_top()

Move the selected rows to the top of the data set.

Returns:

None.

move_selected_rows_to_bottom()

Move the selected rows to the bottom of the data set.

Returns:

None.

hide_selected_rows()

Hide the currently selected rows.

Returns:

None.

Columns#

insert_column(index, text='', image='', command='', anchor='w', width=200, minwidth=20, stretch=False)

Insert a column at index.

Parameters:

anchor – cell alignment — one of "nw", "n", "ne", "w", "center", "e", "sw", "s", "se".

Returns:

the new column.

Return type:

TableColumn

delete_column(index=None, cid=None, visible=True)

Delete a single column by index or cid.

Returns:

None.

delete_columns(indices=None, cids=None, visible=True)

Delete multiple columns by index or cid (all columns if none given).

Returns:

None.

get_column(index=None, visible=False, cid=None)

Return one column by index or cid.

Return type:

TableColumn

move_column_left(cid=None)

Move a column one position to the left.

Returns:

None.

move_column_right(cid=None)

Move a column one position to the right.

Returns:

None.

move_column_to_first(cid=None)

Move a column to the leftmost position.

Returns:

None.

move_column_to_last(cid=None)

Move a column to the rightmost position.

Returns:

None.

hide_selected_column(cid=None)

Detach a column from the table (it can be restored with show_selected_column()).

Returns:

None.

show_selected_column(cid=None)

Re-attach a previously hidden column.

Returns:

None.

align_column_left(cid=None)

Left-align a column’s cell text. align_column_center and align_column_right are the other two.

Returns:

None.

align_heading_left(cid=None)

Left-align a column’s heading text. align_heading_center and align_heading_right are the other two.

Returns:

None.

autoalign_columns()

Align every column by its data type — numbers right, everything else left.

Returns:

None.

autofit_columns()

Size every visible column to fit its content.

Returns:

None.

Sorting#

sort_column_data(cid=None, sort=None)

Sort the rows by a column.

Parameters:

sort0 / None to sort ascending, 1 to sort descending.

Returns:

None.

reset_column_sort()

Restore the rows to their original insertion order.

Returns:

None.

Pagination#

goto_first_page()

Show the first page of data. goto_last_page, goto_next_page, and goto_prev_page navigate the others.

Returns:

None.

goto_page()

Show the page entered in the page-number box.

Returns:

None.

Export#

export_all_records()

Export every record to a CSV file (opens a save dialog). export_current_page, export_current_selection, and export_records_in_filter export the matching subset instead.

Returns:

None.

save_data_to_csv(headers, records, delimiter=',')

Write headers and records to a chosen CSV file.

Returns:

None.

Appearance#

apply_table_stripes(stripecolor)

Stripe even-numbered rows with a (background, foreground) pair; either may be None.

Returns:

None.

Properties#

tablecolumns

All columns, in order. tablecolumns_visible is the visible subset.

Type:

list[TableColumn]

tablerows

All rows. tablerows_visible and tablerows_filtered are the visible and filtered subsets.

Type:

list[TableRow]

cidmap

A mapping of cid to TableColumn. iidmap maps iid to TableRow.

Type:

dict

is_filtered

Whether a filter is currently active.

Type:

bool

pagesize

The number of records shown per page.

Type:

int

searchcriteria

The current search string.

Type:

str

Shared capabilities#

Tableview is a Frame subclass, so it also has the methods every widget inherits — configuration, placement, event binding, lifecycle, focus, and introspection. These are documented under Capabilities.

See also#