Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Unified Diff: ui/webui/resources/js/cr/ui/table/table_column_model.js

Issue 1006003004: Adding a visibility property to cr.ui.table.TableColumn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback. Fix resize jank. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d159fd50a94dfd77935f2c9f24197a1064c63825 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,16 @@ cr.define('cr.ui.table', function() {
if (index < 0 || index >= this.columns_.size - 1)
return;
+ var column = this.columns_[index];
width = Math.max(width, MIMIMAL_WIDTH);
- if (width == this.columns_[index].width)
+ if (width == column.absoluteWidth)
return;
- this.columns_[index].width = width;
- cr.dispatchSimpleEvent(this, 'resize');
+ column.width = width;
+
+ // Dispatch an event if a visible column was resized.
+ if (column.visible)
+ cr.dispatchSimpleEvent(this, 'resize');
},
/**
@@ -183,6 +187,35 @@ 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)
+ return;
+
+ var column = this.columns_[index];
+ if (column.visible == visible)
+ 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) {
+ return this.columns_[index].visible;
+ }
};
return {
« no previous file with comments | « ui/webui/resources/js/cr/ui/table/table_column.js ('k') | ui/webui/resources/js/cr/ui/table/table_header.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698