Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get size helpers #1022

Merged
merged 1 commit into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/Grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions source/Grid/Grid.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions source/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,20 @@ class Grid extends React.PureComponent<Props, State> {
};
}

/**
* 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.
Expand Down