Our blazing fast Grid component built with pure JavaScript


Post by henrique »

Hi!

I need some help with one situation. I'm creating a dynamic menu, with information from the backend of my application. But it is giving me an error that I replicated with the menu sample of the documentation.

I know the creation is out of a normal order but is the way the menu must be created. Any workaround will help!

const itemSubMenu = new MenuItem(
        {
            text : 'Sub menu',
        });

const subMenu = new Menu(
            {
                icon : 'b-fw-icon b-fa-play',
                text : 'Play'
            });

itemSubMenu.menu = subMenu;

const menu = new Menu({
    anchor   : true,
    autoShow : false,
    items    : [
        {
            icon : 'b-fw-icon b-icon-add',
            text : 'Add'
        },
        {
            icon : 'b-fw-icon b-icon-trash',
            text : 'Remove'
        },
        {
            icon     : 'b-fw-icon b-icon-lock',
            disabled : true,
            text     : 'I am disabled'
        },
		itemSubMenu
    ],
    // Method is called for all ancestor levels
    onItem({ item }) {
        Toast.show('You clicked ' + item.text);
    }
});

Post by Animal »

Why not just roll it all up into one big config object?

But anyway that should work.

"an error" doesn't really give us much chance to help.


Post by henrique »

I can create a big config file, because I need do save the MenuItem widget in a list, to relate this widget to another object that I have. But the error that gives in this sample, is because the changeMenu event, is trying to get an owner that's doesn't exists. If you execute the sample, you will get the error, just like me.

I found a way to escape the error. If you don't want to fix this problem, It's okey for me now.

Thanks for the reply.


Post by mats »

But it is giving me an error that I replicated with the menu sample of the documentation.

Can you please share some more details? What's the error message you get? And how do we reproduce?


Post by henrique »

This source I posted I applied to the live demo in the documentation of the menu https://www.bryntum.com/products/grid/docs/api/Core/widget/Menu.

Just paste there and the error will occur like the image bellow:

Screenshot_6.png
Screenshot_6.png (84.92 KiB) Viewed 410 times

Post by Animal »

Try it this way round:

const itemSubMenu = new MenuItem(
        {
            text : 'Sub menu',
        });

const subMenu = new Menu(
            {
                icon : 'b-fw-icon b-fa-play',
                text : 'Play'
            });

const menu = new Menu({
    anchor   : true,
    autoShow : false,
    items    : [
        {
            icon : 'b-fw-icon b-icon-add',
            text : 'Add'
        },
        {
            icon : 'b-fw-icon b-icon-trash',
            text : 'Remove'
        },
        {
            icon     : 'b-fw-icon b-icon-lock',
            disabled : true,
            text     : 'I am disabled'
        },
		itemSubMenu
    ],
    // Method is called for all ancestor levels
    onItem({ item }) {
        Toast.show('You clicked ' + item.text);
    }
});

itemSubMenu.menu = subMenu;

Post by Animal »

Even if its workaroundable, we should fix it: https://github.com/bryntum/support/issues/8371


Post Reply