Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable update_cell - text keys as given in add_columns() #1825

Open
alexveden opened this issue Feb 17, 2023 · 2 comments
Open

DataTable update_cell - text keys as given in add_columns() #1825

alexveden opened this issue Feb 17, 2023 · 2 comments

Comments

@alexveden
Copy link

It would be nice to be able to access table keys simply by column name (str), as passed in table.add_columns().

from textual.app import App
from textual.widgets import Header, Footer
from textual.widgets import DataTable


class TableTestApp(App):
    def compose(self):
        """Create child widgets for the app."""
        yield Header()
        yield DataTable(id='data_table')
        yield Footer()
    
    def on_mount(self):
        table: DataTable = self.query_one('#data_table', DataTable)
        table.cursor_type = 'row'
        keys = table.add_columns('Status', 'File', 'Log', 'Run')
        table.add_row('test', 'fn', 'log', 'run', key='test_key')
        
        # It's great to have this way of updates - via text column as key
        #table.update_cell('test_key', 'File', 'foo')
        
        # This works fine
        table.update_cell('test_key', keys[1], 'foo')


if __name__ == "__main__":
    #print("Hello world")
    app = TableTestApp()
    app.run()

To be added by @willmcgugan

@github-actions
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@TomJGooding
Copy link
Contributor

TomJGooding commented Sep 20, 2023

I found this open issue while looking into a possible bug with update_cell.

If I've understood this #3196 (comment) correctly, the column key actually should not be inferred from the label?

If that's the case, I think the docs should clarify that the key that "will be generated for you" has nothing to do with the column label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants