Search results

Getting Started

This section briefly explains about how to create a simple In-place Editor using TypeScript and configure its properties using Essential JS 2 quickstart seed repository.

Dependencies

The following is the list of dependencies required to use the In-place Editor control in your application.

|-- @syncfusion/ej2-inplace-editor
    |-- @syncfusion/ej2-base
    |-- @syncfusion/ej2-data
    |-- @syncfusion/ej2-inputs
    |-- @syncfusion/ej2-popups
    |-- @syncfusion/ej2-buttons
    |-- @syncfusion/ej2-dropdowns
    |-- @syncfusion/ej2-calendars
    |-- @syncfusion/ej2-richtexteditor

Set up your development environment

  • Clone the Essential JS 2 quickstart application project from GitHub and install necessary npm packages using the following command.
git clone https://github.com/syncfusion/ej2-quickstart.git quickstart
cd quickstart
npm install

By default, the project is configured with all the Essential JS 2 dependencies. For better understanding, remove all the dependencies from src/system.config.js to get started with the In-place Editor control.

[src/system.config.js]

System.config({
    paths: {
        'syncfusion:': './node_modules/@syncfusion/',
    },
    map: {
        app: 'app',
        //Syncfusion packages mapping
        "@syncfusion/ej2-base": "syncfusion:ej2-base/dist/ej2-base.umd.min.js",
        "@syncfusion/ej2-data": "syncfusion:ej2-data/dist/ej2-data.umd.min.js",
        "@syncfusion/ej2-lists": "syncfusion:ej2-lists/dist/ej2-lists.umd.min.js",
        "@syncfusion/ej2-inputs": "syncfusion:ej2-inputs/dist/ej2-inputs.umd.min.js",
        "@syncfusion/ej2-popups": "syncfusion:ej2-popups/dist/ej2-popups.umd.min.js",
        "@syncfusion/ej2-buttons": "syncfusion:ej2-buttons/dist/ej2-buttons.umd.min.js",
        "@syncfusion/ej2-dropdowns": "syncfusion:ej2-dropdowns/dist/ej2-dropdowns.umd.min.js",
        "@syncfusion/ej2-calendars": "syncfusion:ej2-calendars/dist/ej2-calendars.umd.min.js",
        "@syncfusion/ej2-navigations": "syncfusion:ej2-navigations/dist/ej2-navigations.umd.min.js",
        "@syncfusion/ej2-splitbuttons": "syncfusion:ej2-splitbuttons/dist/ej2-splitbuttons.umd.min.js",
        "@syncfusion/ej2-richtexteditor": "syncfusion:ej2-richtexteditor/dist/ej2-richtexteditor.umd.min.js",
        "@syncfusion/ej2-inplace-editor": "syncfusion:ej2-inplace-editor/dist/ej2-inplace-editor.umd.min.js"
    },
    packages: {
        'app': { main: 'app', defaultExtension: 'js' }
    }
});

System.import('app');
  • In-place Editor CSS files are available in the ej2-inplace-editor and its sub-control package folder. This can be referenced in your application using the following code.

[src/styles/styles.css]

@import '../../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-calendars/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-richtexteditor/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-inplace-editor/styles/material.css';
  • In case, if you want to make use of the combined CSS files of entire controls, then you can avail it from the root folder of Essential JS 2 package and reference it with the code shown below.
@import '../../node_modules/ej2/material.css';

Add the In-place Editor with Textbox

By default, Essential JS 2 TextBox control is rendered in In-place Editor with type property sets as Text.

  • Add the HTML div tag with its id attribute as element in your index.html file to initialize the In-place Editor.

[src/index.html]

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 In-place Editor</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <meta name="description" content="Essential JS 2" />
    <meta name="author" content="Syncfusion" />
    <link rel="shortcut icon" href="resources/favicon.ico" />
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <!--style reference from app-->
    <link href="/styles/styles.css" rel="stylesheet" />
    <!--system js reference and configuration-->
    <script src="node_modules/systemjs/dist/system.src.js" type="text/javascript"></script>
    <script src="system.config.js" type="text/javascript"></script>
</head>
<body>
    <div style="margin: 50px;">
        <!--element which is going to render-->
        <div id="element">
    </div>
</body>
</html>
  • Import the In-place Editor control to your app.ts file and initialize it to the #element as shown below.

[src/app/app.ts]

import { InPlaceEditor } from '@syncfusion/ej2-inplace-editor';
let editObj: InPlaceEditor = new InPlaceEditor({
    type: 'Text',
    value: 'Andrew',
    model: {
        placeholder: 'Enter employee name'
    }
});
editObj.appendTo('#element');

In the above sample code, #element is the id of the HTML element in a page to which the In-place Editor is initialized.

Configuring DropDownList

You can render Essential JS 2 DropDownList by changing type property as DropDownList and configure its properties and methods using model property.

