Comments in EJ2 JavaScript Document editor control

22 Mar 20245 minutes to read

Document Editor allows you to add comments to documents. You can add, navigate and remove comments in code and from the UI.

Add a new comment

Comments can be inserted to the selected text.

//Add new commnt in the document.
documentEditor.editor.insertComment("Test comment");

Comment navigation

Next and previous comments can be navigated using the below code snippet.

//Navigate to next comment

//Navigate to previous comment

Delete comment

Current comment can be be deleted using the below code snippet.

//Delete the selected comment.

Delete all comment

All the comments in the document can be deleted using the below code snippet.

//Delete all the comments present in the current document.

Protect the document in comments only mode

Document Editor provides support for protecting the document with CommentsOnly protection. In this protection, user allowed to add or edit comments alone in the document.

Document editor provides an option to protect and unprotect document using enforceProtection and stopProtection API.

The following example code illustrates how to enforce and stop protection in Document editor container.

let container: DocumentEditorContainer = new DocumentEditorContainer({
  enableToolbar: true,
  height: '590px',
container.serviceUrl =

//enforce protection
container.documentEditor.editor.enforceProtection('123', 'CommentsOnly');

//stop the document protection

Comment only protection can be enabled in UI by using Restrict Editing pane

Enable comment only protection

Note: In enforce Protection method, first parameter denotes password and second parameter denotes protection type. Possible values of protection type are NoProtection |ReadOnly |FormFieldsOnly |CommentsOnly. In stop protection method, parameter denotes the password.

Mention Support in comments

Mention support displays a list of items that users can select or tag from the suggested list. To use this feature, type the @ character in the comment box and select or tag the user from the suggestion list.

The following example illustrates how to enable mention support in Document Editor

let mentionData: any = [
    { "Name": "Selma Rose", "Eimg": "3", "EmailId": "" },
    { "Name": "Russo Kay", "Eimg": "8", "EmailId": "" },
    { "Name": "Camden Kate", "Eimg": "9", "EmailId": "" },
    { "Name": "Mary Kate", "Eimg": "4", "EmailId": "" },
    { "Name": "Ursula Ann", "Eimg": "2", "EmailId": "" },
    { "Name": "Margaret", "Eimg": "5", "EmailId": "" },
    { "Name": "Laura Grace", "Eimg": "6", "EmailId": "" },
    { "Name": "Robert", "Eimg": "8", "EmailId": "" },
    { "Name": "Albert", "Eimg": "9", "EmailId": "" },
    { "Name": "Michale", "Eimg": "10", "EmailId": "" },
    { "Name": "Andrew James", "Eimg": "7", "EmailId": "" },
    { "Name": "Rosalie", "Eimg": "4", "EmailId": "" },
    { "Name": "Stella Ruth", "Eimg": "2", "EmailId": "" },
    { "Name": "Richard Rose", "Eimg": "10", "EmailId": "" },
    { "Name": "Gabrielle", "Eimg": "3", "EmailId": "" },
    { "Name": "Thomas", "Eimg": "7", "EmailId": "" },
    { "Name": "Charles Danny", "Eimg": "8", "EmailId": "" },
    { "Name": "Daniel", "Eimg": "10", "EmailId": "" },
    { "Name": "Matthew", "Eimg": "7", "EmailId": "" },
    { "Name": "Donald Krish", "Eimg": "9", "EmailId": "" },
    { "Name": "Yohana", "Eimg": "1", "EmailId": "" },
    { "Name": "Kevin Paul", "Eimg": "10", "EmailId": "" },
    { "Name": "Andrew Fuller", "Eimg": "3", "EmailId": ""}
let container: DocumentEditorContainer = new DocumentEditorContainer({ enableToolbar: true,height: '590px',
// Enable mention support in document editor
  documentEditorSettings: {
    mentionSettings: { dataSource: mentionData, fields: { text: 'Name' }},
container.serviceUrl = '';