99 isFunction ,
1010 isNumber ,
1111 scrollTo ,
12+ isEmptyValue ,
1213} from "../../src/utils/index.js" ;
1314import emitter from "../../src/mixins/emitter" ;
1415import {
@@ -22,7 +23,6 @@ import Header from "./header";
2223import Body from "./body" ;
2324import Footer from "./footer" ;
2425import { KEY_CODES } from "../../src/utils/constant" ;
25- import { isEmptyValue } from "../../src/utils/index" ;
2626import clickoutside from "../../src/directives/clickoutside" ;
2727import { mutations } from "./util/store" ;
2828import VueDomResizeObserver from "../../src/comps/resize-observer" ;
@@ -1052,6 +1052,47 @@ export default {
10521052 [ INSTANCE_METHODS . SCROLL_TO ] ( option ) {
10531053 scrollTo ( this . $refs [ this . tableContainerRef ] , option ) ;
10541054 } ,
1055+ // table scroll to rowKey
1056+ [ INSTANCE_METHODS . SCROLL_TO_ROW_KEY ] ( { rowKey } ) {
1057+ if ( isEmptyValue ( rowKey ) ) {
1058+ console . warn ( "Row key can't be empty!" ) ;
1059+ return false ;
1060+ }
1061+
1062+ let scrollTop = 0 ;
1063+
1064+ const { isVirtualScroll, headerRows } = this ;
1065+
1066+ const tableContainerRef = this . $refs [ this . tableContainerRef ] ;
1067+
1068+ if ( isVirtualScroll ) {
1069+ const position = this . virtualScrollPositions . find (
1070+ ( x ) => x . rowKey === rowKey ,
1071+ ) ;
1072+
1073+ if ( position ) {
1074+ scrollTop = position . top ;
1075+ }
1076+ } else {
1077+ const rowEl = this . $el . querySelector (
1078+ `tbody tr[${ COMPS_CUSTOM_ATTRS . BODY_ROW_KEY } ="${ rowKey } "]` ,
1079+ ) ;
1080+
1081+ const totalHeaderHeight = headerRows . reduce (
1082+ ( total , currentVal ) => {
1083+ return currentVal . rowHeight + total ;
1084+ } ,
1085+ 0 ,
1086+ ) ;
1087+
1088+ scrollTop = rowEl . offsetTop - totalHeaderHeight ;
1089+ }
1090+
1091+ scrollTo ( tableContainerRef , {
1092+ top : scrollTop ,
1093+ behavior : "smooth" ,
1094+ } ) ;
1095+ } ,
10551096 } ,
10561097 mounted ( ) {
10571098 // receive row selected change
0 commit comments