You can add the button to the menuConfig.items property when initializing the FeatureTable widget.
UPDATE: I read your problem wrong, this does the same thing as your code, but is a simpler way.
I think the issue is that you must have a row selected in the first screenshot and not selected in the second screenshot. The menu items that apply to selections only appear if you have a row selected.
// Create the feature table
const featureTable = new FeatureTable({
view: view,
layer: featureLayer,
visibleElements: {
menu: true,
// Autocast to VisibleElements
menuItems: {
clearSelection: true,
refreshData: true,
toggleColumns: true,
selectedRecordsShowAllToggle: true,
selectedRecordsShowSelectedToggle: true,
zoomToSelection: true
}
},
container: "tableDiv",
menuConfig: {
items: [
new ButtonMenuItem({
label: "Download Table",
clickFunction: function (event) {
setupCSV();
}
})
]
}
});