fix: get the column key from the columns attribute

This commit is contained in:
2025-11-25 12:24:25 +01:00
parent aa4a016a1a
commit 5c64ee3e37

View File

@@ -21,6 +21,7 @@ class AudituiApp(App):
def on_mount(self) -> None: def on_mount(self) -> None:
table = self.query_one(DataTable) table = self.query_one(DataTable)
table.add_columns("Title", "Author", "Length", "Progress") table.add_columns("Title", "Author", "Length", "Progress")
self.title_column_key = list(table.columns.keys())[0]
sample_books = [ sample_books = [
("The Great Gatsby", "F. Scott Fitzgerald", "4h 30m", "100%"), ("The Great Gatsby", "F. Scott Fitzgerald", "4h 30m", "100%"),
@@ -43,11 +44,11 @@ class AudituiApp(App):
def action_sort(self) -> None: def action_sort(self) -> None:
table = self.query_one(DataTable) table = self.query_one(DataTable)
table.sort("Title") table.sort(self.title_column_key)
def action_reverse_sort(self) -> None: def action_reverse_sort(self) -> None:
table = self.query_one(DataTable) table = self.query_one(DataTable)
table.sort("Title", reverse=True) table.sort(self.title_column_key, reverse=True)
if __name__ == "__main__": if __name__ == "__main__":