This section describes methods that control the HTML Editor UI component.
Postpones rendering that can negatively affect performance until the endUpdate() method is called.
The beginUpdate() and endUpdate() methods reduce the number of renders in cases where extra rendering can negatively affect performance.
See AlsoRemoves focus from the content field of the editor.
Resets the value property to the default value.
Clears the history of changes.
Specifies the device-dependent default configuration properties for this component.
Parameters:The component's default device properties.
Object structure:
Name Type Description device |Device parameters.
When you specify a function, get information about the current device from the argument. Return true if the properties should be applied to the device.
Options to be applied.
defaultOptions is a static method that the UI component class supports. The following code demonstrates how to specify default properties for all instances of the HtmlEditor UI component in an application executed on the desktop.
jQueryDevExpress.ui.dxHtmlEditor.defaultOptions({ device: { deviceType: "desktop" }, options: { // Here go the HtmlEditor properties } });Angular
import HtmlEditor, { Properties } from "devextreme/ui/html_editor"; // ... export class AppComponent { constructor () { HtmlEditor.defaultOptions<Properties>({ device: { deviceType: "desktop" }, options: { // Here go the HtmlEditor properties } }); } }Vue
<template> <div> <DxHtmlEditor id="htmlEditor1" /> <DxHtmlEditor id="htmlEditor2" /> </div> </template> <script> import DxHtmlEditor from "devextreme-vue/html-editor"; import HtmlEditor from "devextreme/ui/html_editor"; HtmlEditor.defaultOptions({ device: { deviceType: "desktop" }, options: { // Here go the HtmlEditor properties } }); export default { components: { DxHtmlEditor } } </script>React
import dxHtmlEditor from "devextreme/ui/html_editor"; import HtmlEditor from "devextreme-react/html-editor"; dxHtmlEditor.defaultOptions({ device: { deviceType: "desktop" }, options: { // Here go the HtmlEditor properties } }); export default function App() { return ( <div> <HtmlEditor id="htmlEditor1" /> <HtmlEditor id="htmlEditor2" /> </div> ) }
You can also set rules for multiple device types:
jQueryconst devicesConfig = [ { deviceType: 'desktop' }, { deviceType: 'tablet' }, { deviceType: 'phone' }, ]; devicesConfig.forEach(deviceConfig => { DevExpress.ui.dxHtmlEditor.defaultOptions({ device: deviceConfig, options: { // Here go the HtmlEditor properties } }); });Angular
import HtmlEditor, { Properties } from "devextreme/ui/html_editor"; // ... export class AppComponent { constructor () { const devicesConfig = [ { deviceType: 'desktop' }, { deviceType: 'tablet' }, { deviceType: 'phone' }, ]; devicesConfig.forEach(deviceConfig => { HtmlEditor.defaultOptions<Properties>({ device: deviceConfig, options: { // Here go the HtmlEditor properties } }); }); } }Vue
<template> <div> <DxHtmlEditor /> </div> </template> <script> import DxHtmlEditor from "devextreme-vue/html-editor"; import HtmlEditor from "devextreme/ui/html_editor"; const devicesConfig = [ { deviceType: 'desktop' }, { deviceType: 'tablet' }, { deviceType: 'phone' }, ]; devicesConfig.forEach(deviceConfig => { HtmlEditor.defaultOptions({ device: deviceConfig, options: { // Here go the HtmlEditor properties } }); }); export default { components: { DxHtmlEditor } } </script>React
import dxHtmlEditor from "devextreme/ui/html_editor"; import HtmlEditor from "devextreme-react/html-editor"; const devicesConfig = [ { deviceType: 'desktop' }, { deviceType: 'tablet' }, { deviceType: 'phone' }, ]; devicesConfig.forEach(deviceConfig => { dxHtmlEditor.defaultOptions({ device: deviceConfig, options: { // Here go the HtmlEditor properties } }); }); export default function App() { return ( <div> <HtmlEditor /> </div> ) }
Deletes content from the given range.
Parameters:A zero-based index at which to begin deleting.
The length of the content to be deleted.
Embedded items have a length of 1.
Disposes of all the resources allocated to the HtmlEditor instance.
jQueryAfter calling this method, remove the DOM element associated with the UI component:
$("#myHtmlEditor").dxHtmlEditor("dispose"); $("#myHtmlEditor").remove();Angular
Use conditional rendering instead of this method:
<dx-html-editor ... *ngIf="condition"> </dx-html-editor>Vue
Use conditional rendering instead of this method:
<template> <DxHtmlEditor ... v-if="condition"> </DxHtmlEditor> </template> <script> import DxHtmlEditor from 'devextreme-vue/html-editor'; export default { components: { DxHtmlEditor } } </script>React
Use conditional rendering instead of this method:
import React from 'react'; import HtmlEditor from 'devextreme-react/html-editor'; function DxHtmlEditor(props) { if (!props.shouldRender) { return null; } return ( <HtmlEditor ... > </HtmlEditor> ); } class App extends React.Component { render() { return ( <DxHtmlEditor shouldRender="condition" /> ); } } export default App;
Gets the root UI component element.
Refreshes the UI component after a call of the beginUpdate() method.
The beginUpdate() and endUpdate() methods reduce the number of renders in cases where extra rendering can negatively affect performance.
See AlsoSets focus on the content field of the editor.
Applies a format to the selected content. Cannot be used with embedded formats.
Parameters:A format name.
formatValue: any
A format value.
Pass null to remove a format.
If no content is selected, the format applies to the character typed next.
jQueryconst htmlEditorInstance = $("#htmlEditorContainer").dxHtmlEditor("instance"); // Makes text bold htmlEditorInstance.format("bold", true); // Inserts a link htmlEditorInstance.format("link", { href: "https://www.google.com/", text: "Google", title: "Go to Google" });Angular
import { ..., ViewChild } from "@angular/core"; import { DxHtmlEditorModule, DxHtmlEditorComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxHtmlEditorComponent, { static: false }) htmlEditor: DxHtmlEditorComponent; // Prior to Angular 8 // @ViewChild(DxHtmlEditorComponent) htmlEditor: DxHtmlEditorComponent; makeTextBold() { this.htmlEditor.instance.format("bold", true); } insertGoogleLink(){ this.htmlEditor.instance.format("link", { href: "https://www.google.com/", text: "Google", title: "Go to Google" }); } } @NgModule({ imports: [ // ... DxHtmlEditorModule ], // ... })Vue
<template> <DxHtmlEditor :ref="htmlEditorRefKey"> <!-- ... --> </DxHtmlEditor> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxHtmlEditor from 'devextreme-vue/html-editor'; const htmlEditorRefKey = "my-html-editor"; export default { components: { DxHtmlEditor }, data() { return { htmlEditorRefKey } }, methods: { makeTextBold() { this.htmlEditor.format("bold", true); }, insertGoogleLink() { this.htmlEditor.format("link", { href: "https://www.google.com/", text: "Google", title: "Go to Google" }); } }, computed: { htmlEditor: function() { return this.$refs[htmlEditorRefKey].instance; } } } </script>React
import { useRef } from 'react'; import 'devextreme/dist/css/dx.light.css'; import HtmlEditor from 'devextreme-react/html-editor'; export default function App() { const htmlEditor = useRef(null); const makeTextBold = () => { htmlEditor.current.instance().format("bold", true); }; const insertGoogleLink = () => { htmlEditor.current.instance().format("link", { href: "https://www.google.com/", text: "Google", title: "Go to Google" }); }; return ( <HtmlEditor ref={htmlEditor}> {/* */} </HtmlEditor> ); }See Also
Applies a single block format to all lines in the given range.
Parameters:A zero-based index at which to begin formatting.
The length of the content to be formatted.
Embedded items have a length of 1.
A format name.
formatValue: any
A format value.
Pass null to remove a format.
The entire line will be formatted even if only a single character from it falls within the given range.
jQuery// Aligns the first line to the right $("#htmlEditorContainer").dxHtmlEditor("instance").formatLine(0, 1, "align", "right");Angular
import { ..., ViewChild } from "@angular/core"; import { DxHtmlEditorModule, DxHtmlEditorComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxHtmlEditorComponent, { static: false }) htmlEditor: DxHtmlEditorComponent; // Prior to Angular 8 // @ViewChild(DxHtmlEditorComponent) htmlEditor: DxHtmlEditorComponent; alignFirstLineToRight() { this.htmlEditor.instance.formatLine(0, 1, "align", "right"); } } @NgModule({ imports: [ // ... DxHtmlEditorModule ], // ... })Vue
<template> <DxHtmlEditor :ref="htmlEditorRefKey"> <!-- ... --> </DxHtmlEditor> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxHtmlEditor from 'devextreme-vue/html-editor'; const htmlEditorRefKey = "my-html-editor"; export default { components: { DxHtmlEditor }, data() { return { htmlEditorRefKey } }, methods: { alignFirstLineToRight() { this.htmlEditor.formatLine(0, 1, "align", "right"); } }, computed: { htmlEditor: function() { return this.$refs[htmlEditorRefKey].instance; } } } </script>React
import { useRef } from 'react'; import 'devextreme/dist/css/dx.light.css'; import HtmlEditor from 'devextreme-react/html-editor'; export default function App() { const htmlEditor = useRef(null); const alignFirstLineToRight = () => { htmlEditor.current.instance().formatLine(0, 1, "align", "right"); }; return ( <HtmlEditor ref={htmlEditor}> {/* */} </HtmlEditor> ); }See Also
Applies several block formats to all lines in the given range.
Parameters:A zero-based index at which to begin formatting.
The length of the content to be formatted.
Embedded items have a length of 1.
Formats to be applied.
This object should have the following structure: { "formatName1": "formatValue1", ... }
Pass null to remove all formats.
The entire line will be formatted even if only a single character from it falls within the given range.
jQuery// Aligns the first line to the right and turns it into an ordered list's item. $("#htmlEditorContainer").dxHtmlEditor("instance").formatLine(0, 1, { "align": "right", "list": "ordered" });Angular
import { ..., ViewChild } from "@angular/core"; import { DxHtmlEditorModule, DxHtmlEditorComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxHtmlEditorComponent, { static: false }) htmlEditor: DxHtmlEditorComponent; // Prior to Angular 8 // @ViewChild(DxHtmlEditorComponent) htmlEditor: DxHtmlEditorComponent; applyLineFormats() { // Aligns the first line to the right and turns it into an ordered list's item. this.htmlEditor.instance.formatLine(0, 1, { "align": "right", "list": "ordered" }); } } @NgModule({ imports: [ // ... DxHtmlEditorModule ], // ... })Vue
<template> <DxHtmlEditor :ref="htmlEditorRefKey"> <!-- ... --> </DxHtmlEditor> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxHtmlEditor from 'devextreme-vue/html-editor'; const htmlEditorRefKey = "my-html-editor"; export default { components: { DxHtmlEditor }, data() { return { htmlEditorRefKey } }, methods: { applyLineFormats() { this.htmlEditor.formatLine(0, 1, { "align": "right", "list": "ordered" }); } }, computed: { htmlEditor: function() { return this.$refs[htmlEditorRefKey].instance; } } } </script>React
import { useRef } from 'react'; import 'devextreme/dist/css/dx.light.css'; import HtmlEditor from 'devextreme-react/html-editor'; export default function App() { const htmlEditor = useRef(null); const applyLineFormats = () => { htmlEditor.current.instance().formatLine(0, 1, { "align": "right", "list": "ordered" }); }; return ( <HtmlEditor ref={htmlEditor}> {/* */} </HtmlEditor> ); }See Also
Applies a single text format to all characters in the given range.
Parameters:A zero-based index at which to begin formatting.
The length of the content to be formatted.
Embedded items have a length of 1.
A format name.
formatValue: any
A format value.
Pass null to remove a format.
// Makes the first five characters bold $("#htmlEditorContainer").dxHtmlEditor("instance").formatText(0, 5, "bold", true);Angular
import { ..., ViewChild } from "@angular/core"; import { DxHtmlEditorModule, DxHtmlEditorComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxHtmlEditorComponent, { static: false }) htmlEditor: DxHtmlEditorComponent; // Prior to Angular 8 // @ViewChild(DxHtmlEditorComponent) htmlEditor: DxHtmlEditorComponent; makeTextBold() { // Makes the first five characters bold this.htmlEditor.instance.formatText(0, 5, "bold", true); } } @NgModule({ imports: [ // ... DxHtmlEditorModule ], // ... })Vue
<template> <DxHtmlEditor :ref="htmlEditorRefKey"> <!-- ... --> </DxHtmlEditor> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxHtmlEditor from 'devextreme-vue/html-editor'; const htmlEditorRefKey = "my-html-editor"; export default { components: { DxHtmlEditor }, data() { return { htmlEditorRefKey } }, methods: { makeTextBold() { // Makes the first five characters bold this.htmlEditor.formatText(0, 5, "bold", true); } }, computed: { htmlEditor: function() { return this.$refs[htmlEditorRefKey].instance; } } } </script>React
import { useRef } from 'react'; import 'devextreme/dist/css/dx.light.css'; import HtmlEditor from 'devextreme-react/html-editor'; export default function App() { const htmlEditor = useRef(null); const makeTextBold = () => { // Makes the first five characters bold htmlEditor.current.instance().formatText(0, 5, "bold", true); }; return ( <HtmlEditor ref={htmlEditor}> {/* */} </HtmlEditor> ); }See Also
Applies several text formats to all characters in the given range.
Parameters:A zero-based index at which to begin formatting.
The length of the content to be formatted.
Embedded items have a length of 1.
Formats to be applied.
This object should have the following structure: { "formatName1": "formatValue1", ... }
Pass null to remove all formats.
// Makes the first five characters bold and underlined $("#htmlEditorContainer").dxHtmlEditor("instance").formatText(0, 5, { "bold": "true", "underline": "true" });Angular
import { ..., ViewChild } from "@angular/core"; import { DxHtmlEditorModule, DxHtmlEditorComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxHtmlEditorComponent, { static: false }) htmlEditor: DxHtmlEditorComponent; // Prior to Angular 8 // @ViewChild(DxHtmlEditorComponent) htmlEditor: DxHtmlEditorComponent; applyLineFormats() { // Makes the first five characters bold and underlined this.htmlEditor.instance.formatText(0, 5, { "bold": "true", "underline": "true" }); } } @NgModule({ imports: [ // ... DxHtmlEditorModule ], // ... })Vue
<template> <DxHtmlEditor :ref="htmlEditorRefKey"> <!-- ... --> </DxHtmlEditor> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxHtmlEditor from 'devextreme-vue/html-editor'; const htmlEditorRefKey = "my-html-editor"; export default { components: { DxHtmlEditor }, data() { return { htmlEditorRefKey } }, methods: { applyLineFormats() { // Makes the first five characters bold and underlined this.htmlEditor.formatText(0, 5, { "bold": "true", "underline": "true" }); } }, computed: { htmlEditor: function() { return this.$refs[htmlEditorRefKey].instance; } } } </script>React
import { useRef } from 'react'; import 'devextreme/dist/css/dx.light.css'; import HtmlEditor from 'devextreme-react/html-editor'; export default function App() { const htmlEditor = useRef(null); const applyLineFormats = () => { // Makes the first five characters bold and underlined htmlEditor.current.instance().formatText(0, 5, { "bold": "true", "underline": "true" }); }; return ( <HtmlEditor ref={htmlEditor}> {/* */} </HtmlEditor> ); }See Also
Gets a format, module, or Parchment.
Parameters:A path to a format ("formats/[formatName]"), module ("modules/[moduleName]"), or Parchment ("parchment").
A format, module, or Parchment content.
You can perform the following tasks after getting a format, module, or Parchment:
Modify the format
You can change the markup tag associated with the format and allowed format values, as shown in the code example after this list.
Extend the format or module
You can extend HTML Editor's formats and modules, and also the DevExtreme Quill's formats and modules. See the Extend Built-In Formats and Modules topic for the code example.
Create a custom format based on the Parchment
Refer to the Parchment documentation for more information.
In the following code, the bold
format is associated with the <b>
tag instead of the default <strong>
tag. After the modification, the format is registered.
$(function() { // ... const htmlEditor = $("#htmlEditorContainer").dxHtmlEditor("instance"); const Bold = htmlEditor.get("formats/bold"); Bold.tagName = "b"; htmlEditor.register({ "formats/bold": Bold }); });Angular
<dx-html-editor ... > </dx-html-editor>
import { Component, ViewChild, AfterViewInit } from '@angular/core'; import { DxHtmlEditorComponent } from 'devextreme-angular'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { @ViewChild(DxHtmlEditorComponent, { static: false }) htmlEditor: DxHtmlEditorComponent; // Prior to Angular 8 // @ViewChild(DxHtmlEditorComponent) htmlEditor: DxHtmlEditorComponent; ngAfterViewInit() { let htmlEditor = this.htmlEditor.instance; let Bold = htmlEditor.get("formats/bold"); Bold.tagName = "b"; htmlEditor.register({ "formats/bold": Bold }); } }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxHtmlEditorModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxHtmlEditorModule ], providers: [ ], bootstrap: [AppComponent] }) export class AppModule { }Vue
<template> <DxHtmlEditor ... :ref="htmlEditorRefName"> </DxHtmlEditor> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxHtmlEditor from 'devextreme-vue/html-editor'; const htmlEditorRefName = "myHtmlEditor"; export default { components: { DxHtmlEditor }, data() { return { htmlEditorRefName } }, computed: { htmlEditor: function() { return this.$refs[htmlEditorRefName].instance; } }, mounted: function() { this.$nextTick(function() { let Bold = this.htmlEditor.get("formats/bold"); Bold.tagName = "b"; this.htmlEditor.register({ "formats/bold": Bold }); }) } } </script>React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import HtmlEditor from 'devextreme-react/html-editor'; class App extends React.Component { constructor(props) { super(props); this.htmlEditorRef = React.createRef(); } get htmlEditor() { return this.htmlEditorRef.current.instance(); } render() { return ( <HtmlEditor ... ref={this.htmlEditorRef}> </HtmlEditor> ); } componentDidMount() { let Bold = this.htmlEditor.get("formats/bold"); Bold.tagName = "b"; this.htmlEditor.register({ "formats/bold": Bold }); } } export default App;See Also
Retrieves the pixel position and size of a selection at a specified location.
Parameters:A zero-based index at which position retrieval begins.
The length of the selection for which the position is retrieved.
An object that contains the following fields: left, top, height, width.
Retrieves formatting of the text within the current selection range.
An object that contains applied formats.
It has the following structure:{ "formatName1": "formatValue1", ... }
Gets formats applied to the content in the specified range.
Parameters:A zero-based index indicating the range's start.
The range's length.
Embedded items have a length of 1.
An object that contains applied formats.
It has the following structure:{ "formatName1": "formatValue1", ... }
Gets the instance of a UI component found using its DOM node.
Parameters:The UI component's container.
The UI component's instance.
getInstance is a static method that the UI component class supports. The following code demonstrates how to get the HtmlEditor instance found in an element with the myHtmlEditor
ID:
// Modular approach import HtmlEditor from "devextreme/ui/html_editor"; ... let element = document.getElementById("myHtmlEditor"); let instance = HtmlEditor.getInstance(element) as HtmlEditor; // Non-modular approach let element = document.getElementById("myHtmlEditor"); let instance = DevExpress.ui.dxHtmlEditor.getInstance(element);See Also
Gets the entire content's length.
Embedded items have a length of 1.
Even if the HTML Editor is empty, this method returns 1, because the UI component always contains an empty line ("\n").
Gets the instance of a module.
You can get DevExtreme Quill modules, DevExtreme UI modules, or custom modules.
If you implement the customizeModules function, make sure that it does not disable the modules that you want to get.
Gets the selected content's position and length.
Parameters:Pass true to focus the content field before getting the selected range. Otherwise, the method returns null if the content field doesn't have focus.
The selected content's range. It has the following structure:
For example, the following code snippet inserts text into the editor at the the cursor's location:
const newPosition = editor.getSelection(true); editor.insertText(newPosition.index, "text");
Retrieves text content from the HTML Editor.
Parameters:A zero-based index at which the retrieved text starts.
The number of characters to retrieve.
The retrieved text content.
This method skips mentions and variables. To get them, use the QuillJS getContents() method:
const quill = htmlEditorInstance.getQuillInstance(); quill.getContents().forEach((contentItem) => { if (contentItem.insert.variable) { // is a variable // Your configuration goes here } else if (contentItem.insert.mention) { // is a mention // Your configuration goes here } else { // is a plain text // Your configuration goes here } });
Inserts an embedded content at the specified position.
Parameters:A zero-based index at which to insert an embedded content.
An embedded format's name.
config: any
An embedded format's value.
jQuery// Adds an image at the beginning of the content $("#htmlEditorContainer").dxHtmlEditor("instance").insertEmbed(0, "extendedImage", { src: "https://js.devexpress.com/Content/images/doc/25_1/PhoneJS/person1.png", alt: "Photo", width: "100px" });Angular
import { ..., ViewChild } from "@angular/core"; import { DxHtmlEditorModule, DxHtmlEditorComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxHtmlEditorComponent, { static: false }) htmlEditor: DxHtmlEditorComponent; // Prior to Angular 8 // @ViewChild(DxHtmlEditorComponent) htmlEditor: DxHtmlEditorComponent; insertImageAtTheBeginning() { this.htmlEditor.instance.insertEmbed(0, "extendedImage", { src: "https://js.devexpress.com/Content/images/doc/25_1/PhoneJS/person1.png", alt: "Photo", width: "100px" }); } } @NgModule({ imports: [ // ... DxHtmlEditorModule ], // ... })Vue
<template> <DxHtmlEditor :ref="htmlEditorRefKey"> <!-- ... --> </DxHtmlEditor> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxHtmlEditor from 'devextreme-vue/html-editor'; const htmlEditorRefKey = "my-html-editor"; export default { components: { DxHtmlEditor }, data() { return { htmlEditorRefKey } }, methods: { insertImageAtTheBeginning() { // Makes the first five characters bold and underlined this.htmlEditor.insertEmbed(0, "extendedImage", { src: "https://js.devexpress.com/Content/images/doc/25_1/PhoneJS/person1.png", alt: "Photo", width: "100px" }); } }, computed: { htmlEditor: function() { return this.$refs[htmlEditorRefKey].instance; } } } </script>React
import { useRef } from 'react'; import 'devextreme/dist/css/dx.light.css'; import HtmlEditor from 'devextreme-react/html-editor'; export default function App() { const htmlEditor = useRef(null); const insertImageAtTheBeginning = () => { // Makes the first five characters bold and underlined htmlEditor.current.instance().insertEmbed(0, "extendedImage", { src: "https://js.devexpress.com/Content/images/doc/25_1/PhoneJS/person1.png", alt: "Photo", width: "100px" }); }; return ( <HtmlEditor ref={htmlEditor}> {/* */} </HtmlEditor> ); }
Inserts text into the HTML Editor.
Parameters:A zero-based index at which the text is inserted.
The text to be inserted.
The format name.
formatValue: any
The format value.
Inserts formatted text at the specified position. Used with all formats except embedded.
Parameters:A zero-based index at which to insert text.
The text to be inserted.
The formats to be applied.
This object should have the following structure:{ "formatName1": "formatValue1", ... }
// Inserts bold, green text at the beginning of the content $("#htmlEditorContainer").dxHtmlEditor("instance").insertText(0, "I will be the first", { bold: true, color: "green" });Angular
import { ..., ViewChild } from "@angular/core"; import { DxHtmlEditorModule, DxHtmlEditorComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxHtmlEditorComponent, { static: false }) htmlEditor: DxHtmlEditorComponent; // Prior to Angular 8 // @ViewChild(DxHtmlEditorComponent) htmlEditor: DxHtmlEditorComponent; insertTextAtTheBeginning() { // Inserts bold, green text at the beginning of the content this.htmlEditor.instance.insertText(0, "I will be the first", { bold: true, color: "green" }); } } @NgModule({ imports: [ // ... DxHtmlEditorModule ], // ... })Vue
<template> <DxHtmlEditor :ref="htmlEditorRefKey"> <!-- ... --> </DxHtmlEditor> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxHtmlEditor from 'devextreme-vue/html-editor'; const htmlEditorRefKey = "my-html-editor"; export default { components: { DxHtmlEditor }, data() { return { htmlEditorRefKey } }, methods: { insertTextAtTheBeginning() { // Inserts bold, green text at the beginning of the content this.htmlEditor.insertText(0, "I will be the first", { bold: true, color: "green" }); } }, computed: { htmlEditor: function() { return this.$refs[htmlEditorRefKey].instance; } } } </script>React
import { useRef } from 'react'; import 'devextreme/dist/css/dx.light.css'; import HtmlEditor from 'devextreme-react/html-editor'; export default function App() { const htmlEditor = useRef(null); const insertTextAtTheBeginning = () => { // Inserts bold, green text at the beginning of the content htmlEditor.current.instance().insertText(0, "I will be the first", { bold: true, color: "green" }); }; return ( <HtmlEditor ref={htmlEditor}> {/* */} </HtmlEditor> ); }
Gets the UI component's instance. Use it to access other methods of the UI component.
This UI component's instance.
Detaches all event handlers from a single event.
The object for which this method is called.
Detaches a particular event handler from a single event.
Parameters:The event's name.
The event's handler.
The object for which this method is called.
Subscribes to an event.
Parameters:The event's name.
The event's handler.
The object for which this method is called.
Use this method to subscribe to one of the events listed in the Events section.
See AlsoSubscribes to events.
Parameters:Events with their handlers: { "eventName1": handler1, "eventName2": handler2, ...}
The object for which this method is called.
Use this method to subscribe to several events with one method call. Available events are listed in the Events section.
See AlsoGets the value of a single property.
Parameters:The property's name or full path.
Return Value: any
This property's value.
Updates the value of a single property.
Parameters:The property's name or full path.
optionValue: any
This property's new value.
Updates the values of several properties.
Parameters:Options with their new values.
Reapplies the most recent undone change. Repeated calls reapply preceding undone changes.
Registers custom formats and modules.
Parameters:Formats and modules to be registered.
This object should have the following structure:{ "path1": "object1", ... }
where path1
is formats/[formatName] for formats or modules/[moduleName] for modules.
$(function() { // ... const htmlEditor = $("#htmlEditorContainer").dxHtmlEditor("instance"); htmlEditor.register({ "modules/myModule": moduleObject }); });Angular
import { Component, ViewChild, AfterViewInit } from '@angular/core'; import { DxHtmlEditorComponent } from 'devextreme-angular'; // ... export class AppComponent { @ViewChild(DxHtmlEditorComponent, { static: false }) htmlEditor: DxHtmlEditorComponent; // Prior to Angular 8 // @ViewChild(DxHtmlEditorComponent) htmlEditor: DxHtmlEditorComponent; ngAfterViewInit() { let htmlEditor = this.htmlEditor.instance; htmlEditor.register({ "modules/myModule": moduleObject }); } }Vue
<template> <DxHtmlEditor ... :ref="htmlEditorRefName"> </DxHtmlEditor> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxHtmlEditor from 'devextreme-vue/html-editor'; const htmlEditorRefName = "myHtmlEditor"; export default { components: { DxHtmlEditor }, data() { return { htmlEditorRefName } }, computed: { htmlEditor: function() { return this.$refs[htmlEditorRefName].instance; } }, mounted: function() { this.$nextTick(function() { this.htmlEditor.registerModules({ "modules/myModule": moduleObject }); }) } } </script>React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import HtmlEditor from 'devextreme-react/html-editor'; class App extends React.Component { constructor(props) { super(props); this.htmlEditorRef = React.createRef(); } get htmlEditor() { return this.htmlEditorRef.current.instance(); } render() { return ( <HtmlEditor ... ref={this.htmlEditorRef}> </HtmlEditor> ); } componentDidMount() { this.htmlEditor.register({ "modules/myModule": moduleObject }); } } export default App;
Quill registers modules globally in a static function. You cannot register different modules for different HTML Editor instances. If you register a module for one HTML Editor, this module will be registered for all other HtmlEditors on the page/application.
See AlsoRegisters a handler to be executed when a user presses a specific key.
Parameters:A key.
A handler. Accepts the keydown event as the argument. It is a EventObject or a jQuery.Event when you use jQuery.
The key argument accepts one of the following values:
A custom handler for a key cancels the default handler for this key.
See AlsoRemoves all formatting and embedded content from the specified range.
Parameters:A zero-based index at which to begin removing.
The length of the content to be removed.
Embedded items have a length of 1.
Renders the component again without reloading data. Use the method to update the component's markup and appearance dynamically.
The repaint()
method re-initializes the component with new settings, resetting its state and history. Note: when you repaint()
a component, the "undo" and "redo" buttons become inactive.
Resets the value property to the value passed as an argument.
Parameters:value: any
Specifies the new value.
Resets a property to its default value.
Selects and highlights content in the specified range.
Parameters:A zero-based index at which to begin selecting.
The length of the content to be selected.
Embedded items have a length of 1.
Reverses the most recent change. Repeated calls reverse preceding changes.
Feel free to share topic-related thoughts here.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4