From 9f1498ded368bbcf22db24ad3f17658bcf76b3cb Mon Sep 17 00:00:00 2001 From: pdudhat Date: Mon, 19 Jul 2021 02:29:47 -0400 Subject: [PATCH] feat(virtualizedRenderer): allow to pass content grid ref as property allow to call grid methods by passing content gridref as vritualizedRenderer props --- .../virtualized/virtualized.stories.js | 40 ++++++++++++++++++- src/virtualized/virtualizedRenderer.js | 5 ++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/stories/virtualized/virtualized.stories.js b/src/stories/virtualized/virtualized.stories.js index b7e45e7..80f431a 100644 --- a/src/stories/virtualized/virtualized.stories.js +++ b/src/stories/virtualized/virtualized.stories.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useRef, useState } from 'react' import { storiesOf } from '@storybook/react' import R from 'ramda' import Grid, { @@ -59,6 +59,43 @@ export const dateInputCellEditRender = ({ getInputProps }) => ( ) +const GridWithScrollTrigger = () => { + const [rowNo, setRowNo] = useState() + const gridRef = useRef() + return ( +
+
+ setRowNo(e.target.value)} /> + +
+ { + const type = props.gridToolProps.headers[props.reactVirtualizedProps.columnIndex].type + return defaultVirtualizedCellRender({ + ...props, + editRender: (type === 'date-time' || type === 'date') && dateInputCellEditRender, + }) + }, + contentGridRef: gridRef, + })} + editMode="cell" + isEditable={() => true} + /> +
+ ) +} + const data = createData(200) storiesOf('Virtualized grid', module) .add('Basic', () => ( @@ -94,3 +131,4 @@ storiesOf('Virtualized grid', module) /> )) + .add('Scroll Trigger', () => ) diff --git a/src/virtualized/virtualizedRenderer.js b/src/virtualized/virtualizedRenderer.js index b15cf2b..f61b244 100644 --- a/src/virtualized/virtualizedRenderer.js +++ b/src/virtualized/virtualizedRenderer.js @@ -48,7 +48,7 @@ const handleSelectionScroll = ({ contentGrid, x2, y2, previousPosition, fixedHea // // const VirtualizedRender = ({ renderOptions = {}, gridRenderProps }) => { - const contentGridRef = useRef() + const internalContentGridRef = useRef() const rowHeaderGridRef = useRef() const columnHeaderGridRef = useRef() const positionRef = useRef() @@ -74,6 +74,7 @@ const VirtualizedRender = ({ renderOptions = {}, gridRenderProps }) => { autoFixColByKey, cellRender = defaultCellRender, rowHeaderRender = defaultRowHeaderRender, + contentGridRef: externalContentGridRef, // colHeaderRenderer, // pagerRenderer = defaultPagerRenderer, // editByRow = true, @@ -81,6 +82,8 @@ const VirtualizedRender = ({ renderOptions = {}, gridRenderProps }) => { // fixedScrollHeightAdjustment = 6, } = renderOptions + const contentGridRef = externalContentGridRef || internalContentGridRef + const { scrollY, scrollX,