Skip to content

Commit

Permalink
JsonGrid fixes (#15346)
Browse files Browse the repository at this point in the history
* Fix JsonGrid

- Change the gridEditor record value of the currently edited field on keyup
- Don't use the context menu. This does not make sense with only one entry in that menu

* Fix a not displayed value change in the grid

* Remove the column menu for the grid and for the action columns.

* grunt build

Co-authored-by: Jason Coward <jason@opengeek.com>
  • Loading branch information
Jako and opengeek committed Feb 24, 2021
1 parent 2a8ca3c commit d615819
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manager/assets/modext/modx.jsgrps-min.js

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions manager/assets/modext/widgets/core/modx.grid.js
Expand Up @@ -117,6 +117,7 @@ MODx.grid.Grid = function(config) {

config.columns.push({
width: config.actionsColumnWidth || defaultActionsColumnWidth
,menuDisabled: true
,renderer: this.actionsColumnRenderer.bind(this)
});
}
Expand All @@ -130,6 +131,7 @@ MODx.grid.Grid = function(config) {

config.cm.columns.push({
width: config.actionsColumnWidth || defaultActionsColumnWidth
,menuDisabled: true
,renderer: this.actionsColumnRenderer.bind(this)
});
}
Expand Down Expand Up @@ -806,6 +808,7 @@ MODx.grid.LocalGrid = function(config) {
if (config.showActionsColumn && config.columns && Array.isArray(config.columns)) {
config.columns.push({
width: config.actionsColumnWidth || 50
,menuDisabled: true
,renderer: {
fn: this.actionsColumnRenderer,
scope: this
Expand Down Expand Up @@ -1526,14 +1529,27 @@ MODx.grid.JsonGrid = function (config) {
header: el.header || _(el.name),
dataIndex: el.name,
editable: true,
menuDisabled: true,
hidden: el.hidden || false,
editor: {
xtype: el.xtype || 'textfield',
allowBlank: el.allowBlank || true,
enableKeyEvents: true,
fieldname: el.name,
listeners: {
change: {
fn: this.saveValue,
scope: this
},
keyup: {
fn: function (sb) {
var record = this.getSelectionModel().getSelected();
if (record) {
record.set(sb.fieldname, sb.el.dom.value);
this.saveValue();
}
},
scope: this
}
}
},
Expand Down Expand Up @@ -1671,6 +1687,43 @@ Ext.extend(MODx.grid.JsonGrid, MODx.grid.LocalGrid, {
value.push(row);
}, this);
this.hiddenField.setValue(Ext.util.JSON.encode(value));
},
_getActionsColumnTpl: function () {
return new Ext.XTemplate('<tpl for=".">'
+ '<tpl if="actions !== null">'
+ '<ul class="x-grid-buttons">'
+ '<tpl for="actions">'
+ '<li><i class="x-grid-action icon icon-{icon:htmlEncode}" title="{text:htmlEncode}" data-action="{action:htmlEncode}"></i></li>'
+ '</tpl>'
+ '</ul>'
+ '</tpl>'
+ '</tpl>', {
compiled: true
});
},
actionsColumnRenderer: function (value, metaData, record, rowIndex, colIndex, store) {
return this._getActionsColumnTpl().apply({
actions: this.getActions()
});
},
onClick: function (e) {
var target = e.getTarget();
if (!target.classList.contains('x-grid-action')) return;
if (!target.dataset.action) return;

var actionHandler = 'action' + target.dataset.action.charAt(0).toUpperCase() + target.dataset.action.slice(1);
if (!this[actionHandler] || (typeof this[actionHandler] !== 'function')) {
actionHandler = target.dataset.action;
if (!this[actionHandler] || (typeof this[actionHandler] !== 'function')) {
return;
}
}

var record = this.getSelectionModel().getSelected();
var recordIndex = this.store.indexOf(record);
this.menu.record = record.data;

this[actionHandler](record, recordIndex, e);
}
});
Ext.reg('grid-json', MODx.grid.JsonGrid);
Expand Down

0 comments on commit d615819

Please sign in to comment.