havit / Havit.Blazor

Free Bootstrap 5 components for ASP.NET Blazor + optional enterprise-level stack for Blazor development (gRPC code-first, layered architecture, localization, auth, ...)
https://havit.blazor.eu
MIT License
475 stars 66 forks source link

HxGrid Inline Editing ValueChanged on HxInputNumber #754

Closed bluisanajmr closed 6 months ago

bluisanajmr commented 6 months ago

I have an HxGrid with inline editing. Everything works great up until the point where I wanted to create a valuechanged event for one of the inline HxInputNumber fields.

<HxGridColumn HeaderText="Quantity">
    <ItemTemplate Context="InvoiceLineItemContext">
        @if (edititem == InvoiceLineItemContext)
        {
            <HxInputNumber TValue="Decimal" Value="@InvoiceLineItemContext.Quantity" ValueExpression="() => InvoiceLineItemContext.Quantity" ValueChanged="calculatequantity" Decimals="2" />
        }
        else
        {
            <div>@InvoiceLineItemContext.Quantity.ToString("c0")</div>
        }
    </ItemTemplate>
</HxGridColumn>

All of my other fields are using a simple bind like this.

 <HxGridColumn HeaderText="Price">
     <ItemTemplate Context="InvoiceLineItemContext">
         @if (edititem == InvoiceLineItemContext)
         {
             <HxInputNumber @bind-Value="InvoiceLineItemContext.Price" Decimals="2" InputGroupStartText="$" />
         }
         else
         {
             <div>@InvoiceLineItemContext.Price.ToString("c0")</div>
         }
     </ItemTemplate>
 </HxGridColumn>

The quantity inputnumber field renders but I am unable to get a value to bind in it. Any number that I enter into the inputnumber field changes back to 0 as soon as I move out of the field.

hakenr commented 6 months ago

How does your calculatequantity method look like? You have to save the value to the model there. In this setup I would strongly recommend using bind-Value="InvoiceLineItemContext.Quantity" bind-Value:after="calculatequantity" instead of ValueChanged.

bluisanajmr commented 6 months ago

Thanks Hadenr, bine-value:after worked perfectly.