Skip to content

Commit

Permalink
Fixed primefaces#2456 - When scrollable and virtual Scroller are enab…
Browse files Browse the repository at this point in the history
…led at the same time, the scroll style is incorrect when the scrollHeight is changed
  • Loading branch information
mertsincan committed Nov 21, 2021
1 parent b00fa14 commit 8461882
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/datatable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ export class DataTable extends Component {

return (
<div className="p-datatable-wrapper" style={{ maxHeight: isVirtualScrollerDisabled ? this.props.scrollHeight : '' }}>
<VirtualScroller {...virtualScrollerOptions} items={processedData} columns={columns} style={{ height: this.props.scrollHeight }}
<VirtualScroller {...virtualScrollerOptions} items={processedData} columns={columns} scrollHeight={this.props.scrollHeight}
disabled={isVirtualScrollerDisabled} loaderDisabled showSpacer={false}
contentTemplate={(options) => {
const ref = (el) => { this.table = el; options.spacerRef && options.spacerRef(el) };
Expand Down
7 changes: 6 additions & 1 deletion src/components/virtualscroller/VirtualScroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ export class VirtualScroller extends Component {
return [];
}

isPropChanged(prevProps) {
const props = ['itemSize', 'scrollHeight'];
return props.some((p) => !ObjectUtils.equals(prevProps[p], this.props[p]));
}

init() {
this.setSize();
this.calculateOptions();
Expand All @@ -524,7 +529,7 @@ export class VirtualScroller extends Component {
}

componentDidUpdate(prevProps, prevState) {
if (!ObjectUtils.equals(prevProps.itemSize, this.props.itemSize) || (!prevProps.items || prevProps.items.length !== (this.props.items || []).length)) {
if ((!prevProps.items || prevProps.items.length !== (this.props.items || []).length) || this.isPropChanged(prevProps)) {
this.init();
}

Expand Down

0 comments on commit 8461882

Please sign in to comment.