diff --git a/CHANGELOG.md b/CHANGELOG.md index 71f24e0c75..5eec759b8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added `DOMNode.displayed_children` https://github.com/Textualize/textual/pull/6070 - Added `TextArea.UserInsert` message https://github.com/Textualize/textual/pull/6070 - Added `TextArea.hide_suggestion_on_blur` boolean https://github.com/Textualize/textual/pull/6070 +- Added `DataTable.get_row_key` https://github.com/Textualize/textual/pull/6081 ### Changed diff --git a/src/textual/widgets/_data_table.py b/src/textual/widgets/_data_table.py index b78ce528a1..9c0af42601 100644 --- a/src/textual/widgets/_data_table.py +++ b/src/textual/widgets/_data_table.py @@ -1033,6 +1033,22 @@ def get_row_index(self, row_key: RowKey | str) -> int: raise RowDoesNotExist(f"No row exists for row_key={row_key!r}") return self._row_locations.get(row_key) + def get_row_key(self, row_index: int) -> RowKey: + """Return the current key for the row identified by row_index. + + Args: + row_index: The index of the row. + + Returns: + The current key of the specified row index. + + Raises: + RowDoesNotExist: If there is no row with the given index. + """ + if not self.is_valid_row_index(row_index): + raise RowDoesNotExist(f"Row index {row_index!r} is not valid.") + return self._row_locations.get_key(row_index) + def get_column(self, column_key: ColumnKey | str) -> Iterable[CellType]: """Get the values from the column identified by the given column key.