Interface

DataApi (core/editor/utils)

@ckeditor/ckeditor5-core/src/editor/utils/dataapimixin

interface deprecated

Interface defining editor methods for setting and getting data to and from the editor's main root element using the data pipeline.

This interface is not a part of the Editor class because one may want to implement an editor with multiple root elements, in which case the methods for setting and getting data will need to be implemented differently.

Filtering

Methods

  • getData( [ options ] ) → string

    Gets the data from the editor.

    editor.getData(); // -> '<p>This is editor!</p>'
    

    If your editor implementation uses multiple roots, you should pass root name as one of the options:

    editor.getData( { rootName: 'header' } ); // -> '<p>Content for header part.</p>'
    

    By default, the editor outputs HTML. This can be controlled by injecting a different data processor. See the Markdown output guide for more details.

    A warning is logged when you try to retrieve data for a detached root, as most probably this is a mistake. A detached root should be treated like it is removed, and you should not save its data. Note, that the detached root data is always an empty string.

    Parameters

    [ options ] : Record<string, unknown>

    Additional configuration for the retrieved data. Editor features may introduce more configuration options that can be set through this parameter.

    Returns

    string

    Output data.

  • setData( data ) → void

    Sets the data in the editor.

    editor.setData( '<p>This is editor!</p>' );
    

    If your editor implementation uses multiple roots, you should pass an object with keys corresponding to the editor root names and values equal to the data that should be set in each root:

    editor.setData( {
        header: '<p>Content for header part.</p>',
        content: '<p>Content for main part.</p>',
        footer: '<p>Content for footer part.</p>'
    } );
    

    By default the editor accepts HTML. This can be controlled by injecting a different data processor. See the Markdown output guide for more details.

    Parameters

    data : string | Record<string, string>

    Input data.

    Returns

    void