I'm having an issue with the SfGrid in Batch mode.
When the event "OnCellSave" is triggered, two things can happen:
- if there's only one row (the same I'm editing), if I insert a metal and then I don't press Enter or Tab, but I just click on another field, I get errors.
- if I'm inserting a second row, when I select a metal, whatever I do, when "OnCellSaved" is triggered, I get errors and the grid crashes.
This makes impossible to use the event, but this event is also the only reason why I'm using the batch mode.
The grid is a bit complex, because it's on three levels, but the problem has nothing to do with this.
I tried to change the code in many ways and by doing it I found out that the problem is triggering the event "OnCellSave".
Indeed if I don't call the event, the issue doesn't persist.
I also tried to use "CellSaved" insted of "OnCellSave" as an event, but the result doesn't change.
I found an existing issue in the forum at this link:
It looks similar to my problem, and the related bug results solved:
I'm using version 19, so it should be fixed, but I still have this issue.
I'm attaching a zip folder with the screenshots of what I described (+ the expected behaviour) and the file with the grid and the event. The problematic grid is the one on the first level (not nested). Code as follows:
<SfGrid @ref="Grid" AllowPaging="true" DataSource="@TemporaryItemsData" Toolbar="@(new List<string>() { "Add","Delete","Update","Cancel" })">
<GridEvents CellSelected="CellSelectHandler" OnBatchAdd="BatchAddHandler" OnBatchSave="BatchSaveHandler" OnBatchDelete="BatchDeleteHandler" TValue="GroupedItemsDTO"></GridEvents>
<GridEditSettings AllowAdding="@IsEditingGroupedItemsAllowed" AllowEditing="@IsEditingGroupedItemsAllowed" AllowDeleting="@IsEditingGroupedItemsAllowed" Mode="@EditMode.Batch" ShowConfirmDialog="false"></GridEditSettings>
<GridSelectionSettings Mode=Syncfusion.Blazor.Grids.SelectionMode.Both></GridSelectionSettings>
<GridColumns>
<!-- Primary Key - Editing feature requires a primary key column for CRUD operations.-->
<GridColumn Field=@nameof(GroupedItemsDTO.Id) IsPrimaryKey="true" Visible="false" TextAlign="@TextAlign.Left" Width="140"></GridColumn>
<!-- Metallo -->
<GridColumn Field=Metal.Name Index="0" HeaderText="@Loc["Oncia_Items_Metal"]" Width="110" EditType="EditType.DropDownEdit">
<EditTemplate Context="context">
<SfDropDownList ID="Metal___Name" CssClass="e-custom-select" TItem="MetalDTO" TValue="string"
@bind-Value="@((context as GroupedItemsDTO).Metal.Name)" Placeholder="@Loc["Oncia_Items_Metal"]" DataSource="@MetalList">
<DropDownListEvents ValueChange="MetalOnChange" TItem="MetalDTO" TValue="string"></DropDownListEvents>
<DropDownListFieldSettings Text="Name" Value="Name"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
Here the function called by the event:
protected async Task CellSavedHandler(CellSaveArgs<GroupedItemsDTO> args)
{
if (args.ColumnName == "Metal.Name")
{
await GetExchangeRatePercentageList(args.Data.Metal.Name);
args.Data.ExchangeRatePercentage.DeltaValue = 0;
args.Data.Total = 0;
}
if (args.ColumnName == "GrossWeight" || args.ColumnName == "TareWeight")
{
if (args.Data.GrossWeight != null && args.Data.TareWeight != null && (args.Data.GrossWeight - args.Data.TareWeight > 0))
args.Data.NetWeight = args.Data.GrossWeight - args.Data.TareWeight;
if (args.Data.ExchangeRatePercentage != null && args.Data.ExchangeRatePercentage.DeltaValue != 0 && args.Data.NetWeight != null)
args.Data.Total = Decimal.ToDouble(args.Data.ExchangeRatePercentage.DeltaValue) * args.Data.NetWeight;
}
if (args.ColumnName == "ExchangeRatePercentage.DeltaValue")
if (args.Data.NetWeight != null)
args.Data.Total = Decimal.ToDouble(args.Data.ExchangeRatePercentage.DeltaValue) * args.Data.NetWeight;
}