I am trying to implement a context menu for each of the node and each node needs to have seperate context menu items.
function contextMenuOpen(args) {
for (let item of args.items) {
if (
diagram.selectedItems.nodes.length &&
diagram.selectedItems.nodes[0].id === 'sdlc' &&
item.text !== 'Item-1'
) {
// Hide the other items in hidden items collection expect Item-1
args.hiddenItems.push(item.id);
} else if (
diagram.selectedItems.nodes.length &&
diagram.selectedItems.nodes[0].id === 'support' &&
item.text !== 'Item-2'
) {
args.hiddenItems.push(item.id);
} else if (
diagram.selectedItems.nodes.length &&
diagram.selectedItems.nodes[0].id === 'analysis' &&
item.text !== 'Item-3'
) {
args.hiddenItems.push(item.id);
}
}
} |
This helped. Thank you for your support
Can we add new items in the items list dynamically?
for eg:
contextMenuSettings: {
show: true,
items: [
{
text: 'Item-1',
id: 'item1',
target: '.e-diagramcontent',
},
{
text: 'Item-2',
id: 'item2',
target: '.e-diagramcontent',
},
{
text: 'Item-3',
id: 'item3',
target: '.e-diagramcontent',
},
],
showCustomMenuOnly: true,
},
Here, suppose i want to add
{
text: 'Item-4',
id: 'item-4',
}
I want to know if this is possible, and if yes then how?
function contextMenuOpen(args) {
for (let item of args.items) {
if (
diagram.selectedItems.nodes.length &&
diagram.selectedItems.nodes[0].id === 'sdlc' &&
item.text !== 'Item-1'
) {
args.hiddenItems.push(item.id);
} else if (
diagram.selectedItems.nodes.length &&
diagram.selectedItems.nodes[0].id === 'support' &&
item.text !== 'Item-2'
) {
args.hiddenItems.push(item.id);
} else if (
diagram.selectedItems.nodes.length &&
diagram.selectedItems.nodes[0].id === 'analysis' &&
item.text !== 'Item-3'
) {
args.hiddenItems.push(item.id);
} if (
diagram.selectedItems.nodes.length &&
diagram.selectedItems.nodes[0].id === 'analysis'
) {
args.hiddenItems.push("item4");
}
}
} |
Let's say the user switches from English to French.
If the items cannot be added/removed dynamicly, how do we go about updating the items with the proper locale?
thanks,
Jacques
Hi Aashutosh,
We should set the French culture initially and can update the context menu items dynamically by using contextMenuOpen event.
Code Snippet:
ej.base.setCulture('de');
function contextMenuOpen(args) { for (let item of args.items) { if ( diagram.selectedItems.nodes.length && diagram.selectedItems.nodes[0].id === 'sdlc' && item.text !== 'Objet-1' ) { args.hiddenItems.push(item.id); } else if ( diagram.selectedItems.nodes.length && diagram.selectedItems.nodes[0].id === 'support' && item.text !== 'Objet-2' ) { args.hiddenItems.push(item.id); } else if ( diagram.selectedItems.nodes.length && diagram.selectedItems.nodes[0].id === 'analysis' && item.text !== 'Objet-3' ) { args.hiddenItems.push(item.id); } } }
|
Sample : https://stackblitz.com/edit/npuzur-fun9ha?file=index.js |
Regards,
Balasubramanian