Skip to content

Commit

Permalink
Refactor #1541 - For TreeTable
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Sep 10, 2020
1 parent 2548cd4 commit ff6247a
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions src/components/treetable/TreeTableScrollableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@ export class TreeTableScrollableView extends Component {

componentDidMount() {
this.setScrollHeight();

if(!this.props.frozen) {
this.alignScrollBar();

if (!this.props.frozen) {
let scrollBarWidth = DomHandler.calculateScrollbarWidth();

this.scrollHeaderBox.style.marginRight = scrollBarWidth + 'px';
if(this.scrollFooterBox) {
this.scrollFooterBox.style.marginRight = scrollBarWidth + 'px';
}
}
else {
this.scrollBody.style.paddingBottom = DomHandler.calculateScrollbarWidth() + 'px';
}
}

componentDidUpdate() {
if(!this.props.frozen) {
this.alignScrollBar();
}
}

setScrollHeight() {
if(this.props.scrollHeight) {
if(this.props.scrollHeight.indexOf('%') !== -1) {
Expand All @@ -58,7 +57,7 @@ export class TreeTableScrollableView extends Component {
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';
Expand All @@ -68,7 +67,7 @@ export class TreeTableScrollableView extends Component {
}
}
}

findDataTableContainer(element) {
if(element) {
let el = element;
Expand All @@ -93,30 +92,17 @@ export class TreeTableScrollableView extends Component {
if(frozenView) {
frozenScrollBody = DomHandler.findSingle(frozenView, '.p-treetable-scrollable-body');
}

this.scrollHeaderBox.style.marginLeft = -1 * this.scrollBody.scrollLeft + 'px';
if(this.scrollFooterBox) {
this.scrollFooterBox.style.marginLeft = -1 * this.scrollBody.scrollLeft + 'px';
}

if(frozenScrollBody) {
frozenScrollBody.scrollTop = this.scrollBody.scrollTop;
}
}

hasVerticalOverflow() {
return DomHandler.getOuterHeight(this.scrollTable) > DomHandler.getOuterHeight(this.scrollBody);
}

alignScrollBar() {
let scrollBarWidth = this.hasVerticalOverflow() ? DomHandler.calculateScrollbarWidth() : 0;

this.scrollHeaderBox.style.marginRight = scrollBarWidth + 'px';
if(this.scrollFooterBox) {
this.scrollFooterBox.style.marginRight = scrollBarWidth + 'px';
}
}

calculateRowHeight() {
let row = DomHandler.findSingle(this.scrollTable, 'tr:not(.p-treetable-emptymessage-row)');
if(row) {
Expand Down Expand Up @@ -170,4 +156,4 @@ export class TreeTableScrollableView extends Component {
</div>
);
}
}
}

0 comments on commit ff6247a

Please sign in to comment.