How to Customize Toolbar in JavaScript DOCX Editor
28 Aug 20262 minutes to read
How to customize existing toolbar in DocumentEditorContainer
JavaScript DOCX Editor (Document Editor) Container allows you to customize (add, show, hide, enable, and disable) existing items in a toolbar.
-
Add - New items can be defined by
CustomToolbarItemModeland with existing items intoolbarItemsproperty. Newly added item click action can be defined intoolbarClick. -
Show, Hide - Existing items can be shown or hidden using the
toolbarItemsproperty. Pre-defined toolbar items are available withToolbarItem. -
Enable, Disable - Toolbar items can be enabled or disabled using
enableItems
var toolItem = {
prefixIcon: "e-de-ctnr-lock",
tooltipText: "Disable Image",
text: onWrapText("Disable Image"),
id: "Custom"
};
//Initialize Document Editor Container component with custom toolbar item.
var container = new ej.documenteditor.DocumentEditorContainer({
toolbarItems: [toolItem, 'Undo', 'Redo', 'Separator', 'Image', 'Table', 'Hyperlink', 'Bookmark', 'TableOfContents', 'Separator', 'Header', 'Footer', 'PageSetup', 'PageNumber', 'Break', 'InsertFootnote', 'InsertEndnote', 'Separator', 'Find', 'Separator', 'Comments', 'TrackChanges', 'Separator', 'LocalClipboard', 'RestrictEditing', 'Separator', 'FormFields', 'UpdateFields','ContentControl']
});
container.appendTo('#container');
//To handle custom toolbar click event.
container.toolbarClick = function (args) {
switch (args.item.id) {
case 'Custom':
//Disable image toolbar item.
container.toolbar.enableItems(4, false);
break;
}
};
function onWrapText(text) {
var content = '';
var index = text.lastIndexOf(' ');
if (index !== -1) {
content = text.slice(0, index) + "<div class='e-de-text-wrap'>" + text.slice(index + 1) + "</div>";
} else {
content = text;
}
return content;
}NOTE
Default value of
toolbarItemsis['New', 'Open', 'Separator', 'Undo', 'Redo', 'Separator', 'Image', 'Table', 'Hyperlink', 'Bookmark', 'TableOfContents', 'Separator', 'Header', 'Footer', 'PageSetup', 'PageNumber', 'Break', 'InsertFootnote', 'InsertEndnote', 'Separator', 'Find', 'Separator', 'Comments', 'TrackChanges', 'Separator', 'LocalClipboard', 'RestrictEditing', 'Separator', 'FormFields', 'UpdateFields','ContentControl'].
Online demo
Explore how to customize the toolbar in the JavaScript (ES5) DOCX Editor for working with Word documents in this live demo here.