Chromium Code Reviews| Index: ui/webui/resources/js/cr/ui/table/table_column_model.js |
| diff --git a/ui/webui/resources/js/cr/ui/table/table_column_model.js b/ui/webui/resources/js/cr/ui/table/table_column_model.js |
| index da7803a0a13c810cfed967c7ad30cf2b9949afac..0369e9435d3cc5aa05a3ca68e7359fd3261c2269 100644 |
| --- a/ui/webui/resources/js/cr/ui/table/table_column_model.js |
| +++ b/ui/webui/resources/js/cr/ui/table/table_column_model.js |
| @@ -97,12 +97,18 @@ cr.define('cr.ui.table', function() { |
| if (index < 0 || index >= this.columns_.size - 1) |
| return; |
| + var column = this.columns_[index]; |
| + var widthProperty = column.visible ? 'width' : 'hiddenWidth'; |
| + |
| width = Math.max(width, MIMIMAL_WIDTH); |
| - if (width == this.columns_[index].width) |
| + if (width == column[widthProperty]) |
| return; |
| - this.columns_[index].width = width; |
| - cr.dispatchSimpleEvent(this, 'resize'); |
| + column[widthProperty] = width; |
| + |
| + // Dispatch an event if a visible column was resized. |
| + if (column.visible) |
| + cr.dispatchSimpleEvent(this, 'resize'); |
|
Dan Beam
2015/03/17 23:04:13
wouldn't we dispatch this even if a column is hidd
Ben Kwa
2015/03/18 02:48:11
If the column is hidden, resizing it does nothing
|
| }, |
| /** |
| @@ -183,6 +189,36 @@ cr.define('cr.ui.table', function() { |
| } |
| return -1; |
| }, |
| + |
| + /** |
| + * Show/hide a column. |
| + * @param {number} index The column index. |
| + * @param {boolean} visible The column visibility. |
| + */ |
| + setVisible: function(index, visible) { |
| + if (index < 0 || index > this.columns_.size - 1) |
|
Dan Beam
2015/03/17 23:04:13
should this be an assert?
Ben Kwa
2015/03/18 02:48:11
It could be. I was following the pattern in the r
|
| + return; |
| + |
| + var column = this.columns_[index]; |
| + if (column.visible === visible) { |
|
Dan Beam
2015/03/17 23:04:13
prefer ==
Dan Beam
2015/03/17 23:04:13
no curlies
Ben Kwa
2015/03/18 16:13:50
Done.
Ben Kwa
2015/03/18 16:13:50
Done.
|
| + return; |
| + } |
| + |
| + // Changing column visibility alters the width. Save the total width out |
| + // first, then change the column visibility, then relayout the table. |
| + var contentWidth = this.totalWidth; |
| + column.visible = visible; |
| + this.normalizeWidths(contentWidth); |
| + }, |
| + |
| + /** |
| + * Returns a column's visibility. |
| + * @param {number} index The column index. |
| + * @return {boolean} Whether the column is visible. |
| + */ |
| + isVisible: function(index) { |
|
Dan Beam
2015/03/17 23:04:13
assert(this.columns_[index]);
Ben Kwa
2015/03/18 02:48:11
This was me going with convention again - the othe
|
| + return this.columns_[index].visible; |
| + } |
| }; |
| return { |