This section briefly explains about how to include a In-place Editor component in your Blazor client-side application. You can refer Getting Started with Syncfusion Blazor for Client-Side in Visual Studio 2019 Preview page for the introduction and configuring the common specifications.
Syncfusion.EJ2.Blazor
NuGet package to the application by using the NuGet Package Manager
. Please ensure to check the Include prerelease
option.<head>
element of the ~/wwwroot/index.html
page.<head>
<environment include="Development">
<link href="https://cdn.syncfusion.com/ej2/17.3.29/material.css" rel="stylesheet" />
<script src="https://cdn.syncfusion.com/ej2/17.3.29/dist/ej2.min.js"></script>
</environment>
</head>
Initialize the Blazor In-place Editor component in any web page (razor) in the Pages
folder. For example, the In-place Editor component is added in the ~/Pages/Index.razor page.
The following code explains how to initialize a simple In-place-Editor in the Razor page.
@using Syncfusion.EJ2.Blazor
@using Syncfusion.EJ2.Blazor.Inputs
@using Syncfusion.EJ2.Blazor.InPlaceEditor
<table>
<tr>
<td>
<label class="control-label" style="text-align: left;font-size: 14px;font-weight: 400">
TextBox
</label>
</td>
<td>
<EjsInPlaceEditor Mode="RenderMode.Inline" Type="InputType.Text" Value="@TextValue" SubmitOnEnter="true" Model="@TModel">
</EjsInPlaceEditor>
</td>
</tr>
</table>
@code {
public string TextValue = "Andrew";
public TextBoxModel TModel = new TextBoxModel()
{
Placeholder = "Enter employee name"
};
}
The following code explains how to initialize a simple In-place Editor with popup in the Blazor page.
@using Syncfusion.EJ2.Blazor
@using Syncfusion.EJ2.Blazor.DropDowns
@using Syncfusion.EJ2.Blazor.InPlaceEditor
<table>
<tr>
<td>
<label class="control-label">
Choose a Country:
</label>
</td>
<td>
<EjsInPlaceEditor Mode="RenderMode.Popup" Type="InputType.AutoComplete" Value="@AutoValue" Model="@AutocompleteData">
</EjsInPlaceEditor>
</td>
</tr>
</table>
@code {
public string AutoValue = "Australia";
public AutoCompleteModel<string> AutocompleteData = new AutoCompleteModel<string>()
{
Placeholder = "Type to search countries",
DataSource = new string[] { "Australia", "Bermuda", "Canada", "Cameroon", "Denmark", "Finland", "Greenland", "Poland" }
};
}
After successful compilation of your application, run the application.
Output be like the below.
You can render the Blazor DropDownList by changing the Type
property as DropDownList
and configure its properties and methods using the Model
property.
In the following example, Type
and model values are configured to render the DropDownList
component.
@using Syncfusion.EJ2.Blazor
@using Syncfusion.EJ2.Blazor.DropDowns
@using Syncfusion.EJ2.Blazor.InPlaceEditor
<EjsInPlaceEditor Mode="RenderMode.Inline" Type="InputType.DropDownList" Value="@DropdownValue" Model="@DropdownData" />
@code {
public string DropdownValue = "Australia";
public DropDownListModel<string> DropdownData = new DropDownListModel<string>()
{
Placeholder = "Select Country",
DataSource = new string[] { "Australia", "Bermuda", "Canada", "Cameroon", "Denmark", "Finland", "Greenland", "Poland" }
};
}
You can render the Blazor DatePicker
by changing the Type
property as Date
and also configure its properties and methods using the Model
property.
In the following sample, Type
and Model
values are configured to render the DatePicker
component.
@using Syncfusion.EJ2.Blazor
@using Syncfusion.EJ2.Blazor.Calendars
@using Syncfusion.EJ2.Blazor.InPlaceEditor
<EjsInPlaceEditor Mode="RenderMode.Inline" Type="InputType.Date" Value="@DateValue" Model="@DateModel" />
@code {
public DateTime DateValue { get; set; } = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
public DatePickerModel DateModel = new DatePickerModel()
{
Placeholder = "Select date",
ShowTodayButton = true
};
}
In the following code, it is configured to render the DatePicker
, Dropdownlist
and Textbox
components.
@using Syncfusion.EJ2.Blazor
@using Syncfusion.EJ2.Blazor.Inputs
@using Syncfusion.EJ2.Blazor.Calendars
@using Syncfusion.EJ2.Blazor.DropDowns
@using Syncfusion.EJ2.Blazor.InPlaceEditor
<div id="container" class="control-group">
<h3> Modify Basic Details </h3>
<table style="margin: 10px auto;">
<tr>
<td>Name</td>
<td class='left'>
<EjsInPlaceEditor Mode="RenderMode.Inline" Type="InputType.Text" Value="@TextValue" Model="@TModel">
</EjsInPlaceEditor>
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td class='left'>
<EjsInPlaceEditor Mode="RenderMode.Inline" Type="InputType.Date" Value="@DateValue" Model="@DateModel">
</EjsInPlaceEditor>
</td>
</tr>
<tr>
<td>Gender</td>
<td class='left'>
<EjsInPlaceEditor Mode="RenderMode.Inline" Type="InputType.DropDownList" Value="@DropdownValue" Model="@DropdownData">
</EjsInPlaceEditor>
</td>
</tr>
</table>
</div>
<style>
#container {
text-align: center;
margin-top: 50px;
}
#container table {
width: 400px;
margin: auto;
}
#container table td {
height: 70px;
width: 150px;
}
#container table .left {
text-align: left;
}
</style>
@code {
public DateTime DateValue { get; set; } = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
public string TextValue = "Andrew";
public string DropdownValue = "Male";
public DropDownListModel<string> DropdownData = new DropDownListModel<string>()
{
Placeholder = "Select Gender",
DataSource = new string[] { "Male", "Female" }
};
public DatePickerModel DateModel = new DatePickerModel()
{
Placeholder = "Select date",
ShowTodayButton = true
};
public TextBoxModel TModel = new TextBoxModel()
{
Placeholder = "Enter your name"
};
}
Output be like the below.
You can submit editor value to the 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 is used by DataManager to communicate with DataSource. |
PrimaryKey |
Defines the unique primary key of editable field which can be used for saving data in the data-base. |
The
PrimaryKey
property is mandatory. If it is not set, edited data are not sent to the server.
The edited data is submitted to the server and you can see the new values getting reflected in the In-place Editor.
@using Syncfusion.EJ2.Blazor
@using Syncfusion.EJ2.Blazor.DropDowns
@using Syncfusion.EJ2.Blazor.InPlaceEditor
<div id="container">
<div class="control-group">
Best Employee of the year: <EjsInPlaceEditor @ref="InPlaceObj" PrimaryKey="Employee" Name="Employee" Adaptor="AdaptorType.UrlAdaptor" Url="https://ej2services.syncfusion.com/development/web-services/api/Editor/UpdateData" Mode="RenderMode.Inline" Type="InputType.DropDownList" Value="@DropdownValue" Model="@DropdownData">
<InPlaceEditorEvents Created="OnCreate" OnActionSuccess="OnSuccess" TValue="string"></InPlaceEditorEvents>
</EjsInPlaceEditor>
</div>
<table style="margin:60px auto;width:25%">
<tr>
<td style="text-align: left">
Old Value :
</td>
<td id="oldValue" style="text-align: left">
@PreviousValue
</td>
</tr>
<tr>
<td style="text-align: left">
New Value :
</td>
<td id="newValue" style="text-align: left">
@CurrentValue
</td>
</tr>
</table>
</div>
<style>
.e-inplaceeditor {
min-width: 200px;
text-align: left;
}
#container .control-group {
text-align: center;
margin: 100px auto;
}
</style>
@code {
EjsInPlaceEditor<string> InPlaceObj;
public string PreviousValue { get; set; }
public string DropdownValue = "Andrew Fuller";
public string CurrentValue { get; set; }
public DropDownListModel<string> DropdownData = new DropDownListModel<string>()
{
Placeholder = "Select employee",
DataSource = new string[] { "Andrew Fuller", "Janet Leverling", "Laura Callahan", "Margaret Hamilt", "Michael Suyama", "Nancy Davloio", "Robert King" },
PopupHeight = "200px"
};
public void OnCreate(object args)
{
this.CurrentValue = this.DropdownValue;
}
public void OnSuccess(ActionEventArgs args)
{
this.PreviousValue = this.CurrentValue;
this.CurrentValue = args.Value;
}
}
The output will be as follows.