Inline Editing and datepicker issue

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


6 Replies

SK Sujith Kumar Rajkumar Syncfusion Team January 24, 2022 03:00 PM UTC

Hi Segal, 
 
Greetings from Syncfusion support. 
 
Please find the response for your queries below, 
 
Query – 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)” 
 
We are currently validating this query from our end and we will provide the further details on or before 27th January 2022. 
 
Until then your patience is appreciated. 
 
Query – 2: “Please advise how using c# can I write the method in the .cs page on razor page when the "save" button is clicked?” 
 
When the Grid save button is clicked the following events – actionBegin, actionComplete will be triggered in the client side which need to be defined in the cshtml page. So if you need to access the .cs page method there you can use ajax call to achieve the same. 
 
This is demonstrated in the below code snippet where the EJ2 base’s ajax method is used to call the required controller action method(from grid’s actionBegin event on save) in razor page, 
 
// 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(); 
    } 
} 
 
 
Controller 
public JsonResult OnPostCustomActionCall([FromBody]CustomAction dataValue) 
{ 
    var rowData = dataValue; 
    return new JsonResult(dataValue); 
} 
 
public class CustomAction 
{ 
    public OrdersDetails value { get; set; } 
} 
 
 
Please find the below sample prepared based on this for your reference, 
 
 
Regards, 
Sujith R 



SK Sujith Kumar Rajkumar Syncfusion Team January 25, 2022 04:56 AM UTC

Hi Segal, 
 
Thanks for your patience. 
 
We suspect that the BindProperty filter might not be added to the availableDate_Selected property in the PageModel causing the reported problem. 
 
This is demonstrated in the below code snippet and sample for your reference, 
 
[BindProperty]  
public DateTime? availableDate_Selected { get; set; }  
 
 
Let us know if you have any concerns. 
 
Regards, 
Sujith R 



SS Sejal Sheth January 26, 2022 04:13 AM UTC

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



SK Sujith Kumar Rajkumar Syncfusion Team January 27, 2022 11:40 AM UTC

Hi Sejal,

From the shared code snippet we could see that you have set the update url property value as – “CapacityManagement?handler=Update” but the update method name is defined as – “OnPostInsert”. So please modify the update url property with the proper value as – “CapacityManagement?handler=Insert” to resolve the problem.

Let us know if you have any concerns.

Regards,
Sujith R




SS Sejal Sheth January 27, 2022 02:33 PM UTC

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



RS Rajapandiyan Settu Syncfusion Team January 28, 2022 10:57 AM UTC

Hi Sejal, 

Greetings from Syncfusion support. 

We are tried to reproduce the reported behavior with the provided code example, but it was unsuccessful at our end. Find the below sample for your reference. 


Kindly share the below details to validate further. 

  1. Bind the actionFailure event in Grid and let us know if you face any exceptions or errors in that event.
 

    function actionFailure(args) { 
        console.log(args); 
    } 


  1. Share the Grid script version and program.cs file.
  2. Share the video demo and screenshot of the reported problem .
  3. If possible share a simple issue reproducible sample which will be very helpful to provide a solution at earlier.

Regards, 
Rajapandiyan S 


Loader.
Up arrow icon