1+ import Table , { type Reference } from 'rc-table' ;
12import React from 'react' ;
2- import Table from 'rc-table' ;
33import '../../assets/index.less' ;
44
55const data = [ ] ;
@@ -12,51 +12,63 @@ for (let i = 0; i < 10; i += 1) {
1212 } ) ;
1313}
1414
15- class Demo extends React . Component {
16- state = {
17- showBody : true ,
18- } ;
15+ const Test = ( ) => {
16+ const tblRef = React . useRef < Reference > ( ) ;
17+ const [ showBody , setShowBody ] = React . useState ( true ) ;
1918
20- toggleBody = ( ) => {
21- this . setState ( ( { showBody } ) => ( { showBody : ! showBody } ) ) ;
19+ const toggleBody = ( ) => {
20+ setShowBody ( ! showBody ) ;
2221 } ;
2322
24- render ( ) {
25- const { showBody } = this . state ;
26- const columns = [
27- { title : 'title1' , key : 'a' , dataIndex : 'a' , width : 100 } ,
28- { id : '123' , title : 'title2' , dataIndex : 'b' , key : 'b' , width : 100 } ,
29- { title : 'title3' , key : 'c' , dataIndex : 'c' , width : 200 } ,
30- {
31- title : (
32- < a onClick = { this . toggleBody } href = "#" >
33- { showBody ? '隐藏' : '显示' } 体
34- </ a >
35- ) ,
36- key : 'x' ,
37- width : 200 ,
38- render ( ) {
39- return < a href = "#" > Operations</ a > ;
40- } ,
23+ const columns = [
24+ { title : 'title1' , key : 'a' , dataIndex : 'a' , width : 100 } ,
25+ { id : '123' , title : 'title2' , dataIndex : 'b' , key : 'b' , width : 100 } ,
26+ { title : 'title3' , key : 'c' , dataIndex : 'c' , width : 200 } ,
27+ {
28+ title : (
29+ < a onClick = { toggleBody } href = "#" >
30+ { showBody ? '隐藏' : '显示' } 体
31+ </ a >
32+ ) ,
33+ key : 'x' ,
34+ width : 200 ,
35+ render ( ) {
36+ return < a href = "#" > Operations</ a > ;
4137 } ,
42- ] ;
43- return (
38+ } ,
39+ ] ;
40+
41+ return (
42+ < div >
43+ < h2 > scroll body table</ h2 >
44+ < button
45+ onClick = { ( ) => {
46+ tblRef . current ?. scrollTo ( {
47+ top : 9999 ,
48+ } ) ;
49+ } }
50+ >
51+ Scroll To End
52+ </ button >
53+ < button
54+ onClick = { ( ) => {
55+ tblRef . current ?. scrollTo ( {
56+ key : 9 ,
57+ } ) ;
58+ } }
59+ >
60+ Scroll To key 9
61+ </ button >
4462 < Table
63+ reference = { tblRef }
4564 columns = { columns }
4665 data = { data }
4766 scroll = { { y : 300 } }
4867 rowKey = { record => record . key }
49- onRow = { ( record , index ) => ( { style : { backgroundColor : " red" } } ) }
68+ onRow = { ( record , index ) => ( { style : { backgroundColor : ' red' } } ) }
5069 />
51- ) ;
52- }
53- }
54-
55- const Test = ( ) => (
56- < div >
57- < h2 > scroll body table</ h2 >
58- < Demo />
59- </ div >
60- ) ;
70+ </ div >
71+ ) ;
72+ } ;
6173
6274export default Test ;
0 commit comments