Delete Multiple Records (Noob Question)

Hi SyncFusion

Usually I wouldn't ask - but I spend a fair few hours on your forums looking for a solution.
I want to be able to delete many records simultaneously from a grid. 

This is the column 

<GridColumn Visible="editinggrid" Type="ColumnType.CheckBox" Width="20"></GridColumn>

AllowSelection is true
Mode is Mode="EditMode.Batch" 
GridSelectionSettings Type is "SelectionType.Multiple"

This is the event that fires when Delete is clicked from the toolbar

 <GridEvents OnBatchDelete="BatchDelete" TValue="ResourceForGridDTO"></GridEvents>

    public async void BatchDelete(BeforeBatchDeleteArgs<ResourceForGridDTO> args)
    {
        ResourceLibraryDTO resourcelibrary = await apiService.GetResourceLibraryAsync(args.RowData.ResourceId, library.LibraryId);
        var userId = await ProtectedLocalStore.GetAsync<Guid>("userId");
        resourcelibrary.Void = true;
        resourcelibrary.ModifiedBy = userId;
        await apiService.UpdateResourceLibrary(resourcelibrary);
        await ShowSuccessToast("Success", "Successfully removed the resource");

    }

This works for one record, but not all the selected records.
I can't for the life of me figure out how to do this, I tired  var selectedRecords = ResourcesGrid.GetSelectedRows(); (the grid is @ref to ResourcesGrid)
But it can't find any selected rows.
Help or a general steer in the right direction would be highly appreciated

John


4 Replies 1 reply marked as answer

PS Pavithra Subramaniyam Syncfusion Team June 15, 2020 09:29 AM UTC

Hi John, 
 
You can get the records to be deleted inside the “OnBatchDelete” event using the “GetSelectedRecords” method. Please refer to the below code example and sample link for more information. 
 
public async void BatchDelete(BeforeBatchDeleteArgs<Order> args) 
    { 
        var deletedRecords = await this.Grid.GetSelectedRecords(); 
    } 
 
 
 
 
Please get back to us if you have any concern. 
 
Regards, 
Pavithra S 


Marked as answer

JO John June 17, 2020 09:28 AM UTC

Thanks! I was just missing the await :)

I still can't for the life of me understand how to access the selected record so I can update it

        var selectedRecords = await this.ResourcesGrid.GetSelectedRows();
        foreach (var record in selectedRecords)
        {
            string thisstring = record.ID;
            int resourceId = args.RowData.ResourceId;
        }

args.RowData.ResourceId is always the same and Record.ID is always null.
Any advice appreciated 


JO John June 17, 2020 09:32 AM UTC

Actually ignore that..,. I should have used  var selectedRecords = await this.ResourcesGrid.GetSelectedRecords();
Thanks :)
Working now!


RN Rahul Narayanasamy Syncfusion Team June 18, 2020 05:02 AM UTC

Hi John, 
 
Thanks for the update. 
 
Please get back to us if you need further assistance. 
 
Regards, 
Rahul 


Loader.
Up arrow icon