From 291e50b1425642136b2550750dae6adfbb2d4184 Mon Sep 17 00:00:00 2001 From: Neo Nie Date: Mon, 26 Feb 2018 11:26:44 +0800 Subject: [PATCH] add get size helpers --- docs/Grid.md | 8 ++++++++ source/Grid/Grid.jest.js | 16 ++++++++++++++++ source/Grid/Grid.js | 14 ++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/docs/Grid.md b/docs/Grid.md index 8c45fe7b3..cee274c07 100644 --- a/docs/Grid.md +++ b/docs/Grid.md @@ -49,6 +49,14 @@ A windowed grid of elements. `Grid` only renders cells necessary to fill itself Gets offsets for a given cell and alignment. +##### getTotalRowsHeight + +Gets estimated total rows' height. + +##### getTotalColumnsWidth + +Gets estimated total columns' width. + ##### handleScrollEvent ({ scrollLeft, scrollTop }) This method handles a scroll event originating from an external scroll control. diff --git a/source/Grid/Grid.jest.js b/source/Grid/Grid.jest.js index 845940d07..201f75db4 100644 --- a/source/Grid/Grid.jest.js +++ b/source/Grid/Grid.jest.js @@ -613,6 +613,22 @@ describe('Grid', () => { expect(scrollTop).toEqual(900); }); + it('should support getTotalRowsHeight() public method', () => { + const grid = render(getMarkup()); + grid.recomputeGridSize(); + const totalHeight = grid.getTotalRowsHeight(); + // 100 rows * 20 item height = 2,000 total item height + expect(totalHeight).toEqual(2000); + }); + + it('should support getTotalColumnsWidth() public method', () => { + const grid = render(getMarkup()); + grid.recomputeGridSize(); + const totalWidth = grid.getTotalColumnsWidth(); + // 50 columns * 50 item width = 2,500 total item width + expect(totalWidth).toEqual(2500); + }); + // See issue #565 it('should update scroll position to account for changed cell sizes within a function prop wrapper', () => { let rowHeight = 20; diff --git a/source/Grid/Grid.js b/source/Grid/Grid.js index 61e3d4aae..9d680f33f 100644 --- a/source/Grid/Grid.js +++ b/source/Grid/Grid.js @@ -386,6 +386,20 @@ class Grid extends React.PureComponent { }; } + /** + * Gets estimated total rows' height. + */ + getTotalRowsHeight() { + return this.state.instanceProps.rowSizeAndPositionManager.getTotalSize(); + } + + /** + * Gets estimated total columns' width. + */ + getTotalColumnsWidth() { + return this.state.instanceProps.columnSizeAndPositionManager.getTotalSize(); + } + /** * This method handles a scroll event originating from an external scroll control. * It's an advanced method and should probably not be used unless you're implementing a custom scroll-bar solution.