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
App.tsx
App.css.jsx
App.jsx
index.jsx
import { InPlaceEditorComponent } from '@syncfusion/ej2-react-inplace-editor';
import * as React from 'react';
import './App.css';

class App extends React.Component {
  public inplaceEditorObj: InPlaceEditorComponent;

 // define the JSON of data
 public gameList: object[] = [
    { 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' }
 ];

  public model = { dataSource: this.gameList, fields: { text: 'Name' }, placeholder: 'Select a customer' };

  public 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;
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;
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));

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
App.tsx
App.css.jsx
App.jsx
index.jsx
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 {
  public query: Query = new Query().from('Customers').select(['ContactName', 'CustomerID']).take(6);
  public 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
        };

  public 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;
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;
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));

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
App.tsx
App.css.jsx
App.jsx
index.jsx
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 {
  public dm: any = new DataManager({
    adaptor: new WebApiAdaptor,
    url: 'https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Customers/'
    }).executeQuery(new Query().take(8)).then((e: any) => {
        this.model.dataSource = e.result.d;
  });
  public model: any = {
    dataSource: [{}],
    fields: { text: 'ContactName', value: 'CustomerID' },
    placeholder: 'Select a customer'
  };

  public 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;
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;
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));