Search results

Server Actions in React In-place Editor component

By passing In-place Editor component value to the server, the primaryKey property value must required otherwise action not performed for remote data.

If the URL property value is empty, data passing will handled at local and also the actionSuccess event will trigger with null as argument value.

The following arguments are passed to the server when submit actions perform.

Arguments Explanations
value For processing edited value, like DB value updating.
primaryKey For value mapping to the server, like selecting DB.
name For field mapping to the server, like DB column field mapping.

Find the following sample server codes for defining models and controller functions to configure processing data.

  public class SubmitModel {
      public string Name { get; set; }
      public string PrimaryKey { get; set; }
      public string Value { get; set; }
  }
public IEnumerable<SubmitModel> UpdateData([FromBody]SubmitModel value) {
  // User can process data
  return value;
}
  • When Server actions successfully done, the actionSuccess event will be fired with returned server data.

  • If the server is not responding, the actionFailure event will be fired with data, but value not updated in the Editor.

In the following sample, the actionSuccess event will trigger once the value submitted successfully into the server. In this sample, both actionSuccess and actionFailure were configured and resulted value will be converted to chips.

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;
            visibility: visible;
            align-items: center;
            height: 80px;
        }

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

        #multiselect {
            width: 300px;
        }

        .content-title {
            font-weight: 500;
            margin-right: 20px;
            display: flex;
            align-items: center;
            width: 130px;
        }

        .e-highlight {
            color: red;
        }
    </style>
</head>
<body>
    <div id='root'>
        <div id='loader'>Loading....</div>
    </div>
</body>
</html>
import { Inject, InPlaceEditorComponent, MultiSelect } from '@syncfusion/ej2-react-inplace-editor';
import * as React from 'react';
import './App.css';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.serviceUrl = 'https://ej2services.syncfusion.com/development/web-services/api/Editor/UpdateData';
        this.frameWorkList = ['Android', 'JavaScript', 'jQuery', 'TypeScript', 'Angular', 'React', 'Vue', 'Ionic'];
        this.value = ['JavaScript', 'jQuery'];
        this.model = { mode: 'Box', dataSource: this.frameWorkList, placeholder: 'Select skill' };
    }
    chipOnCreate() {
        this.inplaceEditorObj.element.querySelector('.e-editable-value').innerHTML = this.chipCreation(this.inplaceEditorObj.value, true);
    }
    onActionSuccess(e) {
        e.value = this.chipCreation(e.value.split(','), true);
    }
    onActionFailure(e) {
        e.value = this.chipCreation(e.value.split(','), false);
    }
    chipCreation(data, isSuccess) {
        let value = '<div class="e-chip-list">';
        [].slice.call(data).forEach((val) => {
            value += '<div class="e-chip"> <span class="e-chip-text' + (!isSuccess ? 'e-highlight' : '') + '"> ' + val + '</span></div>';
        });
        value += '</div>';
        return value;
    }
    create() {
        this.chipOnCreate();
    }
    render() {
        return (<div id='container'>
         <span className="content-title"> Select frameworks: </span>
         <InPlaceEditorComponent ref={(text) => { this.inplaceEditorObj = text; }} id='multiselect' data-underline='false' mode='Inline' type='MultiSelect' value={this.value} name='skill' url={this.serviceUrl} primaryKey='FrameWork' adaptor='UrlAdaptor' model={this.model} actionSuccess={this.onActionSuccess = this.onActionSuccess.bind(this)} actionFailure={this.onActionFailure = this.onActionFailure.bind(this)} created={this.create = this.create.bind(this)}>
         <Inject services={[MultiSelect]}/>
         </InPlaceEditorComponent>
     </div>);
    }
}
export default App;

See Also