Select to view content in your preferred language

Add custom menu item to FeatureTable menu

1434
5
Jump to solution
04-22-2022 12:23 PM
SeanRedar
Regular Contributor

I can create the menu item but am stumped how I add the menu item to the FeatureTable's menu.  Any suggestions would be great.

0 Kudos
1 Solution

Accepted Solutions
AlejandroMari1
Frequent Contributor

This has worked for me on JS API 4.23:

const table = new FeatureTable({
    layer: myLayer,
    fieldConfigs: myFields,
    attachmentsEnabled: false,
    visibleElements: {
        selectionColumn: true,
        header: true,
        menu: true
    }
});

table.when().then(() => {
    const newMenuItem = {
        label: "Do something",
        clickFunction: (event) => {
            console.log("Clicked!");
        }
    };
    table.menu.items.push(newMenuItem);
});

View solution in original post

0 Kudos
5 Replies
AlejandroMari1
Frequent Contributor

This has worked for me on JS API 4.23:

const table = new FeatureTable({
    layer: myLayer,
    fieldConfigs: myFields,
    attachmentsEnabled: false,
    visibleElements: {
        selectionColumn: true,
        header: true,
        menu: true
    }
});

table.when().then(() => {
    const newMenuItem = {
        label: "Do something",
        clickFunction: (event) => {
            console.log("Clicked!");
        }
    };
    table.menu.items.push(newMenuItem);
});
0 Kudos
SeanRedar
Regular Contributor

Yes, thank you.  I think I was passing the wrong object to the menu.

0 Kudos
SeanRedar
Regular Contributor

Update - it worked inconsistently but doesn't seem to be working at all now.  

0 Kudos
KevinUseche
New Contributor

add visible property on object newMenuItem

 

                    table.when().then(() => {
                        const newMenuItem = {
                            label: "Do something",
                            iconClass: "Icon font name, if applicable",
                            visible: true,
                            clickFunction: (event) => {
                                console.log("Clicked!");
                            }
                        };
                        table.menu.items.push(newMenuItem);
                    });
0 Kudos
ChristineWiltawsky1
Occasional Contributor

The menu property is marked as readonly and should not be edited. You can use the property menuConfig instead. Here is an example which shows standard entries and a custom menu item in the Feature Tables's menu

featureTable.when().then(() => {
            const buttonMenuItem1 = new ButtonMenuItem ({
                    label: "custom menu item label",
                    clickFunction: function () {
                        console.log("click MenuItem1");
                    }
                });
                const buttonMenu = new ButtonMenu ({
                    iconClass: "esri-icon-handle-horizontal",
                    items: []
                });
                featureTable.menu.items.forEach(element => {
                    buttonMenu.items.push(element);
                });
                buttonMenu.items.push(buttonMenuItem1);
                featureTable.menuConfig = buttonMenu;
        });