I am creating a Razor Page using the SyncFusion Datagrid control and DatePicker
Datepicker is added as part of a form
<ejs-datepicker id="AvailDate" focus="onFocus" width="150px" ejs-for="@Model.availableDate_Selected" placeholder="Enter date" change="valueChange_availableDate"></ejs-datepicker>
<script type="text/javascript">
function onFocus (args) {
var datepickerObject = document.getElementById("AvailDate").ej2_instances[0];
datepickerObject.show();
}
function valueChange_availableDate() {
var listObj = document.getElementById('AvailDate').ej2_instances[0];
var value = document.getElementById('value');
var text = document.getElementById('text');
}
</script>
@section Scripts{
<script type="text/javascript">
valueChange_availableDate();
</script>
}
Issue 1: When the user selects a date from the dropdown, the value is not assigned to the @Model.availableDate_Selected . Please help identify when the value is accessible from the code (.cs page)
@{
List<object> commands = new List<object>();
commands.Add(new { type = "Edit", buttonOption = new { iconCss = "e-icons e-edit", cssClass = "e-flat" } });
commands.Add(new { type = "Save", buttonOption = new { iconCss = "e-icons e-update", cssClass = "e-flat" } });
commands.Add(new { type = "Cancel", buttonOption = new { iconCss = "e-icons e-cancel-icon", cssClass = "e-flat" } });
}
....
<div class="control-section">
<ejs-grid id="Grid" dataSource="@Model.capacityList" allowPaging="true" allowSorting="true" allowExcelExport="false" height="300"
allowFiltering="false" width="100%" toolbar="@(new List<string>() {"Search" })" allowTextWrap="false" enableStickyHeader="true">
<e-grid-editSettings allowEditing="true"></e-grid-editSettings>
<e-grid-pagesettings pageSize="15"></e-grid-pagesettings>
<e-grid-columns>
<e-grid-column field="CapacityID" allowEditing="false" isPrimaryKey="true" headerText="CapacityID" width="0"></e-grid-column>
<e-grid-column field="CarrierName" allowEditing="false" headerText="Carrier" width="80"></e-grid-column>
<e-grid-column field="EquipmentName" allowEditing="false" headerText="Equipment" width="75"></e-grid-column>
<e-grid-column field="Quantity" allowEditing="false" headerText="Qty" width="75" format="N0"></e-grid-column>
<e-grid-column field="From" allowEditing="false" headerText="From" width="90"></e-grid-column>
<e-grid-column field="To" allowEditing="false" headerText="To" width="90"></e-grid-column>
<e-grid-column field="DateAvailable" allowEditing="false" headerText="Available Date" format="MM/dd/yy" width="90"></e-grid-column>
<e-grid-column field="CarrierComments" allowEditing="false" headerText="Carrier Commments" width="120"></e-grid-column>
<e-grid-column field="EquipmentUsed" allowEditing="true" headerText="Used Qty" width="80" format="N0"></e-grid-column>
<e-grid-column field="UsedComments" allowEditing="true" headerText="Commments" width="170"></e-grid-column>
<e-grid-column headerText="Manage Records" width="70" commands="commands"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
Issue 2: Please advise how using c# can I write the method in the .cs page on razor page when the "save" button is clicked?
Thank you
|
// Grid’s actionBegin event handler
function actionBegin(args) {
if (args.requestType === 'save') {
console.log("Save action is getting executed");
var newData = args.data;
var ajax = new ej.base.Ajax({
url: "Index?handler=CustomActionCall",
type: "POST",
beforeSend: function (xhr) {
xhr.httpRequest.setRequestHeader("XSRF-TOKEN", $('input:hidden[name="__RequestVerificationToken"]').val());
},
contentType: "application/json; charset=utf-8",
// Current row data is sent in ajax request
data: JSON.stringify({ value: newData }),
});
ajax.onSuccess = result => {
// Success handler
}
ajax.send();
}
} |
|
public JsonResult OnPostCustomActionCall([FromBody]CustomAction dataValue)
{
var rowData = dataValue;
return new JsonResult(dataValue);
}
public class CustomAction
{
public OrdersDetails value { get; set; }
} |
|
[BindProperty]
public DateTime? availableDate_Selected { get; set; } |
Thank you for your feedback.
I was able to get the availableDate_Selected property working.
I am still struggling with the CRUD operation.
The page where I am implementing this grid is under Identity/Account/Manage/CapacityManagement .cshtml
<ejs-grid id="Grid" allowPaging="true" load="onLoad" toolbar="@( new List<object>() {"Edit","Update","Cancel"})">
<e-grid-editSettings allowEditing="true"></e-grid-editSettings>
<e-data-manager json="@Model.capacityList.ToArray()" adaptor="RemoteSaveAdaptor" updateUrl="CapacityManagement?handler=Update"></e-data-manager>
<e-grid-pagesettings pageSize="15"></e-grid-pagesettings>
<e-grid-columns>
<e-grid-column field="CapacityID" allowEditing="false" isIdentity="true" isPrimaryKey="true" type="number" headerText="CapacityID" width="0"></e-grid-column>
<e-grid-column field="CarrierName" allowEditing="false" headerText="Carrier" width="80"></e-grid-column>
<e-grid-column field="EquipmentName" allowEditing="false" headerText="Equipment" width="75"></e-grid-column>
<e-grid-column field="Quantity" allowEditing="false" headerText="Qty" type="number" width="75" format="N0"></e-grid-column>
<e-grid-column field="From" allowEditing="false" headerText="From" width="90"></e-grid-column>
<e-grid-column field="To" allowEditing="false" headerText="To" width="90"></e-grid-column>
<e-grid-column field="DateAvailable" allowEditing="false" headerText="Available Date" format="MM/dd/yy" width="90"></e-grid-column>
<e-grid-column field="CarrierComments" allowEditing="false" headerText="Carrier Commments" width="120"></e-grid-column>
<e-grid-column field="EquipmentUsed" allowEditing="true" headerText="Used Qty" type="number" validationRules="@(new { required=true, number=true})" width="55" format="N0"></e-grid-column>
<e-grid-column field="UsedComments" allowEditing="true" headerText="Commments" width="130"></e-grid-column>
@*<e-grid-column field="" headerText="Confirm Equipment" allowEditing="false" width="120" template="#template"></e-grid-column>*@
</e-grid-columns>
</ejs-grid>
The issue is that when the "Update" button is clicked on the grid, the method is not executed.
Checking the developers tools shows response code of 400 on the post method.
Methods for the Post:
public JsonResult OnPostDataSource([FromBody] Model dm)
{
//availableDate_Selected = null;
var capacityList = GetValue();
int count = capacityList.Cast< Model >().Count();
return new JsonResult(new { capacityList, count });
}
public JsonResult OnPostInsert([FromBody] CRUDModel< Model > value)
{
return new JsonResult(value.value);
}
Please advise how I can resolve the 400 error on the post method call.
Thank you
Thank you for your reply Sujith.
That was my error in what I posted on the forrum.
Below is my datagrid
<ejs-grid id="Grid" allowPaging="true" load="onLoad" toolbar="@( new List<object>() {"Edit","Update","Cancel"})">
<e-grid-editSettings allowEditing="true"></e-grid-editSettings>
<e-data-manager json="@Model.capacityList.ToArray()" adaptor="RemoteSaveAdaptor" updateUrl="CapacityManagement?handler=Update"></e-data-manager>
<e-grid-pagesettings pageSize="15"></e-grid-pagesettings>
<e-grid-columns>
<e-grid-column field="CapacityID" allowEditing="false" isIdentity="true" isPrimaryKey="true" type="number" headerText="CapacityID" width="0"></e-grid-column>
<e-grid-column field="CarrierName" allowEditing="false" headerText="Carrier" width="80"></e-grid-column>
<e-grid-column field="EquipmentName" allowEditing="false" headerText="Equipment" width="75"></e-grid-column>
<e-grid-column field="Quantity" allowEditing="false" headerText="Qty" type="number" width="75" format="N0"></e-grid-column>
<e-grid-column field="From" allowEditing="false" headerText="From" width="90"></e-grid-column>
<e-grid-column field="To" allowEditing="false" headerText="To" width="90"></e-grid-column>
<e-grid-column field="DateAvailable" allowEditing="false" headerText="Available Date" format="MM/dd/yy" width="90"></e-grid-column>
<e-grid-column field="CarrierComments" allowEditing="false" headerText="Carrier Commments" width="120"></e-grid-column>
<e-grid-column field="EquipmentUsed" allowEditing="true" headerText="Used Qty" type="number" validationRules="@(new { required=true, number=true})" width="55" format="N0"></e-grid-column>
<e-grid-column field="UsedComments" allowEditing="true" headerText="Commments" width="130"></e-grid-column>
@*<e-grid-column field="" headerText="Confirm Equipment" allowEditing="false" width="120" template="#template"></e-grid-column>*@
</e-grid-columns>
</ejs-grid>
And here is the code behind
public JsonResult OnPostUpdate([FromBody] CRUDModel<CapacityViewModel> value) // triggers when editing action is done
{
CapacityViewModel updateRecord = value.value;
bool isSucess = CapacityMethods.PostCapacityUsed(updateRecord.CapacityID, LoginViewModel.UserName, updateRecord.EquipmentUsed, updateRecord.UsedComments);
return new JsonResult(value.value);
}
The update method is not called at all when the update button is clicked.
Thank you
|
function actionFailure(args) {
console.log(args);
}
|