How to delete row with multi primary key?

HI,

Hello,

I need to remove a row with composite key and I'm not able to pass the second key as a parameter. I searched and saw some examples for the previous version and tried to apply it but it didn't work.

Can you help?


<e-grid-column field="id"

                                       headerText="id"

                                       textAlign="Left"

                                       isPrimaryKey="true"

                                       visible="false">

                        </e-grid-column>

                        <e-grid-column field="estoqueid"

                                       headerText="estoqueid"

                                       textAlign="Left"

                                       isPrimaryKey="true"

                                       visible="false">

                        </e-grid-column>




 function actionBeginDestGrid2(args) {

        if (args.requestType == 'delete') {

            args.model.dataSource.dataSource.headers = [];

            args.model.dataSource.dataSource.headers.push({ "id": args.data.id, "estoqueid": args.data.estoqueid });

        }

    }




3 Replies

RS Rajapandiyan Settu Syncfusion Team September 5, 2022 05:47 PM UTC

Hi Roberto,


Thanks for contacting Syncfusion support.


Query:  I need to remove a row with composite key and I'm not able to pass the second key as a parameter.


By default, the EJ2 grid does not have support for composite keys. All the CRUD actions are performed based on the first primaryKey field only. If you want to send additional value to the server while deleting a record, you can achieve it by using the addParams property of grid.query.


In actionBegin event (requestType as delete), we dynamically send the EmployeeID value to the server side.


actionBegin: https://ej2.syncfusion.com/javascript/documentation/api/grid/#actionbegin

Index.cshtml

 

    function actionBegin(args){

        if (args.requestType == "delete") {

            var grid = document.getElementById('Grid').ej2_instances[0];

            var EmployeeID = args.data[0].EmployeeID; // get the row data

            grid.query = new ej.data.Query().addParams('EmployeeID', EmployeeID); // send your own keys

        }

    }


Screenshot: Get the additional params at the server side


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/core_grid_delete_addparams-145254384.zip


Please get back to us if you need further assistance.


Regards,
Rajapandiyan S



RO Roberto September 5, 2022 09:45 PM UTC

hello,

It works,

thanks



RS Rajapandiyan Settu Syncfusion Team September 6, 2022 03:47 AM UTC

Hi Roberto,


We are happy to hear that you have achieved your requirement with the solution provided.


Please get back to us if you need further assistance.


Regards,

Rajapandiyan S


Loader.
Up arrow icon