[pve-devel] [PATCH manager v2] fix #759: save columns of resourceGrid

Dominik Csapak d.csapak at proxmox.com
Wed Apr 20 09:35:19 CEST 2016


with this patch, the resourceGrid saves its state when
the columns are changed (resized, sorted, etc.)

also add a little reset button to the toolbar

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
 * use a defaultSorter variable instead of
   using the same settings twice
 * use the defaultColums() function directly instead
   of writing into a variable
 www/css/ext6-pve.css              | 13 +++++++++++++
 www/manager6/grid/ResourceGrid.js | 38 ++++++++++++++++++++++++++++----------
 2 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/www/css/ext6-pve.css b/www/css/ext6-pve.css
index 4895623..cc75f75 100644
--- a/www/css/ext6-pve.css
+++ b/www/css/ext6-pve.css
@@ -345,3 +345,16 @@
 .x-form-display-field-default {
     min-height: 20px;
 }
+
+.x-button-reset:before {
+    font-size: 16px;
+}
+
+/* for resetcolumnsbutton */
+.x-button-reset:after{
+    content: "\f0e7 ";
+    position: relative;
+    text-shadow: 0 0 2px #fff;
+    left: -3px;
+    top: 2px;
+}
diff --git a/www/manager6/grid/ResourceGrid.js b/www/manager6/grid/ResourceGrid.js
index b97711f..560ae51 100644
--- a/www/manager6/grid/ResourceGrid.js
+++ b/www/manager6/grid/ResourceGrid.js
@@ -3,7 +3,14 @@ Ext.define('PVE.grid.ResourceGrid', {
     alias: ['widget.pveResourceGrid'],
 
     border: false,
-
+    saveCurrentState: function(){
+	var me = this;
+	me.saveState();
+    },
+    defaultSorter: {
+	property: 'type',
+	direction: 'ASC'
+    },
     initComponent : function() {
 	var me = this;
 
@@ -14,12 +21,7 @@ Ext.define('PVE.grid.ResourceGrid', {
 
 	var store = Ext.create('Ext.data.Store', {
 	    model: 'PVEResources',
-	    sorters: [
-		{
-		    property : 'type',
-		    direction: 'ASC'
-		}
-	    ],
+	    sorters: me.defaultSorter,
 	    proxy: { type: 'memory' }
 	});
 
@@ -149,7 +151,21 @@ Ext.define('PVE.grid.ResourceGrid', {
 
 	Ext.apply(me, {
 	    store: store,
+	    stateful: true,
+	    stateId: 'resourcegrid',
 	    tbar: [
+		{
+		    xtype: 'button',
+		    itemId: 'resetbutton',
+		    tooltip: gettext("Reset Columns"),
+		    iconCls: 'fa fa-fw fa-columns x-button-reset',
+		    handler: function(button, e, opts) {
+			var sp = Ext.state.Manager.getProvider();
+			me.getStore().sort(me.defaultSorter);
+			me.reconfigure(null, PVE.data.ResourceStore.defaultColums());
+			sp.clear(me.stateId);
+		    }
+		},
 		'->', 
 		gettext('Search') + ':', ' ',
 		{
@@ -206,13 +222,15 @@ Ext.define('PVE.grid.ResourceGrid', {
 		},
 		destroy: function() {
 		    rstore.un("load", load_cb);
-		}
+		},
+		columnschanged: 'saveCurrentState',
+		columnresize: 'saveCurrentState',
+		columnmove: 'saveCurrentState',
+		sortchange: 'saveCurrentState',
 	    },
             columns: coldef
 	});
-
 	me.callParent();
-
 	updateGrid();
 	rstore.on("load", load_cb);
     }
-- 
2.1.4





More information about the pve-devel mailing list