Delete values in batch and cell mode by index

Hello,

In the sample project, I would like to be able to delete rows that contain selected cells. To do this, I have created a button named "Delete selected rows" which retrieves the selected rows and should delete them.

In the example (app.component.ts l.65) I use deleteRecord, but I also tried to use deleteRow with in input "tr Elements".

I don't want to delete rows based on their id because they don't always have one.
I would like to delete it in the cell and batch mode. That way I can click on the cancel button.

Thank you in advance for your answer.


Attachment: test_753f27ef.zip


3 Replies

RR Rajapandi Ravi Syncfusion Team December 3, 2021 12:40 PM UTC

Hi Willemin, 

Greetings from Syncfusion support 

From your update, we could see that you like to delete the records by using Toolbar button click. From checking your sample, we found that you are calling the deleteRecord() method by passing only one argument, but it requires two arguments. Please refer the below API and modified code example for more information. 


 
 
 
deleteSelectedRows(): void { 
    let selectedRows = this.grid.getSelectedRowCellIndexes() 
    let selectedObjects: any[] = []; 

    selectedRows.forEach(row => { 
      selectedObjects.push(this.grid.currentViewData[row.rowIndex]); 
    }); 

    selectedObjects.forEach(selectedObject => { 
      console.log(selectedObject); 
      this.grid.editModule.deleteRecord("id", selectedObject); 
    }); 
  } 


Regards, 
Rajapandi R 



WI Willemin December 3, 2021 01:14 PM UTC

Thank you for your answer.

I knew that I had to enter a fieldname and its corresponding data. I had explained my problem wrong.
I would like to be able to delete an entity from its index.
Knowing that all the values of my entity are nullable.

For example my grid contains :

{ name: theo, age: 41 },
{ name: lea, age: 69 },
{ name: null, age: 71 },
{ name: antoine, age: null },
{ name: null, age: null }]

I would like to from an index, delete an entity. I would also like the deletion to be done in the code.
The grid is in batch and cell mode.
The user should be able to click on cancel/save to validate or not the modifications.



RR Rajapandi Ravi Syncfusion Team December 4, 2021 10:33 AM UTC

Hi Willemin, 

Thanks for the update 

We have checked your shared information and we could see that you are not having primarykey field in your Grid. By default, in our EJ2 Grid, you can delete the record by defining the primaryKey field in the delete record argument, you are not able to delete the record from an index, without having primarykey in the Grid datasource you are not able to perform the CRUD action in the Grid. Please refer the below documentation for more information. 


In your query you have mentioned that “The user should be able to click on cancel/save to validate or not the modifications.” So please share the details about this query and explain your scenario step by step with detailed description. 

Regards, 
Rajapandi R 


Loader.
Up arrow icon