I think I was trying to do something similar... this code may help...
I created a context menu, with the select handler of the menu doing the work (in my case inserting text).
I then created a custom toolbar item and added it to the DocumentContainer, and handled the toolbarClick event of the document editor to open the context menu below the icon.
@{
List<object> toolbarItems = new List<object>();
toolbarItems.AddRange(new List<object> { "Open", "Separator", "Table", "Image", "Separator", "PageNumber", "Break", "Separator", "Undo", "Redo", "Separator", "Find", "Separator" });
toolbarItems.Add(new { text = "Add Field", tooltipText = "Add a data field", id = "AddField", prefixIcon = "fas fa-puzzle-piece" });
}
<ejs-documenteditorcontainer id="DocumentEditor" enableToolbar="true" toolbarItems="toolbarItems" showPropertiesPane="true" serviceUrl="../">
</ejs-documenteditorcontainer>
<ejs-contextmenu id="contextmenu" items="ViewBag.documentFields" select="insertField" animationSettings="@new Syncfusion.EJ2.Navigations.ContextMenuAnimationSettings(){ Effect= Syncfusion.EJ2.Navigations.MenuEffect.SlideDown, Duration=1200 }"></ejs-contextmenu>
@section Scripts
{
<script>
var container;
var documenteditor;
var documenteditorElement
function resizeEditor() {
var newHeight = 0.85 * (window.innerHeight - documenteditorElement.getBoundingClientRect().top);
documenteditorElement.style.height = newHeight + "px";
}
function insertField(args) {
documenteditor.editor.insertText(args.item.id);
}
$(document).ready(function () {
documenteditorElement = document.getElementById("DocumentEditor");
container = documenteditorElement.ej2_instances[0];
documenteditor = container.documentEditor;
resizeEditor();
container.toolbarClick = function (args) {
switch (args.item.id) {
case 'AddField':
var contextMenuObj = ej.base.getInstance(document.getElementById('contextmenu'), ejs.navigations.ContextMenu)
var rect = document.getElementById("AddField").getBoundingClientRect();
contextMenuObj.open(rect.bottom, rect.left);
break;
}
};
});
</script>
<ejs-scripts></ejs-scripts>
}