blazor-devexpress-dot-blazor-dot-dxlistbox-2-e0acba87.md
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.v25.2.dll
NuGet Package : DevExpress.Blazor
[Parameter]
public RenderFragment<ListBoxEmptyDataAreaTemplateContext> EmptyDataAreaTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment<ListBoxEmptyDataAreaTemplateContext> |
The empty data area template.
|
The List Box 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 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; }
}
}
.empty-data-area-template {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%
}
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public partial class Employee {
public Employee() {
this.Orders = new List<Order>();
}
public int EmployeeId { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Title { get; set; }
public string TitleOfCourtesy { get; set; }
public Nullable BirthDate { get; set; }
public Nullable HireDate { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string HomePhone { get; set; }
public string Extension { get; set; }
public byte[] Photo { get; set; }
public string Notes { get; set; }
public Nullable<int> ReportsTo { get; set; }
public string PhotoPath { get; set; }
public string GroupName { get; set; }
public virtual ICollection<Order> Orders { get; set; }
public string Text => $"{FirstName} {LastName} ({Title})";
public string FullName => $"{FirstName} {LastName}";
public string ImageFileName => $"employees/{EmployeeId}.jpg";
}
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BlazorDemo.Data.Northwind;
using BlazorDemo.DataProviders;
namespace BlazorDemo.Services {
public partial class NwindDataService {
public Task<IEnumerable<Employee>> GetEmployeesAsync(CancellationToken ct = default) {
// Return your data here
}
}
}
public class Startup {
public void ConfigureServices(IServiceCollection services) {
// ...
services.AddScoped<NwindDataService>();
}
}
Run Demo: List Box - Empty Data Area Template
DevExpress.Blazor.IListBox<TData, TValue>.EmptyDataAreaTemplate
See Also
DxListBox<TData, TValue> Class