Hi guys,
It's good to see that there is namedItems
, similar to ExtJs actions
. The only difference between them is that actions are passed through parent to child items on every level, while in B is just on 1 level. So there are 2 solutions for this:
A. Use on child namedItems: 'up.namedItems',
so the 2 level child can re-use the configuration, see uncommented lines:
describe('Container namedItems', function () {
it('', () => {
new Container({
appendTo: document.body,
width: 800,
height: 500,
namedItems: {
removeRow : {
text : 'Remove row',
onItem() {
console.log('Remove row: onItem');
},
onClick() {
console.log('Remove row: onClick');
}
}
},
items: [
{
type: 'toolbar',
//namedItems: 'up.namedItems',
items: {
removeRow: true,
menuButton: {
type: 'button',
text: 'Menu',
menu: {
//namedItems: 'up.namedItems',
items: {
removeRow: true,
}
}
}
}
}
],
});
});
});
B. Do an override on Container:
import Container from '@bryntum/grid/source/lib/Core/widget/Container';
import Override from '@bryntum/grid/source/lib/Core/mixin/Override';
class ContainerOverride {
static get target() {
return {
class: Container,
};
}
// Override and import it in case there will be lots of namedItems: 'up.namedItems',
processItemsObject(items, namedItems, newItems) {
if (!namedItems) {
const parent = this.up((widget) => {
return !! widget.namedItems;
});
if (parent) {
namedItems = parent.namedItems;
}
}
this._overridden.processItemsObject.call(this, items, namedItems, newItems);
}
}
Override.apply(ContainerOverride);
Wondering if would make sense to add this feature by default in the toolkit. ? As a real world example would be that there's a Grid that has a toolbar and a context menu, and we need to share the configs for some buttons btween them, as example there's Edit button in both toolbar and context menu. And in combination with widget inheritance and abstraction this ends up well designed. For example in a child class (a grid) if we need to re-org a bit the buttons we just have 2 configs (now, in our current Ext App):
contextMenuItems: ['@addCM', '@addMultiple', '@edit', '@delete'],
toolbarItems: ['@add', '@addMultiple', '@edit', '@delete'],
And lastly wondering why there's no onClick
on menu item, or onAction
, so we don't declare for each namedItems both handlers....would be good to have at least for both widgets onAction
Thanks,
Vadim