From c92dd68bab7246b4be74624e89a00627bd31198c Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 21 May 2021 16:39:23 +0200 Subject: [PATCH] object grid: allow one to declaratively specify rows So that users of this component do not necesacrrily need to add an initComponent override and make the `me.add_XYZ_row()` there, but instead can use something like: gridRows: [ { xtype: 'text', name: 'http-proxy', text: gettext('HTTP proxy'), defaultValue: Proxmox.Utils.noneText, vtype: 'HttpProxy', deleteEmpty: true, }, ], I avoid using `rows` as config key as that is internally used for quite a few things, and potentially some existing users (did not checked all). We can still switch to that easily if it is deemed to be better... Signed-off-by: Thomas Lamprecht --- src/grid/ObjectGrid.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/grid/ObjectGrid.js b/src/grid/ObjectGrid.js index 425d3c2..c323a6b 100644 --- a/src/grid/ObjectGrid.js +++ b/src/grid/ObjectGrid.js @@ -19,6 +19,11 @@ Useful for a readonly tabular display Ext.define('Proxmox.grid.ObjectGrid', { extend: 'Ext.grid.GridPanel', alias: ['widget.proxmoxObjectGrid'], + + // can be used as declarative replacement over manually calling the add_XYZ_row helpers, + // see top-level doc-comment above for details/example + gridRows: [], + disabled: false, hideHeaders: true, @@ -246,6 +251,17 @@ Ext.define('Proxmox.grid.ObjectGrid', { initComponent: function() { let me = this; + for (const rowdef of me.gridRows || []) { + let addFn = me[`add_${rowdef.xtype}_row`]; + if (typeof addFn !== 'function') { + throw `unknown object-grid row xtype '${rowdef.xtype}'`; + } else if (typeof rowdef.name !== 'string') { + throw `object-grid row need a valid name string-property!`; + } else { + addFn.call(me, rowdef.name, rowdef.text || rowdef.name, rowdef); + } + } + let rows = me.rows; if (!me.rstore) { -- 2.39.2