Track Changes in ASP.NET MVC DOCX Editor
14 Aug 20267 minutes to read
Track Changes allows you to keep a record of changes or edits made to a document. You can then choose to accept or reject the modifications. It is a useful tool for managing changes made by several reviewers to the same document. If the Track Changes option is enabled, all editing operations are preserved as revisions in the Document Editor.
Enable track changes in Document Editor
The following example demonstrates how to enable Track Changes.
@Html.EJS().DocumentEditorContainer("container").Created("onCreated").EnableToolbar(true).EnableTrackChanges(true).Render()public ActionResult Default()
{
return View();
}NOTE
Track changes are document-level settings. When opening a document, if the document does not have track changes enabled, then
enableTrackChangeswill be disabled even ifenableTrackChanges = trueis set during the initial rendering. If you want to enable track changes for all documents, then enable track changes during thedocumentChangeevent. The following example demonstrates how to enable Track Changes for all documents while opening.
<div>
@Html.EJS().DocumentEditorContainer("container").documentChange("onDocChange").EnableToolbar(true).Render()
</div>
<ejs-documenteditorcontainer id="container" documentChange="onDocumentChange" enableToolbar=true serviceUrl="/api/DocumentEditor/" height="590px"></ejs-documenteditorcontainer>
<script>
function onDocumentChange() {
var container = document.getElementById("container").ej2_instances[0];
if(container !== null){
container.documentEditor.enableTrackChanges= true;
}
}
</script>public ActionResult Default()
{
return View();
}Show/Hide revisions pane
The Show/Hide Revisions Pane feature in the Document Editor allows users to toggle the visibility of the revisions pane, providing flexibility in reviewing tracked changes in the document.
The following example code illustrates how to show/hide the revisions pane.
<div>
@Html.EJS().DocumentEditorContainer("container").Created("onCreated").EnableToolbar(true).EnableTrackChanges(true).Render()
</div>
<script>
var documenteditor;
var container;
var documenteditorElement = document.getElementById("container");
container = documenteditorElement.ej2_instances[0];
container.documentEditor.showRevisions = true; // To show revisions pane
container.documentEditor.showRevisions = false; // To hide revisions pane
</script>public ActionResult Default()
{
return View();
}Get all tracked revisions
The following example demonstrates how to get all tracked revisions from the current document.
/**
* Get revisions from the current document
*/
var revisions = container.documentEditor.revisions;Accept or reject all changes programmatically
The following example demonstrates how to accept or reject all changes.
/**
* Get revisions from the current document
*/
var revisions = container.documentEditor.revisions;
/**
* Accept all tracked changes
*/
revisions.acceptAll();
/**
* Reject all tracked changes
*/
revisions.rejectAll();Accept or reject a specific revision
The following example demonstrates how to accept or reject a specific revision in the Document Editor.
/**
* Get revisions from the current document
*/
var revisions = container.documentEditor.revisions;
/**
* Accept specific changes
*/
revisions.get(0).accept();
/**
* Reject specific changes
*/
revisions.get(1).reject();Navigate between the tracked changes
The following example demonstrates how to navigate tracked revisions programmatically.
/**
* Navigate to next tracked change from the current selection.
*/
container.documentEditor.selection.navigateNextRevision();
/**
* Navigate to previous tracked change from the current selection.
*/
container.documentEditor.selection.navigatePreviousRevision();Filtering changes based on user
The Document Editor has a built-in review panel that supports filtering changes by user.

Custom metadata along with author
The Document Editor provides a revisionSettings property to customize revisions. The customData property allows you to attach additional metadata to tracked revisions in the Word Processor. This metadata can represent roles, tags, or any custom identifier for the revision. To display this metadata along with the author name in the Track Changes pane, you must enable the showCustomDataWithAuthor property.
The following example code illustrates how to enable and update custom metadata for track changes revisions.
@Html.EJS().DocumentEditorContainer("container").EnableTrackChanges(true).DocumentEditorSettings("settings").Render()
<script>
var settings = { revisionSettings: { customData: 'Developer', showCustomDataWithAuthor: true} };
</script>public ActionResult Default()
{
return View();
}The Track Changes pane will display the author name along with the custom metadata, as shown in the screenshot below.

NOTE
When you export the document as SFDT, the
customDatavalue is stored in the revision collection. When you reopen the SFDT, the custom data is restored automatically and displayed in the Track Changes pane. Other than SFDT export (e.g., DOCX and others), thecustomDatais not preserved, as it is specific to the Document Editor component.
Protect the document in track changes only mode
The Document Editor provides support for protecting the document with RevisionsOnly protection. In this protection, all users can view the document and make corrections, but they cannot accept or reject any tracked changes in the document. Later, the author can view their corrections and accept or reject the changes.
The Document Editor provides options to protect and unprotect a document using the enforceProtection and stopProtection APIs.
The following example code illustrates how to enforce and stop protection in the Document Editor container.
@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', 'RevisionsOnly');
//stop the document protection
container.documentEditor.editor.stopProtection('123');
}
</script>public ActionResult Default()
{
return View();
}Tracked changes only protection can be enabled in UI by using Restrict Editing pane

NOTE
In the
enforceProtectionmethod, the first parameter denotes the password and the second parameter denotes the protection type. Possible values of the protection type areNoProtection | ReadOnly | FormFieldsOnly | CommentsOnly | RevisionsOnly. In thestopProtectionmethod, the parameter denotes the password.Online demo
Explore how to track and review changes in Word documents using the ASP.NET MVC Document Editor in this live demo.