question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataTable.add_row() doesn't work as expected, though add_rows() does.

See original GitHub issue

This 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.

ss2

However, if invoked with any argument (say foo), the add_rows() path is taken and the rows do display correctly in this case:

ss3

Using repo version of textual, Linux Mint 64-bit (Cinnamon desktop).

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vsajipcommented, Dec 15, 2022

OK, sorry for the noise. I didn’t read carefully enough 😞

1reaction
davepcommented, Dec 15, 2022

add_row takes the column values as positional parameters. So rather than like this:

row = [ 1,2,3 ]
table.add_row( row )

it would be more like this:

row = [ 1,2,3 ]
table.add_row( row[0], row[1], row[2])

or even:

row = [ 1,2,3 ]
table.add_row( *row )

Edit to add: and/or what @rodrigogiraoserrao said 'cos he got in there as I was writing this. 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found