Radzen Data Grid - How to set currency based on drop downselection?

I have a Blazor Server Application, There is this currency dropdown on the Radzen data grid. I want to change the Unit Cost currency based on selection. The problem is, If I change one of the row's currencies, all of the row's currencies are set to the selected ones'. How can I fix this?

Blazor related portion

...
<RadzenDataGridColumn TItem="OrderDetail" Property="UnitCost" Title="Unit Cost">
                                <EditTemplate Context="orderDetail">
                                    @*<RadzenNumeric TValue="double" Min="1" @bind-Value="orderDetail.UnitCost" Style="width: 100%; display: block" Name="UnitCost"/>
                                    <RadzenRequiredValidator Text="Unit Cost is required" Component="UnitCost" Popup="true" Style="position: absolute"/>*@
                                    @switch (SelectedCurrency)
                                    {
                                        case "Dolar":
                                            @string.Format(new CultureInfo("en-US"), "{0:C}", orderDetail.BuyQuantity * orderDetail.CostRatio)
                                            break;
                                        case "Euro":
                                            @string.Format(new CultureInfo("en-FR"), "{0:C}", orderDetail.BuyQuantity * orderDetail.CostRatio)
                                            break;
                                        default:
                                            @string.Format(new CultureInfo("tr-TR"), "{0:C}", orderDetail.BuyQuantity * orderDetail.CostRatio)
                                            break;
                                    }
                                </EditTemplate>
                                <Template Context="detail">
                                    @switch (SelectedCurrency)
                                    {
                                        case "Dolar":
                                            @string.Format(new CultureInfo("en-US"), "{0:C}", detail.BuyQuantity * detail.CostRatio)
                                            break;
                                        case "Euro":
                                            @string.Format(new CultureInfo("en-FR"), "{0:C}", detail.BuyQuantity * detail.CostRatio)
                                            break;
                                        default:
                                            @string.Format(new CultureInfo("tr-TR"), "{0:C}", detail.BuyQuantity * detail.CostRatio)
                                            break;
                                    }
                                </Template>
                                @*<FooterTemplate>
                                    <b>@string.Format(new CultureInfo("en-US"), "{0:C}", SelectedOrders?.FirstOrDefault()?.OrderDetails.Sum(o=>o.BuyQuantity * o.CostRatio))</b>
                                </FooterTemplate>*@
                            </RadzenDataGridColumn>

@code {
    
    [Parameter]
    public string SelectedCurrency { get; set; }

    readonly List<string> currency = new() { "TL", "Dolar", "Euro"};

    IList<Order?> SelectedOrders { get; set; }
    
    IEnumerable<Order?> _orders = new List<Order?>();
    IEnumerable<Vendor?> _vendors;

    RadzenDataGrid<Order?> _grid;
    RadzenDataGrid<OrderDetail> _gridDetail;

    protected override async Task OnInitializedAsync()
    {
        _orders = await ViewAllOrdersUseCase.ExecuteAsync();
        SelectedOrders = new List<Order?> { _orders.FirstOrDefault() };

        _vendors = await ViewAllVendorsUseCase.ExecuteAsync();

    }
    private void OnChange(object args)
    {
        SelectedCurrency = args.ToString();
    }

You use a variable available for the entire page, while you need one related to the data item.

:slight_smile: Oh I see, thank you @enchev. Is there a practical way to reach my goal that you can suggest?

You can extend the data item with additional property or you can have a Dictionary with Key/Value representing the data item and the selected currency/culture.

I did not fully understand. Could you please elaborate on what you mean by extending the data item? @enchev

1 Like

Thank you, I will set the SelectedCurrency to the extended property and check this extended property.

One more support @enchev :slight_smile: I asked a lot of questions today. I extended the data and here is how I try to bind SelectedCurrency.

 <RadzenDataGridColumn TItem="OrderDetail" Property="ExtendedCurrency" Title="ExtendedCurrency" @bind-Value="@SelectedCurrency"/>

I am getting this error;

System.InvalidOperationException: Object of type 'Radzen.Blazor.RadzenDataGridColumn`1[[IMS.CoreBusiness.OrderDetail, IMS.CoreBusiness, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' does not have a property matching the name 'Value'.

There is no Value property available for DataGrid columns.

Ops :slight_smile: Is it possible to get the order detail id from the OnChange dropdown? Somehow I have to set SelectedCurrency to the ExtendedCurrency in the code :slight_smile:

...
 <RadzenDataGridColumn TItem="OrderDetail" Property="Currency" Title="Currency">
                                <EditTemplate Context="orderDetail">
                                   <RadzenDropDown AllowClear="true" TValue="string" Class="w-100" Data=@currency @bind-Value="orderDetail.Currency" Name="Currency" Change=@(args => OnChange(args))/>
                                    <RadzenRequiredValidator Text="Currency is required" Component="Currency" Popup="true" Style="position: absolute"/>
                                </EditTemplate>
                            </RadzenDataGridColumn>
....
private void OnChange(object args)
    {
        SelectedCurrency = args.ToString();
       
    }

@enchev Actually something like this what I want, but I don't get what is context.

Change=@(args => OnChange(args, order.OrderDetails.IndexOf(context)))

Here is the context, you can pass it to OnChange

1 Like

Thank you for the perfect support. Glad I chose Radzen. @enchev