DataTable
issues with adding new columns to a table that has existing data in it
#2826
-
Hello, I'm working on a project that displays DynamoDB table (a nosql db) data called dyno-viewer I encountered and issue where with a DataTable (in my case have created an widget that inherited the DataTable but i got the same issue with DataTable widget) and it wanted to add rows to the table that had existing rows but also needed to add new columns (which can happen when paginating though a DynamoDB table) it errors out when it tries to render the new table with a column key error. Here is an example app that showcases it: from textual.app import App, ComposeResult
from textual.widgets import DataTable
class DataTableAppFail(App):
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self):
table = self.query_one(DataTable)
table.add_columns(*["col1", "col2", "col3"])
table.add_rows([[1, 2, 3], [4, 5, 6]])
table.add_columns(*["col4", "col5"])
DataTableAppFail().run() when that runs give it gives this error
This looks like a bug but wanted to check if i was doing something wrong or if you have any suggestions Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I agree this looks like a bug. Perhaps If you clear the table and add back the same rows, it works as expected thanks to |
Beta Was this translation helpful? Give feedback.
I agree this looks like a bug. Perhaps
add_column
should update the table data if necessary to addNone
values?If you clear the table and add back the same rows, it works as expected thanks to
itertools.zip_longest
.