Skip to content

Commit

Permalink
Fixed #234
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Mar 16, 2020
1 parent 1c178dc commit b76a9c5
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/components/datatable/ScrollableView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ export default {
this.virtualScrollCallback();
this.virtualScrollCallback = null;
}
this.setScrollHeight();
},
watch: {
scrollHeight() {
this.setScrollHeight();
},
totalRecords(newValue) {
if (this.virtualScroll) {
this.$refs.virtualScroller.style.height = newValue * this.virtualRowHeight + 'px';
Expand Down Expand Up @@ -162,21 +161,28 @@ export default {
},
setScrollHeight() {
if (this.scrollHeight) {
if(this.scrollHeight.indexOf('%') !== -1) {
let datatableContainer = this.findDataTableContainer(this.$el);
this.$refs.scrollBody.style.visibility = 'hidden';
this.$refs.scrollBody.style.height = '100px'; //temporary height to calculate static height
let containerHeight = DomHandler.getOuterHeight(datatableContainer);
let relativeHeight = DomHandler.getOuterHeight(datatableContainer.parentElement) * parseInt(this.scrollHeight, 10) / 100;
let staticHeight = containerHeight - 100; //total height of headers, footers, paginators
let scrollBodyHeight = (relativeHeight - staticHeight);
this.$refs.scrollBody.style.height = 'auto';
this.$refs.scrollBody.style.maxHeight = scrollBodyHeight + 'px';
this.$refs.scrollBody.style.visibility = 'visible';
let frozenView = this.$el.previousElementSibling;
if (frozenView) {
let frozenScrollBody = DomHandler.findSingle(frozenView, '.p-datatable-scrollable-body');
this.$refs.scrollBody.style.maxHeight = frozenScrollBody.style.maxHeight;
}
else {
this.$refs.scrollBody.style.maxHeight = this.scrollHeight;
if(this.scrollHeight.indexOf('%') !== -1) {
let datatableContainer = this.findDataTableContainer(this.$el);
this.$refs.scrollBody.style.visibility = 'hidden';
this.$refs.scrollBody.style.height = '100px'; //temporary height to calculate static height
let containerHeight = DomHandler.getOuterHeight(datatableContainer);
let relativeHeight = DomHandler.getOuterHeight(datatableContainer.parentElement) * parseInt(this.scrollHeight, 10) / 100;
let staticHeight = containerHeight - 100; //total height of headers, footers, paginators
let scrollBodyHeight = (relativeHeight - staticHeight);
this.$refs.scrollBody.style.height = 'auto';
this.$refs.scrollBody.style.maxHeight = scrollBodyHeight + 'px';
this.$refs.scrollBody.style.visibility = 'visible';
}
else {
this.$refs.scrollBody.style.maxHeight = this.scrollHeight;
}
}
}
},
Expand Down

0 comments on commit b76a9c5

Please sign in to comment.