Button within AutoComplete
Hi, can we add a button inside of an AutoComplete?
<SfAutoComplete @ref="_searchAutoComplete" TValue="string" TItem="SearchItem" Placeholder="Search..." AllowFiltering="true" Width="240px" ShowPopupButton="true" CssClass="e-custom">
<SfDataManager AdaptorInstance="@typeof(SearchDataAdapter)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<AutoCompleteEvents TItem="SearchItem" TValue="string" OnValueSelect="@OnItemSelected"></AutoCompleteEvents>
<AutoCompleteFieldSettings GroupBy="Type" Text="Name" Value="Id" />
<AutoCompleteTemplates TItem="SearchItem">
<ItemTemplate>
<div class="row">
<div class="col-2 justify-content-center">
<span class="@context.IconCss" />
</div>
<div class="col-10 justify-content-center text-truncate">@context.Name</div>
</div>
</ItemTemplate>
</AutoCompleteTemplates>
<SfButton IconCss="bi upc-scan" OnClick="(() => _barcodeVisible = !_barcodeVisible)" />
</SfAutoComplete>
Hi Yongkee Cho,
Thank you for reaching out to us. Adding a custom button inside the Syncfusion SfAutoComplete using JSInterop allows you to manipulate the DOM dynamically.
Here’s how to achieve this:
Index.razor
<SfAutoComplete TValue="string" TItem="string" @bind-Value="SelectedValue" ShowPopupButton="true" DataSource="@Items" Placeholder="Select an item" @ref="DropDownListRef">
@code {
// Refresh method to update items
// Invoke JS logic after the component has been rendered
// Callback for the button click |
Layout.cshtml
<script>
// Check if the button already exists to prevent duplicates
// Create a new button element
// Add a click event to the button
// Append the button to the input wrapper
</script> |
Regards,
Priyanka K
Attachment: BlazorApp2_7320d478.zip
It worked. Thank you.
Hi Yongkee Cho,
We are delighted to hear that the requirement has been successfully achieved on your end. Please feel free to reach out to us if you need any further assistance. We’re always here to help!
Regards,
Priyanka K
- 3 Replies
- 2 Participants
- Marked answer
-
YC Yongkee Cho
- Nov 23, 2024 01:46 PM UTC
- Dec 9, 2024 04:43 AM UTC