How to delete a record from a gird that has multiple primary keys

I have a grid and the records in it use two fields to make up the primary key. How can I pass both field values to the controller so that I can make sure I delete the correct record? My code is below:

@Html.EJS().Grid("ContainerGrid").DataSource(DataManager => { DataManager.Json(@Model.ContainerTransactions.ToArray()).InsertUrl("Home/AddContainerItem").UpdateUrl("Home/UpdateContainerItem").RemoveUrl("Home/DeleteContainerItem").Adaptor("RemoteSaveAdaptor"); }).Width("auto").Columns(col =>

        {

            col.Field("InventoryID").HeaderText("Item").IsPrimaryKey(true).Width("40").EditType("dropdownedit").Edit(new { @params = itemDropDown }).ValidationRules(new { required = true }).Add();

            col.Field("ContainerID").ValueAccessor(containerAccessor).IsPrimaryKey(true).Visible(false).Add();

            col.Field("Description").HeaderText("Description").ValueAccessor(descriptionAccessor).Width("90").Add();

           ...


        }).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(new List<string>() { "Add", "Edit","Delete" }).Render()



4 Replies

SK Sujith Kumar Rajkumar Syncfusion Team August 3, 2021 12:49 PM UTC

Hi Danyelle, 
 
Greetings from Syncfusion support. 
 
Based on the provided information we could understand that your requirement is to send additional data in the server request on deleting a record. You can achieve it by using the Grid’s actionBegin event(triggers on performing delete action) and set the required data value to the Grid’s query property. 
 
This is demonstrated in the below code snippet, 
 
// Grid’s detailDataBound event handler 
function onActionBegin(args) { 
   if (args.requestType === 'delete') { 
       // Condition executes on performing delete action 
       this.query = new ej.data.Query().addParams('CustomerID', args.data[0]["CustomerID"]); 
   } 
} 
 
On doing this the additional data will be send along with the request as shown in the below image, 
 
 
 
 
And it can be accessed in the server side as shown in the below code, 
 
public ActionResult Delete([FromBody]CRUDModel1<OrdersDetails> dm) 
{ 
    // The additional value sent in query can be accessed here 
    var queryValue = dm.CustomerID; 
        ... 
} 
 
public class CRUDModel1<OrdersDetails> 
{ 
              ... 
    public string CustomerID { get; set; } 
} 
 
We have prepared a sample based on this for your reference. You can find it below, 
 
 
More details on the query property can be checked in the below documentation link, 
 
 
 
Please get back to us if you require any further assistance. 
 
Regards, 
Sujith R 



DA Danyelle August 3, 2021 01:52 PM UTC

How would I pass two parameters?

  this.query = new ej.data.Query().addParams('CustomerID', args.data[0]["CustomerID"]); 

  this.query = new ej.data.Query().addParams('InventoryID', args.data[0]["InventoryID"]); 



DA Danyelle August 3, 2021 02:02 PM UTC

I figured it out. 

this.query = new ej.data.Query().addParams('ContainerID'args.data[0]["ContainerID"]).addParams('CreatedDate'args.data[0]["CreatedDate"]);


BS Balaji Sekar Syncfusion Team August 5, 2021 02:32 AM UTC

Hi Danyelle,  
  
We are happy that the problem has been solved.  
  
Please get back to us if you need any further assistance.   
                           
Regards,  
Balaji S. 


Loader.
Up arrow icon