search not showing matching items in dropdown, instead it shows add new item option

i would like to show matching items in dropdwon if there are any matching items

<SfComboBox @ref="@ComboObjCountry" TValue="string" Placeholder="Select a country" TItem="Country" DataSource="@countries" AllowCustom="true" AllowFiltering="true" @bind-Value=etlMetadata.CountryName FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains">

    <ComboBoxFieldSettings Text="CountryName" Value="CountryName"></ComboBoxFieldSettings>

    <ComboBoxEvents TValue="string" Filtering="@OnFilteringCountry" TItem="Country" ValueChange="countryChanged" />

    <ComboBoxTemplates TItem="Country">

        <NoRecordsTemplate>

            <div>

                <div id="nodata">No matched item, would you like to add it to the list as a new item?</div>

                <SfButton id="btn" class="e-control e-btn custom-button" @onclick="@AddCountry">Add New Item</SfButton>

            </div>

        </NoRecordsTemplate>

    </ComboBoxTemplates>

</SfComboBox>

<ValidationMessage For="@(() => etlMetadata.CountryName)" />

 private async Task OnFilteringCountry(Syncfusion.Blazor.DropDowns.FilteringEventArgs args)

 {

     Custom = args.Text;

     args.PreventDefaultAction = true;

     var query = new Query().Where(new WhereFilter() { Field = "Name", Operator = "contains", value = args.Text, IgnoreCase = true });

     query = !string.IsNullOrEmpty(args.Text) ? query : new Query();

     await ComboObjCountry.FilterAsync(countries, query);

 }


2 Replies 1 reply marked as answer

JK jose KJ January 21, 2025 11:33 AM UTC

issue was i used Name instead of CountryName
here  `var query = new Query().Where(new WhereFilter() { Field = "Name", Operator = "contains", value = args.Text, IgnoreCase = true });


Marked as answer

UD UdhayaKumar Duraisamy Syncfusion Team January 22, 2025 05:41 PM UTC

Thank you for the update. You're correct that the issue was caused by using "Name" instead of "CountryName" in the WhereFilter. Since the ComboBoxFieldSettings is configured to use "CountryName" for both the Text and Value fields, the filtering logic should reference the same field name.
To resolve the issue, you can update the OnFilteringCountry method as follows:
private async Task OnFilteringCountry(Syncfusion.Blazor.DropDowns.FilteringEventArgs args)
{
    Custom = args.Text;
    args.PreventDefaultAction = true;

    var query = new Query().Where(new WhereFilter()
    {
        Field = "CountryName", // Correct field name
        Operator = "contains",
        value = args.Text,
        IgnoreCase = true
    });

    query = !string.IsNullOrEmpty(args.Text) ? query : new Query();
    await ComboObjCountry.FilterAsync(countries, query);
}

This adjustment ensures that the filtering logic matches the configuration of your ComboBox, and matching items should now display correctly in the dropdown.

Loader.
Up arrow icon