Welcome to the Blazor feedback portal. We’re happy you’re here! If you have feedback on how to improve the Blazor, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

1
Vote

Hello,

I have a SfTreeGrid that has editable decimal columns like this simplified version :


<SfTreeGrid @ref="mcomp_SFTreeGrid"
            DataSource="@DataSource"
            IdMapping="@IdMapping"
            ParentIdMapping="@ParentIdMapping"
            TreeColumnIndex="@TreeColumnIndex"
            AllowSelection="@AllowSelection"
            AllowSorting="true"
            AllowResizing="true"
            AllowReordering="true"
            ShowColumnChooser="true"
            ShowColumnMenu="true"
            TValue="TItem"
            Height="100%"
            ClipMode="ClipMode.Clip"
            GridLines="GridLine.Both">
    <TreeGridEvents TValue="TItem"
                    CellSelected="(e) => OnCellSelected(e)"
                    CellSaved="(e) => OnCellSaved(e)"></TreeGridEvents>
    <TreeGridSelectionSettings Mode="SelectionMode.Both"></TreeGridSelectionSettings>
    <TreeGridEditSettings AllowEditing="AllowEditing"
                          AllowAdding="AllowAdding"
                          AllowDeleting="AllowDeleting"
                          Mode="Syncfusion.Blazor.TreeGrid.EditMode.Batch"
                          AllowEditOnDblClick="true"
                          ShowConfirmDialog="false" />
    <TreeGridColumns>
<TreeGridColumn Field="Quantity"
HeaderText="@_Localizer["Quantité"]"
AllowEditing="true"
EditType="Syncfusion.Blazor.Grids.EditType.NumericEdit">
</TreeGridColumn>
<TreeGridColumn Field="Price"
  HeaderText="@_Localizer["Prix (HT)"]"
AllowEditing="true"
EditType="Syncfusion.Blazor.Grids.EditType.NumericEdit">
</TreeGridColumn>

<TreeGridColumn Field="Discount"
 HeaderText="@_Localizer["Remise (HT)"]"
 AllowEditing="true"
 EditType="Syncfusion.Blazor.Grids.EditType.NumericEdit">
</TreeGridColumn>
<TreeGridColumn Field="DiscountPercent"
 HeaderText="@_Localizer["Remise % (HT)"]"
 AllowEditing="true"
 EditType="Syncfusion.Blazor.Grids.EditType.NumericEdit">
</TreeGridColumn>
    </TreeGridColumns>
</SfTreeGrid>


@code {
protected async Task OnCellSaved(
Tuple<string, OrderProductDataModel> ptup_ColumnSaved)
    {
        if (ptup_ColumnSaved != null )
        {
            string vstr_ColumnName = ptup_ColumnSaved.Item1;
            OrderProductDataModel vobj_UpdatedProduct = ptup_ColumnSaved.Item2;
            if (mcomp_TreeGridExtension != null &&
                !string.IsNullOrEmpty(ptup_ColumnSaved.Item1) &&
                vobj_UpdatedProduct != null)
            {
                switch (vstr_ColumnName)
                {
                    case "DiscountPercent":
                        await vobj_UpdatedProduct.UpdateDiscountAmount(vobj_UpdatedProduct.DiscountPercent ?? 0);
                        break;
                    case "Discount":
                        await vobj_UpdatedProduct.UpdateDiscountPercent(vobj_UpdatedProduct.Discount ?? 0);
                        break;
                    default:
                        break;
                }
List<double> vlst_Indexes = await mcomp_SFTreeGrid.GetSelectedRowIndexesAsync();
await mcomp_SFTreeGrid.UpdateRowAsync(vlst_Indexes.FirstOrDefault(), pobj_EditedItem);
            }
        }
    }
}

 Sometimes, when I update the Row via UpdateRowAsync, I get the following error:

Error: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Nullable`1[System.Decimal]'.

   at Syncfusion.Blazor.Grids.Internal.NumericEditCell`1.BuildRenderTree(RenderTreeBuilder __builder)

   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)

   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)

   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()



it started since I added the calculation of the percentage fields to fill in the amount and vice versa (UpdateDiscountAmount & UpdateDiscountPercent) in CellSaved : 

        public async Task UpdateDiscountPercent(decimal pdec_DiscountAmount)
        {
            if ((this.Price * this.Quantity * this.Coefficient) != 0)
            {
                this.DiscountPercent = pdec_DiscountAmount / (this.Price * this.Quantity);
            }
            else
            {
                this.DiscountPercent = 0;
            }
        }


        public async Task UpdateDiscountAmount(decimal pdec_DiscountPercent)
        {
            this.Discount = (pdec_DiscountPercent * this.Price * this.Quantity) / 100;
        }

What did I do wrong?


Thank you for your help

Regards

Avanti