Two way binding with OnRead in 3.0

1 Answer 60 Views
ComboBox
Rob
Top achievements
Rank 1
Iron
Veteran
Rob asked on 20 Jan 2022, 06:36 PM

I'm trying to programmatically change the value of an existing ComboBox to something that's not in the last OnRead args.Data list.  Is there a way for me to achieve this and populate the TextField? The only way I can see is to destroy the control and remake it, triggering the initialization OnRead. 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 25 Jan 2022, 08:59 AM | edited on 25 Jan 2022, 05:38 PM

Hello Rob,

In UI for Blazor 3.1 (due in early March) we will add a method to reload data when using OnRead.

In the meantime, it is possible to do this in two ways:

  • recreate the component, as you have already tried
  • toggle the ValueField of the component - I agree this is not a very ingenious approach, but I am mentioning it in case you find this more convenient for your scenario

 

<TelerikComboBox OnRead="@OnComboRead"
                 ValueField="@ComboValueField" />

@code{
    string ComboValueField { get; set; } = "Id";

    async Task RefreshCombo()
    {
        ComboValueField = "Name";
        await Task.Delay(1);
        ComboValueField = "Id";
    }

    async Task OnComboRead(ComboBoxReadEventArgs args)
    {
        if (ComboValueField == "Id")
        {
            var result = await MyService.GetItems(args.Request);

            args.Data = result.Data;
            args.Total = result.Total;
        }
    }
}

 

Regards,
Dimo
Progress Telerik

Learn about the important changes coming in UI for Blazor 3.0 in January 2022!
Rob
Top achievements
Rank 1
Iron
Veteran
commented on 25 Jan 2022, 05:13 PM

Thanks Dimo, I'll continue migrating the rest to be ready for 3.1 then!
Tags
ComboBox
Asked by
Rob
Top achievements
Rank 1
Iron
Veteran
Answers by
Dimo
Telerik team
Share this question
or