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.
Solved! Go to Solution.
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);
});
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);
});
Yes, thank you. I think I was passing the wrong object to the menu.
Update - it worked inconsistently but doesn't seem to be working at all now.
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);
});
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;
});