Event of Filtering ListBox

I want to use Sftextbox in another location as an alternative to the default Filtering Sflistbox and have the same functionality as Filtering SfListbox. How can I do?


z5531658872796_0c1c5852d9fe61ec7468243306943b85.jpg


1 Reply 1 reply marked as answer

KV Keerthikaran Venkatachalam Syncfusion Team June 13, 2024 04:47 PM UTC

Hi Phúc,


Thank you for reaching out to Syncfusion Support.


We have checked the reported query, and you can utilize the FilterAsync method of the listbox to filter its data based on the query provided. Please refer to the below code snippets and samples.


<SfTextBox Input="@InputHandler"></SfTextBox>

 

<SfListBox TValue="string[]" @ref="ListBoxObj" DataSource="@CountryData" TItem="CountryCode">

  <ListBoxFieldSettings Text="Name" Value="Code" />

</SfListBox>

 

@code {

    SfListBox<string[], CountryCode> ListBoxObj;

    private async void InputHandler(InputEventArgs args)

    {

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

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

        await ListBoxObj.FilterAsync(ListBoxObj.DataSource, query);

    }

}


Sample Link: https://blazorplayground.syncfusion.com/BjLfjxiKnDgxUPCb


Please let us know if you need any further assistance on this.


Regards,

KeerthiKaran K V


Marked as answer
Loader.
Up arrow icon