Request new features or modifications


Post by scebotari66 »

Hello, team!

We have a grid cell menu, and we want to specify its items based on namedItems specified as a query string, to inherit the value from an ancestor widget, but it does not seem to work. It throws an error. As this works for other cases, we expect it to work in this case too.

Here is a test case with the problem:

new Panel({
	appendTo: document.body,
	title: 'Panel Title',
	height: 400,
	layout: 'fit',
	namedItems: {
		magicButton: {
			text: 'Magic Button',
		},
	},
	items: {
		grid: {
			type: 'grid',
			columns: [{ field: 'name', text: 'Name' }],
			features: {
				cellMenu: {
					namedItems: 'up.namedItems',
					items: {
						magicButton: true,
					},
				},
			},
			data: [
				{ id: 1, name: 'First' },
				{ id: 2, name: 'Second' },
				{ id: 3, name: 'Third' },
			],
		},
	},
});

Post by joakim.l »

Hi!

NamedItems is available on a Container or any subclass thereof. It is not available on a feature class, like CellMenu.
I suggest you look at implementing the https://bryntum.com/products/grid/docs/api/Grid/feature/CellMenu#config-processItems function would work.

Regards
Joakim


Post by scebotari66 »

Hi, Joakim!

As I see, the feature also has a "menu" config. Then specifying it on the menu directly should work? Now it does not

new Panel({
	appendTo: document.body,
	title: 'Panel Title',
	height: 400,
	layout: 'fit',
	namedItems: {
		magicButton: {
			text: 'Magic Button',
		},
	},
	items: {
		grid: {
			type: 'grid',
			columns: [{ field: 'name', text: 'Name' }],
			features: {
				cellMenu: {
					menu: {
						namedItems: 'up.namedItems',
						items: {
							magicButton: true,
						},
					},
				},
			},
			data: [
				{ id: 1, name: 'First' },
				{ id: 2, name: 'Second' },
				{ id: 3, name: 'Third' },
			],
		},
	},
});

Post by scebotari66 »

As a workaround, we have extracted a the config into a variable, and this way we can use it in cell menu:

const namedItems = {
	magicButton: {
		text: 'Magic Button',
	},
};

new Panel({
	appendTo: document.body,
	title: 'Panel Title',
	height: 400,
	layout: 'fit',
	items: {
		grid: {
			type: 'grid',
			columns: [{ field: 'name', text: 'Name' }],
			features: {
				cellMenu: {
					namedItems,
					items: {
						magicButton: true,
					},
				},
			},
			data: [
				{ id: 1, name: 'First' },
				{ id: 2, name: 'Second' },
				{ id: 3, name: 'Third' },
			],
		},
	},
});

Post by joakim.l »

Good you found a workaround!

I can see that there is some private handling of namedItems built-in to the CellMenu base class ContextMenuBase.
I'll make a ticket which includes making this public and also make sure that it works to use up.namedItems.

https://github.com/bryntum/support/issues/8303

Regards
Joakim


Post by scebotari66 »

Great to hear this. Thanks, Joakim!


Post by Animal »

It should work, and go up the hierarchy, but there's a bug: https://github.com/bryntum/support/issues/8304


Post by Animal »

This will be fixed in the next release. The test uses:

        new Panel({
            appendTo   : document.body,
            title      : 'Panel Title',
            height     : 400,
            layout     : 'fit',
            namedItems : {
                magicButton : {
                    text : 'Magic Button'
                }
            },
            items : {
                grid : {
                    type     : 'grid',
                    columns  : [{ field : 'name', text : 'Name' }],
                    features : {
                        cellMenu : {
                            menu : {
                                namedItems : 'up.namedItems',
                                items      : {
                                    magicButton : true
                                }
                            }
                        }
                    },
                    data : [
                        { id : 1, name : 'First' },
                        { id : 2, name : 'Second' },
                        { id : 3, name : 'Third' }
                    ]
                }
            }
        });

And the result is:

Screenshot 2024-01-19 at 13.50.37.png
Screenshot 2024-01-19 at 13.50.37.png (71.47 KiB) Viewed 3493 times

You can see that the named item is added to the default menu load provided by the Feature.

It can now inherit from Widgets all the way up the owner chain.


Post by scebotari66 »

Whoa, that was fast 🙂

Thanks, Animal!


Post Reply