Skip to content

Commit df9bbbc

Browse files
committed
add get_row_key to DataTable
1 parent 8d78427 commit df9bbbc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/textual/widgets/_data_table.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,22 @@ def get_row_index(self, row_key: RowKey | str) -> int:
10331033
raise RowDoesNotExist(f"No row exists for row_key={row_key!r}")
10341034
return self._row_locations.get(row_key)
10351035

1036+
def get_row_key(self, row_index: int) -> RowKey:
1037+
"""Return the current key for the row identified by row_index.
1038+
1039+
Args:
1040+
row_index: The index of the row.
1041+
1042+
Returns:
1043+
Thhe current key of the specified row index.
1044+
1045+
Raises:
1046+
RowDoesNotExist: If there is no row with the given index.
1047+
"""
1048+
if not self.is_valid_row_index(row_index):
1049+
raise RowDoesNotExist(f"Row index {row_index!r} is not valid.")
1050+
return self._row_locations.get_key(row_index)
1051+
10361052
def get_column(self, column_key: ColumnKey | str) -> Iterable[CellType]:
10371053
"""Get the values from the column identified by the given column key.
10381054

0 commit comments

Comments
 (0)