Search results

Server Actions in JavaScript In-place Editor control

06 Jun 2023 / 3 minutes to read

By passing In-place Editor control value to the server, the primaryKey property value must require, 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.

Copied to clipboard
    public class SubmitModel
        {
            public string Name { get; set; }
            public string PrimaryKey { get; set; }
            public string Value { get; set; }
        }
Copied to clipboard
public IEnumerable<SubmitModel> UpdateData([FromBody]SubmitModel value)
        {
         // User can process data
          return value;
        }
  • 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.ts
index.html
Copied to clipboard
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[] = ['Android', 'JavaScript', 'jQuery', 'TypeScript', 'Angular', 'React', 'Vue', 'Ionic'];

let editObj: InPlaceEditor = new InPlaceEditor({
mode: 'Inline',
type: 'MultiSelect',
value: ['JavaScript', 'jQuery'],
name: 'skill',
url: serviceUrl,
primaryKey: "FrameWork",
adaptor: 'UrlAdaptor',
model: {
    mode: 'Box',
    dataSource: frameWorkList,
    placeholder: 'Select skill'
},
actionSuccess: onActionSuccess,
actionFailure: onActionFailure
});
editObj.appendTo('#element');

chipOnCreate(); // Initialize chips customization at initial load

function chipOnCreate(): void {
editObj.element.querySelector('.e-editable-value').innerHTML = chipCreation(editObj.value);
}

function onActionSuccess(e: ActionEventArgs): void {
e.value = chipCreation(e.value.split(','), true);
}

function onActionFailure(e: ActionEventArgs): void {
e.value = chipCreation(e.value.split(','), false);
}

function chipCreation(data: string[], isSuccess: boolean): string {
let value: string = '<div class="e-chip-list">';
[].slice.call(data).forEach((val: string) => {
    value += '<div class="e-chip"> <span class="e-chip-text' + (!isSuccess ? 'e-highlight' : '') + '"> ' + val + '</span></div>';
});
value += '</div>';
return value;
}
Copied to clipboard
<!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/21.2.3/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'>
        <span class="content-title"> Select frameworks: </span>
        <div id='element' data-underline="false"></div>
    </div>
</body>

</html>

See Also