File tree Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -121,11 +121,16 @@ export type Props<CellType extends Types.CellBase> = {
121
121
) => void ;
122
122
} ;
123
123
124
+ export type Ref < CellType extends Types . CellBase > = {
125
+ getEntireData ( ) : Matrix . Matrix < CellType > ;
126
+ } ;
127
+
124
128
/**
125
129
* The Spreadsheet component
126
130
*/
127
131
const Spreadsheet = < CellType extends Types . CellBase > (
128
- props : Props < CellType >
132
+ props : Props < CellType > ,
133
+ ref : React . Ref < Ref < CellType > >
129
134
) : React . ReactElement => {
130
135
const {
131
136
className,
@@ -553,9 +558,21 @@ const Spreadsheet = <CellType extends Types.CellBase>(
553
558
]
554
559
) ;
555
560
561
+ React . useImperativeHandle (
562
+ ref ,
563
+ ( ) : Ref < CellType > => {
564
+ return {
565
+ getEntireData ( ) {
566
+ return state . model . data ;
567
+ } ,
568
+ } ;
569
+ } ,
570
+ [ state . model . data ]
571
+ ) ;
572
+
556
573
return (
557
574
< context . Provider value = { reducerElements } > { rootNode } </ context . Provider >
558
575
) ;
559
576
} ;
560
577
561
- export default Spreadsheet ;
578
+ export default React . forwardRef ( Spreadsheet ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import DataViewer from "./DataViewer";
4
4
5
5
export default Spreadsheet ;
6
6
export { Spreadsheet , DataEditor , DataViewer } ;
7
- export type { Props } from "./Spreadsheet" ;
7
+ export type { Props , Ref } from "./Spreadsheet" ;
8
8
export { createEmpty as createEmptyMatrix } from "./matrix" ;
9
9
export type { Matrix } from "./matrix" ;
10
10
export {
Original file line number Diff line number Diff line change 4
4
createEmptyMatrix ,
5
5
Spreadsheet ,
6
6
Props ,
7
+ Ref ,
7
8
CellBase ,
8
9
EntireWorksheetSelection ,
9
10
Selection ,
@@ -315,3 +316,21 @@ export const ControlledSelection: StoryFn<Props<StringCell>> = (props) => {
315
316
</ div >
316
317
) ;
317
318
} ;
319
+
320
+ export const GetEntireData : StoryFn < Props < StringCell > > = ( props ) => {
321
+ const ref = React . useRef < Ref < StringCell > > ( null ) ;
322
+
323
+ const getEntireData = React . useCallback ( ( ) => {
324
+ const data = ref . current ?. getEntireData ( ) ;
325
+ console . log ( "data" , data ) ;
326
+ } , [ ] ) ;
327
+
328
+ return (
329
+ < >
330
+ < div >
331
+ < button onClick = { getEntireData } > Get entire data</ button >
332
+ </ div >
333
+ < Spreadsheet ref = { ref } { ...props } />
334
+ </ >
335
+ ) ;
336
+ } ;
You can’t perform that action at this time.
0 commit comments