Skip to content

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

Open
@alexveden

Description

@alexveden

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions