Hi Nicholas,
Greetings from Syncfusion support.
Yes, you can disable the context-menu items dynamically by using ‘enableItems’ method of contextmenu. Please find the code example for your reference.
@{
List<object> ContextMenuitems = new List<object>();
ContextMenuitems.Add(new { text = "Copy with headers", target= ".e-content", id = "copywithheader" });
ContextMenuitems.Add(new { text = "Edit Record", target= ".e-content", id = "edit" });
ContextMenuitems.Add(new { text = "Delete Record", target= ".e-content", id = "delete" });
}
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" contextMenuItems="ContextMenuitems" contextMenuOpen="contextMenuClick" >
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Left" width="125"></e-grid-column>
<e-grid-column field="EmployeeID" headerText="Employee ID" width="125" textAlign="Right" ></e-grid-column>
<e-grid-column field="ShipName" headerText="Ship Name" width="120"></e-grid-column>
<e-grid-column field="ShipCity" headerText="Ship City" width="170"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" textAlign="Right" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
function contextMenuOpen(args) {
if (args.rowInfo.rowData["OrderID"] %2 == 0) {
args.element.ej2_instances[0].enableItems(['openContact','Edit Record', 'Delete Record'], false) // you can disable context menu item by using ‘enableItems’ method of contextMenu. You need to pass contextMenu items and set as false.
}
}
</script>
Here, we have disabled the contextmenu items when OrderID column value %0 == 0.
Please get back to us if you have any queries.
Regards,
Ajith G