Current Data In Batch Mode

Hi,

Apologies if this has been asked before but I can't seem to find an answer on the forums.

I am using the Blazor grid component in batch mode (Mode="EditMode.Batch") and need to perform a calculation each time a row is updated but before they commit their changes. To achieve this I need the data (all rows, not just the edited one) as it is displayed on the screen.

Both DataSource and GetCurrentViewRecords return the data without the uncommitted changes. GetBatchChanges gets the changes split into collections i.e. AddedRecords, DeletedRecords and ChangedRecords.

Is there any way of retreiving the data for all rows as it appears on the screen before the changes are commited?

Thanks



4 Replies 1 reply marked as answer

OP Opap's August 11, 2020 11:30 AM UTC

I have the same issue. I can't seem to find a way to access the whole DataSource.


JP Jeevakanth Palaniappan Syncfusion Team August 11, 2020 01:12 PM UTC

Hi Karen/Opap, 
 
Greetings from Syncfusion Software 
 
Query: Is there any way of retrieving the data for all rows as it appears on the screen before the changes are commited 
 
You can achieve your requirement by modifying the GetCurrentViewRecords /DataSource records with the data retrieved in GetBatchChanges method. We have done the below customization by using the OnBatchSave event.  
 
Please check the below code snippet and the sample for your reference. 
 
<SfGrid @ref="DefaultGrid" DataSource="@Orders" AllowSorting="true" AllowPdfExport="true" AllowPaging="true" 
        Toolbar="@(new List<string>() { "Add","Edit","Delete","Update","Cancel"})"> 
    <GridEvents OnBatchSave="BatchSave" TValue="Order"></GridEvents> 
    .. 
    .. 
    .. 
</SfGrid> 
 
@code{ 
    private List<Order> CurrentView { get; set; } 
//It will have the Customized Data 
 
    private async Task BatchSave() { 
        var BatchChanges = await DefaultGrid.GetBatchChanges(); 
        CurrentView = await DefaultGrid.GetCurrentViewRecords(); 
//To do changes in whole datasource, use the DataSource property here 
 
        foreach (var record in (List<Order>)BatchChanges.ChangedRecords) 
        { 
            var ChangedData = CurrentView.Where(data => (data as Order).OrderID == record.OrderID).FirstOrDefault(); 
            (ChangedData as Order).CustomerID = record.CustomerID; 
            (ChangedData as Order).OrderDate = record.OrderDate; 
            (ChangedData as Order).Freight = record.Freight; 
        } 
        foreach (var record in (List<Order>)BatchChanges.AddedRecords) 
        { 
            CurrentView.Add(record); 
        } 
        foreach (var record in (List<Order>)BatchChanges.DeletedRecords) 
        { 
            CurrentView.Remove(record); 
        } 
    }  
} 
 
To customize the whole dataSource, modify the data with the help of DataSource property instead of GetCurrentViewRecords. 
 

Please get back to us if you need further assistance. 

Regards, 
Jeevakanth SP. 


Marked as answer

KA Karen August 13, 2020 08:17 AM UTC

Thats great, thanks Jeevakanth.


JP Jeevakanth Palaniappan Syncfusion Team August 14, 2020 05:26 AM UTC

Hi Karen, 

Thanks for the update. We are glad to know that your requirement is achieved. 

Kindly get back to us if you need further assistance. 

Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon