Update in Parent grid and Insert in Child Grid not working

I am working on creating a EJ2 data grid with a child grid within it. I am using a local database so I am using the RemoteSaveAdaptor to perform the CRUD operations server side in the controller for both of the parent and child grid. Before adding the child grid, all 3 of the CRUD operations were working for the parent grid. After adding the child grid, the update function isn't working properly. It is getting called but the value is null. In the child grid, The update and delete functions are working correctly but the insert function isn't working properly. It is having the same issue as the parent edit function which is the value is coming in null. I am at a loss as to where to go from here. They are set up exactly like examples and documentation I have found during my research. I have attached the relevant files below. Thank you in advance for your help.

Dana

Attachment: DataGridDemo_99e33c41.zip

3 Replies 1 reply marked as answer

RR Rajapandi Ravi Syncfusion Team January 15, 2021 10:06 AM UTC

Hi Dana, 

Greetings from syncfusion support 

We have analyzed your query and we understand you are using Hierarchical Grid with remote save adaptor and facing the problem with CRUD actions. Based on query we have prepared a sample and tried to reproduce your reported problem. But its working fine from our end. Please refer the below code example, sample for more information. 

 
@{ 
    var ChildGrid = new Syncfusion.EJ2.Grids.Grid() 
    { 
        DataSource = new Syncfusion.EJ2.DataManager() { Json = ViewBag.child, Adaptor = "RemoteSaveAdaptor", InsertUrl = "/Home/Insertchild", UpdateUrl = "/Home/Updatechild", RemoveUrl = "/Home/Deletechild" }, 
        Id = "ChildGrid", 
        QueryString = "EmployeeID", 
        ActionBegin = actionBeginChild, 
        Toolbar = toolbarItems, 
        EditSettings = new Syncfusion.EJ2.Grids.GridEditSettings() { AllowAdding = true, AllowEditing = true, AllowDeleting = true }, 
        Columns = new List<Syncfusion.EJ2.Grids.GridColumn> { 
new Syncfusion.EJ2.Grids.GridColumn(){ Field="OrderID", IsPrimaryKey=true, HeaderText="Order ID", Width="150" }, 
new Syncfusion.EJ2.Grids.GridColumn(){ Field="FirstName", HeaderText="First Name", Width="150" }, 
new Syncfusion.EJ2.Grids.GridColumn(){ Field="LastName", HeaderText="Last Address", Width="120" }, 
} 
    }; 
} 
 
<script> 
    function actionBeginChild(args) { 
        var childInstance = this; 
        console.log(childInstance); 
        if (args.requestType === "add") { 
            // `parentKeyFieldValue` refers to the queryString field value of the parent record. 
            args.data.EmployeeID = this.parentDetails.parentKeyFieldValue; 
        } 
    } 
</script> 
 
<ejs-grid id="Grid" childGrid="ChildGrid" allowSorting="true" toolbar="@(new List<string>() { "Add","Delete","Update", "Cancel" })"> 
    <e-data-manager json="@ViewBag.dataSource" adaptor="RemoteSaveAdaptor" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Delete"></e-data-manager> 
    <e-grid-editSettings allowDeleting="true" allowEditing="true" allowAdding="true"></e-grid-editSettings> 
    <e-grid-columns> 
        .  .  .  .  .  .  .  .  . 
        .  .  .  .  .  .  .  .  . 
   </e-grid-columns> 
</ejs-grid> 
 


Regards,
Rajapandi R 


Marked as answer

DK Dana Kiehl January 15, 2021 04:02 PM UTC

Thanks for you response. I was able to get the Update function for the parent grid and at least last night the insert for the child grid was working. However, once I got both of those working the Insert function for the parent grid stopped working with the value coming in as null and this morning the Insert function for the child grid stopped working again with the value coming in as null. I have not made any changes to my code this morning, it is exactly how it was last night when the insert function for the child grid was working. I have attached an updated version of my files.

Thanks,
Dana

Attachment: DataGridDemo_(2)_406d4c1b.zip


RR Rajapandi Ravi Syncfusion Team January 18, 2021 12:15 PM UTC

Hi Dana, 

Thanks for the update 

The reported problem was occurring when the ‘isIdentity’ is enabled for the primary key column, the Grid will send ‘null’ value for this column on performing add operation(considering this value will be generated in the data base). Now as the Insert CRUD method in the .cs file expects an integer value for the primary key data field and ‘null’ value is sent for this case, the values will not be properly received in the CRUD method arguments. 

So you can resolve this by giving nullable type for this primary key field in the Model definition as demonstrated in the below code snippet, 

Rules.cs 

public class Rules 
    { 
        [Key] 
        public int? RuleId { get; set; } 
        public string RuleDescription { get; set; } 
        public int sortSequence { get; set; } 
    } 

RulesVersions.cs 

public class RulesVersions 
    { 
        [Key] 
        public int? VersionId { get; set; } 
        public DateTime NBStartDate { get; set; } 
        .  .  .  .  .  .  .  .  .  .  
        .  .  .  .  .  .  .  .  .  . 
   } 

Regards,
Rajapandi R 


Loader.
Up arrow icon