DxListBox<TData, TValue>.EmptyDataAreaTemplate Property
Specifies the template used to display custom content in the List Box if there is not items to display.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public RenderFragment<ListBoxEmptyDataAreaTemplateContext> EmptyDataAreaTemplate { get; set; }
Property Value
Type | Description |
---|---|
RenderFragment<ListBoxEmptyDataAreaTemplateContext> | The empty data area template. |
Remarks
The List Box displays an empty data area in the following cases:
The Data property is unset.
<DxListBox TData="string" TValue="string"> </DxListBox>
The specified data source does not contain items.
<DxListBox Data="@ListData" TData="string" TValue="string"> </DxListBox> @code { List<string> ListData { get; set; } = new List<string>(); }
You use the DataAsync property or the CustomData property to bind the List Box to a data source. The component sends the first request to a remote data source and waits for a response
Define the EmptyDataAreaTemplate
to customize content displayed in the empty data area. The template’s context
parameter has the IsDataLoading property that allows you to determine whether the List Box data is still loading data.
The following code snippet embeds the Wait Indicator component into the List Box.
@inject NwindDataService NwindDataService
<DxListBox TData="@WebApiLookup" TValue="string"
ListRenderMode="ListRenderMode.Virtual"
CssClass="cw-400 chi-220"
CustomData="@LoadCustomData"
@key="ComponentKey">
<EmptyDataAreaTemplate>
@if (context.IsDataLoading) {
<div class="empty-data-area-template">
<div class="d-flex flex-column">
<DxWaitIndicator Visible="true"
CssClass="m-auto"
AnimationType="WaitIndicatorAnimationType.Spin" />
<p class="dxbl-text d-block mt-1">Loading, please wait...</p>
</div>
</div>
}
</EmptyDataAreaTemplate>
</DxListBox>
@code {
[Inject] protected HttpClient Client { get; set; }
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();
if(options.RequireTotalCount)
await Task.Delay(3000, cancellationToken);
using var responseStream = await response.Content.ReadAsStreamAsync();
var result = await JsonSerializer.DeserializeAsync<LoadResult>(responseStream, cancellationToken: cancellationToken);
return result;
}
void ReloadListBox() {
ComponentKey = Guid.NewGuid();
}
public class WebApiLookup {
public string Text { get; set; }
public string Value { get; set; }
}
}