Data table
DataTable
¶
Bases: ScrollView
, Generic[CellType]
CellHighlighted
¶
Bases: Message
Emitted when the cursor moves to highlight a new cell.
It's only relevant when the cursor_type
is "cell"
.
It's also emitted when the cell cursor is re-enabled (by setting show_cursor=True
),
and when the cursor type is changed to "cell"
. Can be handled using
on_data_table_cell_highlighted
in a subclass of DataTable
or in a parent
widget in the DOM.
Attributes:
Name | Type | Description |
---|---|---|
value |
CellType
|
The value in the highlighted cell. |
coordinate |
Coordinate
|
The coordinate of the highlighted cell. |
CellSelected
¶
Bases: Message
Emitted by the DataTable
widget when a cell is selected.
It's only relevant when the cursor_type
is "cell"
. Can be handled using
on_data_table_cell_selected
in a subclass of DataTable
or in a parent
widget in the DOM.
Attributes:
Name | Type | Description |
---|---|---|
value |
CellType
|
The value in the cell that was selected. |
coordinate |
Coordinate
|
The coordinate of the cell that was selected. |
ColumnHighlighted
¶
Bases: Message
Emitted when a column is highlighted. This message is only emitted when the
cursor_type
is set to "column"
. Can be handled using
on_data_table_column_highlighted
in a subclass of DataTable
or in a parent
widget in the DOM.
Attributes:
Name | Type | Description |
---|---|---|
cursor_column |
int
|
The x-coordinate of the column that was highlighted. |
ColumnSelected
¶
Bases: Message
Emitted when a column is selected. This message is only emitted when the
cursor_type
is set to "column"
. Can be handled using
on_data_table_column_selected
in a subclass of DataTable
or in a parent
widget in the DOM.
Attributes:
Name | Type | Description |
---|---|---|
cursor_column |
int
|
The x-coordinate of the column that was selected. |
RowHighlighted
¶
Bases: Message
Emitted when a row is highlighted. This message is only emitted when the
cursor_type
is set to "row"
. Can be handled using on_data_table_row_highlighted
in a subclass of DataTable
or in a parent widget in the DOM.
Attributes:
Name | Type | Description |
---|---|---|
cursor_row |
int
|
The y-coordinate of the cursor that highlighted the row. |
RowSelected
¶
Bases: Message
Emitted when a row is selected. This message is only emitted when the
cursor_type
is set to "row"
. Can be handled using
on_data_table_row_selected
in a subclass of DataTable
or in a parent
widget in the DOM.
Attributes:
Name | Type | Description |
---|---|---|
cursor_row |
int
|
The y-coordinate of the cursor that made the selection. |
add_column(label, *, width=None)
¶
Add a column to the table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label |
TextType
|
A str or Text object containing the label (shown top of column). |
required |
width |
int | None
|
Width of the column in cells or None to fit content. Defaults to None. |
None
|
add_columns(*labels)
¶
Add a number of columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*labels |
TextType
|
Column headers. |
()
|
add_row(*cells, height=1)
¶
Add a row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*cells |
CellType
|
Positional arguments should contain cell data. |
()
|
height |
int
|
The height of a row (in lines). Defaults to 1. |
1
|
add_rows(rows)
¶
Add a number of rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rows |
Iterable[Iterable[CellType]]
|
Iterable of rows. A row is an iterable of cells. |
required |
clear(columns=False)
¶
Clear the table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
columns |
bool
|
Also clear the columns. Defaults to False. |
False
|
get_cell_value(coordinate)
¶
Get the value from the cell at the given coordinate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coordinate |
Coordinate
|
The coordinate to retrieve the value from. |
required |
Returns:
Type | Description |
---|---|
CellType
|
The value of the cell. |
Raises:
Type | Description |
---|---|
CellDoesNotExist
|
If there is no cell with the given coordinate. |
refresh_cell(row_index, column_index)
¶
Refresh a cell.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row_index |
int
|
Row index. |
required |
column_index |
int
|
Column index. |
required |
refresh_column(column_index)
¶
Refresh the column at the given index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column_index |
int
|
The index of the column to refresh. |
required |
refresh_row(row_index)
¶
Refresh the row at the given index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row_index |
int
|
The index of the row to refresh. |
required |