Search results

Data Binding in React InPlaceEditor component

The Essential JS2 React In-place Editor component can load the data either from local data sources or remote data services using the dataSource property and it supports the data type of an array or DataManager. Also supports different kind of data services such as OData, OData V4, Web API and data formats such as XML, JSON, JSONP with the help of DataManager adaptors.

Local

To bind local data to the Essential JS2 React In-place Editor component, you have to assign a JavaScript array of object or string to the dataSource property. The local data source can also be provided as an instance of the DataManager.

Source
Preview
index.tsx
index.html
App.css.jsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App  from './App';

ReactDOM.render(<App />, document.getElementById('root'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 React In-place Editor Sample</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
     <style>
        #container {
            display: flex;
            justify-content: center;
            align-items: center;
            visibility: visible;
            height: 80px;
        }

        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }

        #dropdownelement {
            width: 150px;
        }

        .content-title {
            font-weight: 500;
            margin-right: 20px;
            display: flex;
            align-items: center;
        }
    </style>
</head>
<body>
    <div id='root'>
        <div id='loader'>Loading....</div>
    </div>
</body>
</html>
import { InPlaceEditorComponent } from '@syncfusion/ej2-react-inplace-editor';
import * as React from 'react';
import './App.css';
class App extends React.Component {
    constructor() {
        super(...arguments);
        // define the JSON of data
        this.gameList = [
            { Id: '1', Name: 'Maria Anders' },
            { Id: '2', Name: 'Ana Trujillo' },
            { Id: '3', Name: 'Antonio Moreno' },
            { Id: '4', Name: 'Thomas Hardy' },
            { Id: '5', Name: 'Chiristina Berglund' },
            { Id: '6', Name: 'Hanna Moos' }
        ];
        this.model = { dataSource: this.gameList, fields: { text: 'Name' }, placeholder: 'Select a customer' };
    }
    render() {
        return (<div id='container'>
        <span className="content-title"> Select customer name: </span>
        <InPlaceEditorComponent ref={(text) => { this.inplaceEditorObj = text; }} id='dropdownelement' mode='Inline' type='DropDownList' value='Maria Anders' model={this.model}/>
     </div>);
    }
}
export default App;

Remote

To bind remote data to the Essential JS2 React In-place Editor component, assign service data as an instance of DataManager to the dataSource property. To interact with remote data source, provide the endpoint URL.

OData V4

The OData V4 is an improved version of OData protocols, and the DataManager can also retrieve and consume OData V4 services. To fetch data from the server by using DataManager with the adaptor property configure as ODataV4Adaptor.

In the following sample, In-place Editor renders a DropDownList component and its dataSource property configured for fetching a data from the server by using ODataV4Adaptor with DataManager.

Source
Preview
index.tsx
index.html
App.css.jsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App  from './App';

ReactDOM.render(<App />, document.getElementById('root'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 React In-place Editor Sample</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
     <style>
        #container {
            display: flex;
            justify-content: center;
            align-items: center;
            visibility: visible;
            height: 80px;
        }

        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }

        #dropdownelement {
            width: 150px;
        }

        .content-title {
            font-weight: 500;
            margin-right: 20px;
            display: flex;
            align-items: center;
        }
    </style>
</head>
<body>
    <div id='root'>
        <div id='loader'>Loading....</div>
    </div>
</body>
</html>
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { InPlaceEditorComponent } from '@syncfusion/ej2-react-inplace-editor';
import * as React from 'react';
import './App.css';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.query = new Query().from('Customers').select(['ContactName', 'CustomerID']).take(6);
        this.model = {
            dataSource: new DataManager({
                adaptor: new ODataV4Adaptor,
                crossDomain: true,
                url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
            }),
            fields: { text: 'ContactName', value: 'CustomerID' },
            placeholder: 'Select a customer',
            query: this.query
        };
    }
    render() {
        return (<div id='container'>
        <span className="content-title"> Select customer name: </span>
        <InPlaceEditorComponent id='dropdownelement' mode='Inline' type='DropDownList' value='Maria Anders' model={this.model}/>
     </div>);
    }
}
export default App;

Web API

Data can fetch from the server by using DataManager with the adaptor property configure as WebApiAdaptor.

In the following sample, In-place Editor render a DropDownList component and its dataSource property configured for fetching a data from the server by using WebApiAdaptor with DataManager.

Source
Preview
index.tsx
index.html
App.css.jsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App  from './App';

ReactDOM.render(<App />, document.getElementById('root'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 React In-place Editor Sample</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
     <style>
        #container {
            display: flex;
            justify-content: center;
            align-items: center;
            visibility: visible;
            height: 80px;
        }

        #loader {
            color: #008cff;
            height: 40px;
            left: 45%;
            position: absolute;
            top: 45%;
            width: 30%;
        }

        #dropdownelement {
            width: 150px;
        }

        .content-title {
            font-weight: 500;
            margin-right: 20px;
            display: flex;
            align-items: center;
        }
    </style>
</head>
<body>
    <div id='root'>
        <div id='loader'>Loading....</div>
    </div>
</body>
</html>
import { DataManager, Query, WebApiAdaptor } from '@syncfusion/ej2-data';
import { InPlaceEditorComponent } from '@syncfusion/ej2-react-inplace-editor';
import * as React from 'react';
import './App.css';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.dm = new DataManager({
            adaptor: new WebApiAdaptor,
            url: 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Customers/'
        }).executeQuery(new Query().take(8)).then((e) => {
            this.model.dataSource = e.result.d;
        });
        this.model = {
            dataSource: [{}],
            fields: { text: 'ContactName', value: 'CustomerID' },
            placeholder: 'Select a customer'
        };
    }
    render() {
        return (<div id='container'>
        <span className="content-title"> Select customer name: </span>
        <InPlaceEditorComponent id='dropdownelement' mode='Inline' type='DropDownList' value='Maria Anders' model={this.model}/>
     </div>);
    }
}
export default App;