Combobox does not load upon OnInitializedAsync

 
It works in 1st entity (customer) but does not worked on 2nd entity (item). both came from http client API

Here is the base
 protected async override Task OnInitializedAsync()
        {


            // Service fetch data from API
            Customers = (await CustomerService.GetCustomers()).OrderBy(e => e.CustomerName).ToList();
            StateHasChanged();


            Terms = (await TermService.GetTerms()).ToList();
            StateHasChanged();
         }



Here is the razor

  @*Customer*@
    <div class="col-lg-12 control-section">
        <div class="control_wrapper">
            <SfComboBox TItem="Customer" TValue="int" AllowCustom="false" Autofill="true" Placeholder=" Select Customer" CssClass="e-multi-column" AllowFiltering="true" DataSource="@Customers" PopupHeight="300px" @bind-Value="SOHeaderEditModel.CustomerID">
                <ComboBoxTemplates TItem="Customer">
                    <HeaderTemplate>
                        <table><tr><th class="e-text-center combo-width">Customer Code</th><th>Customer Name</th><th>Area</th></tr></table>
                    </HeaderTemplate>
                    <ItemTemplate Context="ComboContext">
                        <table><tbody><tr><td class="e-text-center combo-width">@((ComboContext as Customer).CustomerID)</td><td>@((ComboContext as Customer).CustomerName)</td><td>@((ComboContext as Customer).Area.AreaName)</td></tr> </tbody></table>
                    </ItemTemplate>
                </ComboBoxTemplates>
                <ComboBoxFieldSettings Value="CustomerID" Text="CustomerName"></ComboBoxFieldSettings>
            </SfComboBox>
        </div>
    </div>


    @*Term*@
    <div class="col-lg-12 control-section">
        <div class="control_wrapper">
            <SfComboBox TItem="Term" TValue="int" AllowCustom="false" Autofill="true" Placeholder=" Select Term" CssClass="e-multi-column" AllowFiltering="true" DataSource="@Terms" PopupHeight="300px" @bind-Value="SOHeaderEditModel.TermID">
                <ComboBoxTemplates TItem="Term">
                    <HeaderTemplate>
                        <table><tr><th class="e-text-center combo-width">Term Code</th><th>Term Name</th><th>Area</th></tr></table>
                    </HeaderTemplate>
                    <ItemTemplate Context="ComboContext">
                        <table><tbody><tr><td class="e-text-center combo-width">@((ComboContext as Term).TermID)</td><td>@((ComboContext as Term).TermName)</td><td>@((ComboContext as Term).Conversion.ToString())</td></tr> </tbody></table>
                    </ItemTemplate>
                </ComboBoxTemplates>
                <ComboBoxFieldSettings Value="TermID" Text="TermName"></ComboBoxFieldSettings>
            </SfComboBox>
        </div>
    </div>


Must be there is an alternative event for OnInitializedAsync()


Both entity list (Customer and term) works in datagrid. so there is no error in the  API service.. 


3 Replies 1 reply marked as answer

SN Sevvandhi Nagulan Syncfusion Team June 8, 2021 12:51 PM UTC

Hi Tyrone,  
  

Greetings from Syncfusion support. 

We checked your query.  We made the sample using provided code example and we were unable to replicate the reported issue at our end. We bound the data to the component in the OnInitializedAsync method for all of the combobox.  Please find the code example for your reference. 

protected async override Task OnInitializedAsync() 
    { 
        employeeCollection = await termsService.GetDataAsync(); 
        StateHasChanged(); 
        jobGroupsList = await ownservice.GetDataAsync(); 
        StateHasChanged(); 
    } 


Please find the sample below. 


In addition, we suggest that you to ensure the reported issue by adding some delay using Task.Delay method in C# to delay the server request and try binding the data source in method OnAfteRender method. 

It would be helpful if you modify above sample to replicate the issue. Otherwise, provide any additional information about the issue by comparing our sample with your application and whether you are using server/client application to investigate the issue further at our end. Additionally, share the .NET version, environment details and Syncfusion package version. 

Regards, 
Sevvandhi N 


Marked as answer

TY Tyrone June 9, 2021 02:48 PM UTC

Thanks Sevvandhi N. 

 await Task.Delay(1000); saved the day.. 


SN Sevvandhi Nagulan Syncfusion Team June 10, 2021 06:11 AM UTC

Hi Tyrone, 



We are glad to hear that the reported issue has been resolved. Please get back to us if you need further assistance. 



Regards, 
Sevvandhi N 


Loader.
Up arrow icon