In the below sample, type and model values are configured to render the DropDownList control.

[src/app/app.ts]

import { InPlaceEditor } from '@syncfusion/ej2-inplace-editor';
let genderData = ['Male', 'Female']
let editObj: InPlaceEditor = new InPlaceEditor({
    type: 'DropDownList',
    mode: 'Inline',
    model: {
        dataSource: genderData,
        placeholder: 'Select gender'
    }
});
editObj.appendTo('#element');

Integrate DatePicker

You can render Essential JS2 DatePicker by changing type property as Date  and also configure its properties and methods using model property.

In the below sample, type and model values are configured to render the DatePicker control.

[src/app/app.ts]

import { InPlaceEditor } from '@syncfusion/ej2-inplace-editor';
let editObj: InPlaceEditor = new InPlaceEditor({
    type: 'Date',
    value: new Date('04/12/2018'),
    model: {
        showTodayButton: true
    }
});
editObj.appendTo('#element');

Run the application

  • Run the application in the browser using the following command.
npm start
Source
Preview
index.ts
index.html
import { InPlaceEditor } from '@syncfusion/ej2-inplace-editor';
let genderData = ['Male', 'Female'];
let editObj: InPlaceEditor = new InPlaceEditor({
    type: 'Date',
    mode: 'Inline',
    value: new Date('04/12/2018'),
    model: {
        showTodayButton: true,
         placeholder: 'Select date of birth'
    }
});
editObj.appendTo('#dateofbirth');
let editObj: InPlaceEditor = new InPlaceEditor({
    value: 'Andrew',
    mode: 'Inline',
    model: {
        placeholder: 'Enter your name'
    }
});
editObj.appendTo('#element');
let editObj: InPlaceEditor = new InPlaceEditor({
    type: 'DropDownList',
    value: 'Male',
    mode: 'Inline',
    model: {
        dataSource: genderData,
        placeholder: 'Select gender'
    }
});
editObj.appendTo('#gender');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 In-place Editor</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript In-place Editor Control" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>LOADING....</div>
    <div id='container'>
        <div class="control-group">
            <h3> Modify Basic Details </h3>
            <table>
                <tr>
                    <td>Name</td>
                    <td class='left'>
                        <div id='element'></div>
                    </td>
                </tr>
                <tr>
                    <td>Date of Birth</td>
                    <td class='left'>
                        <div id='dateofbirth'></div>
                    </td>
                </tr>
                <tr>
                    <td>Gender</td>
                    <td class='left'>
                        <div id='gender'></div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    </div>
</body>

</html>

Submitting data to the server (save)

You can submit editor value to server by configuring the url, adaptor and primaryKey property.

Property Usage
url Gets the url for server submit action.
adaptor Specifies the adaptor type that are used by DataManager to communicate with DataSource.
primarykey Defines the unique primary key of editable field which can be used for saving data in data-base.

primaryKey property is mandatory. If it’s not set, edited data are not sent to the server.

Refresh with modified value

The edited data is submitted to the server and you can see the new values getting reflected in the In-place Editor.

Source
Preview
index.ts
index.html
import { InPlaceEditor, ActionEventArgs, MultiSelect } from '@syncfusion/ej2-inplace-editor';
InPlaceEditor.Inject(MultiSelect);
let serviceUrl: string = 'https://ej2services.syncfusion.com/development/web-services/api/Editor/UpdateData';
let frameWorkList: string[] = ['Andrew Fuller', 'Janet Leverling', 'Laura Callahan', 'Margaret Hamilt', 'Michael Suyama', 'Nancy Davloio', 'Robert King'];
let newEle: HTMLElement = document.getElementById('newValue');
let oldEle: HTMLElement = document.getElementById('oldValue');
let editObj: InPlaceEditor = new InPlaceEditor({
    mode: 'Inline',
    type: 'DropDownList',
    value: 'Andrew Fuller',
    name: 'Employee',
    url: serviceUrl,
    primaryKey: "Employee",
    adaptor: 'UrlAdaptor',
    actionSuccess: function(e) {
      oldEle.textContent = newEle.textContent;
      newEle.textContent = e.value;
    },
    model: {
        dataSource: frameWorkList,
        popupHeight: '200px',
        placeholder: 'Select employee'
    }
});
editObj.appendTo('#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 In-place Editor</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript In-place Editor Control" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>LOADING....</div>
    <div id='container'>
        <div class="control-group">
            Best Employee of the year: <div id='element'></div>
        </div>
        <table style="margin:auto;width:50%">
            <tr>
                <td style="text-align: left">
                    Old Value :
                </td>
                <td id="oldValue" style="text-align: left">
                </td>
            </tr>
            <tr>
                <td style="text-align: left">
                    New Value :
                </td>
                <td id="newValue" style="text-align: left">
                    Andrew Fuller
                </td>
            </tr>
        </table>
    </div>
</body>

</html>