Hello,
i want to bind the autocomplete to a list of object. But the data in the template is empty:
The code is this:
Kunde:
<TelerikAutoComplete Data="@DataCustomer" TItem="@Customer" ValueChanged="@((string value) => OnComboCustomerValueChanged(value))">
<ItemTemplate>
@(nameof(Customer.customerName))
</ItemTemplate>
<FooterTemplate>
<h6>Anzahl: @DataCustomer.Count()</h6>
</FooterTemplate>
<NoDataTemplate>
<div class="no-data-template">
<TelerikSvgIcon Icon="@SvgIcon.FilesError" Size="@ThemeConstants.SvgIcon.Size.Large"></TelerikSvgIcon>
<p>No items available</p>
</div>
</NoDataTemplate>
</TelerikAutoComplete>
protected override async Task OnInitializedAsync()
{
List<Customer> customers = new List<Customer>();
customers.Add(new Customer()
{
customerId = "",
customerName = ""
});
DataCustomer = customers;
}
private void OnComboCustomerValueChanged(string value)
{
ComboCustomerValue = value;
if (value != null && value.Length > 3)
{
if (DataCustomer == null)
{
List<Customer> Data = new List<Customer>();
}
if (DataCustomer.FirstOrDefault(item => item.customerId == value.ToString()) == null)
{
IO.Swagger.Api.CustomerApi customerApi = new IO.Swagger.Api.CustomerApi("https://server:8080");
foreach (var itemsFound in customerApi.ApiV1CustomerIdGet(Convert.ToInt32(value)))
{
if (DataCustomer.FirstOrDefault(item => item.customerId == itemsFound.Id.ToString()) == null)
{
DataCustomer.Add(new Customer()
{
customerId = itemsFound.Id.ToString(),
customerName = itemsFound.Name + @" (" + itemsFound.Id.ToString() + @")"
});
}
}
}
}
}
What have i made wrong?
Kind regards
Jens