Comments in Document Editor Component
3 Mar 20231 minute to read
Document editor allows 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.
documentEditor.editor.insertComment("Test comment");
Comment navigation
Next and previous comments can be navigated using the below code snippet.
//Navigate to next comment
documentEditor.selection.navigateNextComment();
//Navigate to previous comment
documentEditor.selection.navigatePreviousComment();
Delete comment
Current comment can be deleted using the below code snippet.
documentEditor.editor.deleteComment();
Delete all comment
All the comments in the document can be deleted using the below code snippet.
documentEditor.editor.deleteAllComments();
Protect the document in comments only mode
Document Editor provides support for protecting the document with CommentsOnly
protection. In this protection, user is 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.
@Html.EJS().DocumentEditorContainer("container").Created("onCreated").EnableToolbar(true).Render()
<script>
var documenteditor;
var container;
function onCreated() {
var documenteditorElement = document.getElementById('container');
container = documenteditorElement.ej2_instances[0];
documenteditor = container.documentEditor;
container.documentEditor.editor.enforceProtection('123', 'CommentsOnly');
//stop the document protection
container.documentEditor.editor.stopProtection('123');
}
</script>
Comment only protection can be enabled in UI by using Restrict Editing pane
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.