@@ -55,6 +55,7 @@ import type {
5555 FillEvent ,
5656 Maybe ,
5757 Position ,
58+ PositionByKey ,
5859 Renderers ,
5960 RowsChangeData ,
6061 SelectCellOptions ,
@@ -111,6 +112,7 @@ export interface DataGridHandle {
111112 element : HTMLDivElement | null ;
112113 scrollToCell : ( position : PartialPosition ) => void ;
113114 selectCell : ( position : Position , options ?: SelectCellOptions ) => void ;
115+ selectCellByKey : ( position : PositionByKey , options ?: SelectCellOptions ) => void ;
114116}
115117
116118type SharedDivProps = Pick <
@@ -547,7 +549,8 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
547549 setScrollToPosition ( { idx : scrollToIdx , rowIdx : scrollToRowIdx } ) ;
548550 }
549551 } ,
550- selectCell
552+ selectCell,
553+ selectCellByKey
551554 } )
552555 ) ;
553556
@@ -859,6 +862,14 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
859862 }
860863 }
861864
865+ function selectCellByKey ( position : PositionByKey , options ?: SelectCellOptions ) : void {
866+ const columnIdx = columns . findIndex ( ( col ) => col . key === position . columnKey ) ;
867+ if ( columnIdx === - 1 ) {
868+ throw new Error ( `Column with key "${ position . columnKey } " not found` ) ;
869+ }
870+ selectCell ( { idx : columnIdx , rowIdx : position . rowIdx } , options ) ;
871+ }
872+
862873 function selectHeaderCell ( { idx, rowIdx } : Position ) : void {
863874 selectCell ( { rowIdx : minRowIdx + rowIdx - 1 , idx } ) ;
864875 }
0 commit comments