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 |
|---|---|---|
|
|
The accent color of headers, selection, and controls — one of
|
|
|
The columns, each a heading string or a dict of column settings
( |
|
|
The rows, each an iterable whose length matches the number of columns. |
|
|
Whether to page the data with a navigation bar below the table. Default
|
|
|
Rows per page when |
|
|
Whether to add a search bar above the table (press Return to search).
Default |
|
|
Whether to add a vertical scrollbar. Default |
|
|
Whether to size columns to their content on load. Default |
|
|
Whether to align numeric columns right and others left, based on the
first record. Default |
|
|
A |
|
|
How many rows appear in the viewport. Default |
|
|
The delimiter used when exporting to CSV. Default |
|
|
Whether to disable the built-in right-click menus. Default |
|
|
A callback invoked when the selection changes, receiving the list of
selected |
|
|
A column index or header name whose value becomes each row’s iid, instead
of an auto-generated one. Default |
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
valuesis empty.- Returns:
the new row.
- Return type:
TableRow
- insert_rows(index, rowdata)
Insert each row of
rowdataafterindex.- 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_centerandalign_column_rightare the other two.- Returns:
None.
- align_heading_left(cid=None)
Left-align a column’s heading text.
align_heading_centerandalign_heading_rightare 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:
sort –
0/Noneto sort ascending,1to sort descending.- Returns:
None.
- reset_column_sort()
Restore the rows to their original insertion order.
- Returns:
None.
Filtering and search#
- search_table_data(criteria, *columns)
Show only rows matching
criteria(case-insensitive), optionally limited to the given columns.- Returns:
None.
- filter_column_to_value(cid=None, value=None)
Show only rows whose value in a column equals
value.- Returns:
None.
- filter_to_selected_rows()
Show only the currently selected rows.
- Returns:
None.
- reset_row_filters()
Remove all row filters and unhide every row.
- Returns:
None.
- reset_column_filters()
Remove all column filters and unhide every column.
- Returns:
None.
- reset_table()
Remove every filter and column sort at once.
- Returns:
None.
Pagination#
- goto_first_page()
Show the first page of data.
goto_last_page,goto_next_page, andgoto_prev_pagenavigate 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, andexport_records_in_filterexport the matching subset instead.- Returns:
None.
- save_data_to_csv(headers, records, delimiter=',')
Write
headersandrecordsto a chosen CSV file.- Returns:
None.
Appearance#
- apply_table_stripes(stripecolor)
Stripe even-numbered rows with a
(background, foreground)pair; either may beNone.- Returns:
None.
Properties#
- tablecolumns
All columns, in order.
tablecolumns_visibleis the visible subset.- Type:
list[TableColumn]
- tablerows
All rows.
tablerows_visibleandtablerows_filteredare the visible and filtered subsets.- Type:
list[TableRow]
- cidmap
A mapping of cid to
TableColumn.iidmapmaps iid toTableRow.- Type:
- is_filtered
Whether a filter is currently active.
- Type:
- pagesize
The number of records shown per page.
- Type:
- searchcriteria
The current search string.
- Type:
See also#
Tableview catalog page — usage, screenshots, and examples.
Treeview — the native ttk tree/table widget it builds on.