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

Re-enable auto height change #72

Merged
merged 1 commit into from
Apr 6, 2016
Merged
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
37 changes: 29 additions & 8 deletions addon/components/justa-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,22 @@ export default Component.extend(InViewportMixin, {
@private
*/
_resizeTable() {
// TODO reenable with better height logic for tables without many rows
// let requestedHeight = this.get('tableHeight');
// let actualHeight = this.$('.table-columns table').outerHeight();
// let totalHeight = Math.min(requestedHeight, actualHeight);
let requestedHeight = this.get('tableHeight');
let actualHeight = this.$('.table-columns table').outerHeight();
let totalHeight = actualHeight === 0 ? requestedHeight : Math.min(requestedHeight, actualHeight);
let isWindows = this.get('isWindows');

if (isWindows) {
totalHeight = totalHeight + 16;
}

// this.$().height(totalHeight);
// this.$('.table-columns').height(totalHeight);
this.$().height(totalHeight);
// windows does not respect the height set, so it needs a 2px buffer
this.$('.table-columns').height(isWindows ? totalHeight + 2 : totalHeight);

run.next(() => {
this.set('containerSize', totalHeight);
});
},

/**
Expand Down Expand Up @@ -178,14 +187,26 @@ export default Component.extend(InViewportMixin, {
}
},

didReceiveAttrs() {
didReceiveAttrs(attrs) {
this._super(...arguments);
this.ensureEqualHeaderHeight();

if (this._didContentLengthChange(attrs)) {
this._resizeTable();
}
},

_didContentLengthChange(attrs) {
let oldLength = get(attrs, 'oldAttrs.content.value.length');
let newLength = get(attrs, 'newAttrs.content.value.length');

return oldLength && oldLength !== newLength;
},

didInsertElement() {
this._super(...arguments);
this._setupListeners();
this._resizeTable();
},

/**
Expand Down Expand Up @@ -304,7 +325,7 @@ export default Component.extend(InViewportMixin, {

if (isWindows && browser === 'chrome') {
let height = this.$().height() + Math.round(Math.random() * 10);
Ember.run.next(() => {
run.next(() => {
this.set('containerSize', height);
});
}
Expand Down