DataTable.add_row() doesn't work as expected, though add_rows() does.
See original GitHub issueThis script (simple_table.py
)
import sys
from textual.app import App, ComposeResult
from textual.widgets import DataTable
class TableApp(App):
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_columns('Col 1', 'Col 2')
rows = (
('v1', 'v2'),
('v3', 'v4')
)
if len(sys.argv) > 1:
table.add_rows(rows)
else:
table.add_row(rows[0])
table.add_row(rows[1])
if __name__ == "__main__":
app = TableApp()
app.run()
If invoked with no parameters it shows an empty table, even though two rows have been added using add_row()
. The orange cursor in the image below shows that the rows have been added - they just don’t display correctly.
However, if invoked with any argument (say foo
), the add_rows()
path is taken and the rows do display correctly in this case:
Using repo version of textual
, Linux Mint 64-bit (Cinnamon desktop).
Issue Analytics
- State:
- Created 9 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Datatable row.Add() not working.
Hi, this is a Quite tricky one, I am using DataTable with Dropdown in every row Now I want to add a new...
Read more >Datatables doesn't populate when I do row.add().draw()
PROBLEM. The problem with your code is in the order of code execution. Your table gets initialized in the ConfTable before it gets ......
Read more >easy way to add rows (& values!) to a data table
to add rows. As an argument, one can submit a list of the values - extremely elegant and useful for dirty coding :)....
Read more >"Add a row into table" in Power Automate is not working.
"Add a row into table" in Power Automate is not working. ... The flow works as expected but does not add any items...
Read more >Add Rows to DataTables in UiPath - YouTube
If you're interested in learning how to add rows and columns to a DataTable, this example will help you out immensely.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK, sorry for the noise. I didn’t read carefully enough 😞
add_row
takes the column values as positional parameters. So rather than like this:it would be more like this:
or even:
Edit to add: and/or what @rodrigogiraoserrao said 'cos he got in there as I was writing this. 😉