- Home
- Forum
- ASP.NET Core - EJ 2
- How do I default the value of a field to a previously entered field when adding records in a dialog to the grid?
How do I default the value of a field to a previously entered field when adding records in a dialog to the grid?
Good day
I have a grid providing CRUD for a model ID, Code, ShortDescription, LongDescription
All fields are required so I am trying to default the value of LongDescription to ShortDescription in dialog mode when entering a new record
I achieved this by using the code below in bold but is this the correct way to do it?
In addition, is there any detailed documentation showing the features available when using params passed in the edit of the field? edit="@(new {@params = TextField})
Thanks
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
@{
ViewData["Title"] = "Collection Types";
}
@{
var TextField = new Syncfusion.EJ2.Inputs.TextBox
{
Change = "Changed",
};
}
<div>
<div tabindex="0" class="e-card" id="basic_card">
<div class="e-card-header">
<div class="e-card-header-caption">
<div class="e-card-header-title"> <h2> Collection Types</h2></div>
<div class="e-card-sub-title"> </div>
</div>
</div>
<div class="e-card-content">
<ejs-grid id="Grid" toolbar="@(new List<string>() { "Add", "Edit", "Delete" })" allowPaging="true" allowSorting="true" allowFiltering="true" actionFailure="actionFailure" created="created" actionComplete="complete">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" showDeleteConfirmDialog="true"></e-grid-editSettings>
<e-grid-pagesettings pageSize="10">
</e-grid-pagesettings>
<e-grid-columns>
<e-grid-column field="ID" headerText="ID" visible="false" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="Code" headerText="Code" width="150" validationRules="@(new { required= true, maxLength = 10 })"></e-grid-column>
<e-grid-column field="ShortDescription" headerText="Short Description" width="150" edit="@(new {@params = TextField})"></e-grid-column>
<e-grid-column field="LongDescription" headerText="Long Description" width="170" ></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<div class="e-card-actions">
</div>
</div>
</div>
<style>
.e-grid .e-altrow {
background-color: #fafafa;
}
</style>
<script>
function actionFailure(args) {
var span = document.createElement('span');
this.element.parentNode.insertBefore(span, this.element);
span.style.color = '#FF0000'
span.innerHTML = 'There was a problem retrieving data';
}
</script>
<script>
function created(args) {
var grid = document.querySelector('#Grid').ej2_instances[0];
grid.dataSource = new ej.data.DataManager({
url: "@Configuration["ApiResourceBaseUrls:Api"]/odata/TableCollections",
adaptor: new ej.data.ODataV4Adaptor({ updateType: 'PUT' }),
headers: [{ 'Authorization': 'Bearer ' + '@ViewBag.AuthToken' }]
});
}
</script>
<script type="text/javascript">
function complete(args) {
console.log("Event " + args.requestType);
// console.log("Action complete " + JSON.stringify(args.dialog));
if ((args.requestType === 'beginEdit' || args.requestType === 'add')) {
let dialog = args.dialog;
// change the header of the dialog
dialog.header = args.requestType === 'beginEdit' ? 'Edit Record' : 'New Record';
}
}
</script>
<script>
function Changed(args) {
var grid = document.querySelector('#Grid').ej2_instances[0];
if (grid.editModule.formObj.element.querySelector("#" + grid.element.id + "LongDescription").ej2_instances[0].value == "") {
grid.editModule.formObj.element.querySelector("#" + grid.element.id + "LongDescription").ej2_instances[0].value = grid.editModule.formObj.element.querySelector("#" + grid.element.id + "ShortDescription").ej2_instances[0].value;
}
}
</script>
SIGN IN To post a reply.
6 Replies
1 reply marked as answer
RR
Rajapandi Ravi
Syncfusion Team
October 6, 2020 11:55 AM UTC
Hi Edmund,
Greetings from syncfusion support
Based on your requirement we have prepared a sample of Grid with Remote save adaptor. To add a new record you have to return the Json value correctly. Please refer the below code example, sample and screenshot for more information.
|
public ActionResult Insert([FromBody]CRUDModel<Orders> value)
{
_context.Orders.Add(value.Value);
_context.SaveChanges();
return Json(value.Value);
}
|
Screenshot:
If you still face the issue, please share us your complete Grid rendering code client and server side.
Regards,
Rajapandi R
Rajapandi R
RW
Ronald Walcott
October 6, 2020 07:44 PM UTC
I believe that you have incorrectly responded to my query Your response is to a query regarding the remote save adaptor.
RR
Rajapandi Ravi
Syncfusion Team
October 7, 2020 05:31 AM UTC
Hi Ronald,
Sorry for the inconvenienced.
Please ignore our above update. This has been posted incorrectly.
Regards,
Rajapandi R
Rajapandi R
PG
Praveenkumar Gajendiran
Syncfusion Team
October 8, 2020 08:45 AM UTC
Hi Ronald,
Sorry for the late reply and we are deeply regret the inconvenience caused.
Sorry for the late reply and we are deeply regret the inconvenience caused.
Query: “I achieved this by using the code below in bold but is this the correct way to do it?”
We checked your code example and it is the correct way to achieve your requirement.
Query 2: “In addition, is there any detailed documentation showing the features available when using params passed in the edit of the field? edit="@(new {@params = TextField})”
The mentioned requirement is a unique requirement, so we do not have a document related to your approach, but we have document about Cell edit type and its params,
Documentation Link: https://ej2.syncfusion.com/aspnetcore/documentation/grid/edit/#cell-edit-type-and-its-params
Please get back to us if you need further assistance.
Regards,
Praveenkumar G
Documentation Link: https://ej2.syncfusion.com/aspnetcore/documentation/grid/edit/#cell-edit-type-and-its-params
Please get back to us if you need further assistance.
Regards,
Praveenkumar G
Marked as answer
RW
Ronald Walcott
October 8, 2020 03:32 PM UTC
Thank you
PK
Prasanna Kumar Viswanathan
Syncfusion Team
October 9, 2020 04:26 AM UTC
Hi Ronald,
Thanks for the update.
Please get back to us if you need any further assistance.
Regards,
Prasanna Kumar N.S.V
SIGN IN To post a reply.
- 6 Replies
- 4 Participants
- Marked answer
-
RW Ronald Walcott
- Oct 5, 2020 05:17 PM UTC
- Oct 9, 2020 04:26 AM UTC