Skip to main content
All docs
V24.1

DxComboBox<TData, TValue>.EmptyDataAreaTemplate Property

Specifies the template used to display custom content in the ComboBox if there is not items to display.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public RenderFragment<ComboBoxEmptyDataAreaTemplateContext> EmptyDataAreaTemplate { get; set; }

Property Value

Type Description
RenderFragment<ComboBoxEmptyDataAreaTemplateContext>

The empty data area template.

Remarks

The ComboBox displays an empty data area in the following cases:

  • The Data property is unset.
  • The specified data source does not contain items.
  • You use the DataAsync property or the CustomData property to bind the ComboBox to a data source. The component sends the first request to a remote data source and waits for a response.

Use the EmptyDataAreaTemplate property to customize content displayed in this empty region. The template’s context parameter includes the IsDataLoading property that allows you to determine whether the ComboBox is still loading data.

The code below embeds the Wait Indicator component into the ComboBox.

@inject NwindDataService NwindDataService

<DxComboBox TData="@WebApiLookup"
            TValue="string"
            @key="ComponentKey"
            ClearButtonDisplayMode="@DataEditorClearButtonDisplayMode.Auto"
            CustomData="@LoadCustomData"
            CssClass="cw-480"
            DropDownVisibleChanged="@OnDropDownVisibleChanged"
            NullText="Select a value..."
            ListRenderMode="ListRenderMode.Virtual"
            SizeMode="Params.SizeMode">
    <EmptyDataAreaTemplate>
        @if(context.IsDataLoading) {
            <div class="empty-data-area-template">
                <div class="d-flex flex-column">
                    <DxWaitIndicator Visible="true"
                                    SizeMode="Params.SizeMode"
                                    CssClass="m-auto"
                                    AnimationType="WaitIndicatorAnimationType.Spin" />
                    <p class="dxbl-text d-block mt-1">Loading, please wait...</p>
                </div>
            </div>
        }
    </EmptyDataAreaTemplate>
</DxComboBox>

@code {
    [Inject] protected HttpClient Client { get; set; }
    bool ThrottleRequireTotalCount { get; set; } = true;
    Guid ComponentKey { get; set; } = Guid.NewGuid();

    async Task<LoadResult> LoadCustomData(DataSourceLoadOptionsBase options, CancellationToken cancellationToken) {
        using var response = await Client.GetAsync(options.ConvertToGetRequestUri("https://js.devexpress.com/Demos/NetCore/api/DataGridWebApi/CustomersLookup"), cancellationToken);
        response.EnsureSuccessStatusCode();
        while(options.RequireTotalCount && ThrottleRequireTotalCount) {
            cancellationToken.ThrowIfCancellationRequested();
            await Task.Yield();
        }
        using var responseStream = await response.Content.ReadAsStreamAsync();
        var result = await JsonSerializer.DeserializeAsync<LoadResult>(responseStream, cancellationToken: cancellationToken);
        return result;
    }

    void OnDropDownVisibleChanged(bool value) {
        if(!value) {
            ThrottleRequireTotalCount = true;
            ComponentKey = Guid.NewGuid();
            StateHasChanged();
        } else {
            _ = ResetThrottleRequireTotalCountAsync(true);
        }
    }
    async Task ResetThrottleRequireTotalCountAsync(bool value) {
        try {
            await Task.Delay(TimeSpan.FromSeconds(5));
        }
        finally {
            ThrottleRequireTotalCount = !value;
        }
    }

    public class WebApiLookup {
        public string Text { get; set; }
        public string Value { get; set; }
    }
}

ComboBox - Empty Data Area Template

Run Demo: Combo Box - Empty Data Area Template

Implements

DevExpress.Blazor.IComboBox<TData, TValue>.EmptyDataAreaTemplate
See Also