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
[DT] Fix Issue #1280: Incorrect width when using percentage #1303
base: dev-master
Are you sure you want to change the base?
Changes from all commits
9a412f1
4e4209e
50bd12f
d50cc2a
dd397f4
582407a
26f65e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,6 +185,57 @@ Y.namespace('DataTable').TableView = Y.Base.create('table', Y.View, [], { | |
//-----------------------------------------------------------------------// | ||
// Protected and private methods | ||
//-----------------------------------------------------------------------// | ||
|
||
/** | ||
Constructor logic. | ||
|
||
@method intializer | ||
@param {Object} config Configuration object passed to the constructor | ||
@protected | ||
@since 3.6.0 | ||
**/ | ||
initializer: function (config) { | ||
this.host = config.host; | ||
|
||
this._initEvents(); | ||
|
||
this._extractDisplayColumns(); | ||
|
||
this.after('columnsChange', this._extractDisplayColumns, this); | ||
}, | ||
|
||
/** | ||
Cleans up state, destroys child views, etc. | ||
|
||
@method destructor | ||
@protected | ||
**/ | ||
destructor: function () { | ||
if (this.head && this.head.destroy) { | ||
this.head.destroy(); | ||
} | ||
delete this.head; | ||
|
||
if (this.foot && this.foot.destroy) { | ||
this.foot.destroy(); | ||
} | ||
delete this.foot; | ||
|
||
if (this.body && this.body.destroy) { | ||
this.body.destroy(); | ||
} | ||
delete this.body; | ||
|
||
if (this._eventHandles) { | ||
this._eventHandles.detach(); | ||
delete this._eventHandles; | ||
} | ||
|
||
if (this.tableNode) { | ||
this.tableNode.remove().destroy(true); | ||
} | ||
}, | ||
|
||
/** | ||
Updates the table's `summary` attribute. | ||
|
||
|
@@ -218,7 +269,7 @@ Y.namespace('DataTable').TableView = Y.Base.create('table', Y.View, [], { | |
@since 3.6.0 | ||
**/ | ||
_afterWidthChange: function (e) { | ||
this._uiSetWidth(e.newVal); | ||
this._uiSetWidth(e.newVal, { src: e.src }); | ||
}, | ||
|
||
/** | ||
|
@@ -322,7 +373,7 @@ Y.namespace('DataTable').TableView = Y.Base.create('table', Y.View, [], { | |
|
||
this._uiSetCaption(this.get('caption')); | ||
this._uiSetSummary(this.get('summary')); | ||
this._uiSetWidth(this.get('width')); | ||
this._uiSetWidth(this.get('width'), { src: e.src }); | ||
|
||
if (this.head || e.headerView) { | ||
if (!this.head) { | ||
|
@@ -357,38 +408,6 @@ Y.namespace('DataTable').TableView = Y.Base.create('table', Y.View, [], { | |
this._bindUI(); | ||
}, | ||
|
||
/** | ||
Cleans up state, destroys child views, etc. | ||
|
||
@method destructor | ||
@protected | ||
**/ | ||
destructor: function () { | ||
if (this.head && this.head.destroy) { | ||
this.head.destroy(); | ||
} | ||
delete this.head; | ||
|
||
if (this.foot && this.foot.destroy) { | ||
this.foot.destroy(); | ||
} | ||
delete this.foot; | ||
|
||
if (this.body && this.body.destroy) { | ||
this.body.destroy(); | ||
} | ||
delete this.body; | ||
|
||
if (this._eventHandles) { | ||
this._eventHandles.detach(); | ||
delete this._eventHandles; | ||
} | ||
|
||
if (this.tableNode) { | ||
this.tableNode.remove().destroy(true); | ||
} | ||
}, | ||
|
||
/** | ||
Processes the full column array, distilling the columns down to those that | ||
correspond to cell data columns. | ||
|
@@ -446,24 +465,6 @@ Y.namespace('DataTable').TableView = Y.Base.create('table', Y.View, [], { | |
}); | ||
}, | ||
|
||
/** | ||
Constructor logic. | ||
|
||
@method intializer | ||
@param {Object} config Configuration object passed to the constructor | ||
@protected | ||
@since 3.6.0 | ||
**/ | ||
initializer: function (config) { | ||
this.host = config.host; | ||
|
||
this._initEvents(); | ||
|
||
this._extractDisplayColumns(); | ||
|
||
this.after('columnsChange', this._extractDisplayColumns, this); | ||
}, | ||
|
||
/** | ||
Relays attribute changes to the child Views. | ||
|
||
|
@@ -497,12 +498,17 @@ Y.namespace('DataTable').TableView = Y.Base.create('table', Y.View, [], { | |
Creates the UI in the configured `container`. | ||
|
||
@method render | ||
@param {Object} options used to pass the renderer's source to the table | ||
@return {TableView} | ||
@chainable | ||
**/ | ||
render: function () { | ||
render: function (options) { | ||
options || (options = {}); | ||
|
||
if (this.get('container')) { | ||
this.fire('renderTable', { | ||
src: options.src || null, | ||
|
||
headerView : this.get('headerView'), | ||
headerConfig: this.get('headerConfig'), | ||
|
||
|
@@ -569,20 +575,33 @@ Y.namespace('DataTable').TableView = Y.Base.create('table', Y.View, [], { | |
|
||
@method _uiSetWidth | ||
@param {Number|String} width The width to make the table | ||
@param {Object} options Object used to pass the source of the width setter | ||
to update the table's width correctly | ||
@protected | ||
@since 3.5.0 | ||
**/ | ||
_uiSetWidth: function (width) { | ||
var table = this.tableNode; | ||
|
||
// Table width needs to account for borders | ||
table.setStyle('width', !width ? '' : | ||
(this.get('container').get('offsetWidth') - | ||
(parseInt(table.getComputedStyle('borderLeftWidth'), 10)||0) - | ||
(parseInt(table.getComputedStyle('borderLeftWidth'), 10)||0)) + | ||
'px'); | ||
|
||
table.setStyle('width', width); | ||
_uiSetWidth: function (width, options) { | ||
var table = this.tableNode, | ||
isPercentage = !!(width && width.toString().charAt(width.length - 1) === '%'); | ||
|
||
|
||
// need to determine if the table view is inside a table widget | ||
// if inside a widget, the table gets set to 100% width (contained by the table) | ||
// if not inside a widget, apply width directly to table view | ||
if (options && options.src === 'widget') { | ||
if (isPercentage) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't a 100% width rule be applied via css and overwritten in js only if necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A 100% width doesn't allow for a "natural" width There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. |
||
table.setStyle('width', '100%'); | ||
} else { | ||
// Table width needs to account for borders | ||
table.setStyle('width', !width ? '' : | ||
(this.get('container').get('offsetWidth') - | ||
(parseInt(table.getComputedStyle('borderLeftWidth'), 10)||0) - | ||
(parseInt(table.getComputedStyle('borderRightWidth'), 10)||0) | ||
) + 'px'); | ||
} | ||
} else { | ||
table.setStyle('width', width); | ||
} | ||
}, | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fork is to support the use of the table view standalone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. Using the existing tests with table view standalone, trying to get the fix to work for widget view required a fork and a passing of source.