Skip to content

Commit

Permalink
Fixed #1261 - DataTable scrollHeight doesn't calculate correctly with…
Browse files Browse the repository at this point in the history
… frozen columns and header groups
  • Loading branch information
cagataycivici committed Mar 12, 2020
1 parent 8394afb commit a3cf76a
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/components/datatable/ScrollableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,32 @@ export class ScrollableView extends Component {

setScrollHeight() {
if(this.props.scrollHeight) {
if(this.props.scrollHeight.indexOf('%') !== -1) {
let datatableContainer = this.findDataTableContainer(this.container);
this.scrollBody.style.visibility = 'hidden';
this.scrollBody.style.height = '100px'; //temporary height to calculate static height
let containerHeight = DomHandler.getOuterHeight(datatableContainer);
let relativeHeight = DomHandler.getOuterHeight(datatableContainer.parentElement) * parseInt(this.props.scrollHeight, 10) / 100;
let staticHeight = containerHeight - 100; //total height of headers, footers, paginators
let scrollBodyHeight = (relativeHeight - staticHeight);

this.scrollBody.style.height = 'auto';
this.scrollBody.style.maxHeight = scrollBodyHeight + 'px';
this.scrollBody.style.visibility = 'visible';
let frozenView = this.container.previousElementSibling;
if(frozenView) {
let frozenScrollBody = DomHandler.findSingle(frozenView, '.p-datatable-scrollable-body');
this.scrollBody.style.maxHeight = frozenScrollBody.style.maxHeight;
}
else {
this.scrollBody.style.maxHeight = this.props.scrollHeight;
if(this.props.scrollHeight.indexOf('%') !== -1) {
let datatableContainer = this.findDataTableContainer(this.container);
this.scrollBody.style.visibility = 'hidden';
this.scrollBody.style.height = '100px'; //temporary height to calculate static height
let containerHeight = DomHandler.getOuterHeight(datatableContainer);
let relativeHeight = DomHandler.getOuterHeight(datatableContainer.parentElement) * parseInt(this.props.scrollHeight, 10) / 100;
let staticHeight = containerHeight - 100; //total height of headers, footers, paginators
let scrollBodyHeight = (relativeHeight - staticHeight);

if (this.props.frozen) {
scrollBodyHeight -= DomHandler.calculateScrollbarWidth();
}

this.scrollBody.style.height = 'auto';
this.scrollBody.style.maxHeight = scrollBodyHeight + 'px';
this.scrollBody.style.visibility = 'visible';
}
else {
this.scrollBody.style.maxHeight = this.props.scrollHeight;
}
}
}
}
Expand Down

0 comments on commit a3cf76a

Please sign in to comment.