Table of contents
Important
The
<CleanTable />component simply extends theQuickGridcomponent to apply styling and provide some useful utilities. For more usage examples, check the QuickGrid docs.
Warning
Keep in mind that filtering requires the
Interactiverendering mode. Pagination and sorting are supported in any render mode.
Basic
Tip
By adding the
PaginationandShowPaginationparameters,CleanTablewill automatically renderCleanPagination. You can, of course, manually render pagination by discarding theShowPaginationparameter.This also works in the
Staticrendering mode!
<CleanTable Items="@(Items)" Pagination="@(new() { ItemsPerPage = 10 })" ShowPagination>
<CleanColumn Property="@(static (p) => p.Id)" Title="Custom ID title" Sortable="@(true)" />
<CleanColumn Property="@(static (p) => p.FullName)" Sortable="@(true)">
<ColumnOptions>
<CleanInputText @bind-Value="@(search)" type="search" placeholder="Search for people…" />
</ColumnOptions>
</CleanColumn>
<CleanColumn Property="@(static (p) => p.DateOfBirth)" Format="d" Sortable="@(true)" />
<CleanColumn Property="@(static (p) => p.Email)">
<!-- By adding child content to the `<CleanColumn />` component, you can override the rendering of the column. Use the `Context` parameter to rename the `context` variable. -->
<a href="@($"mailto:{context}")">@(context)</a>
</CleanColumn>
<CleanColumn Property="@(static (p) => p.Created)" Format="g" Sortable="@(true)" />
</CleanTable>
@code {
private IQueryable<Person> Items
{
get
{
var query = people.AsQueryable();
if (!string.IsNullOrEmpty(search))
{
query = query.Where((p) => p.FullName.Contains(search, StringComparison.OrdinalIgnoreCase));
}
return query;
}
}
private readonly Person[] people =
Enumerable.Range(1, 20)
.Select(static (i) => new Person(i, "Person", i.ToString(), new DateOnly(Random.Shared.Next(1970, 2011), Random.Shared.Next(1, 13), Random.Shared.Next(1, 20)), $"person{i}@email.com"))
.ToArray();
private string? search;
private readonly record struct Person
{
[Display(Name = "Id")] public readonly int Id;
public readonly string GivenName;
public readonly string FamilyName;
[Display(Name = "Birthday")] public readonly DateOnly DateOfBirth;
[Display(Name = "E-mail")] public readonly string Email;
[Display(Name = "Created at")] public readonly DateTimeOffset Created;
[Display(Name = "Name")]
public string FullName =>
$"{GivenName} {FamilyName}";
}
}
Sizes
<CleanTable Items="@(people.AsQueryable())" Size="@(CleanTableSize.Small)">
<CleanColumn Property="@(static (p) => p.Id)" />
<CleanColumn Property="@(static (p) => p.FullName)" />
<CleanColumn Property="@(static (p) => p.DateOfBirth)" Format="d" />
</CleanTable>
<CleanTable Items="@(people.AsQueryable())" Size="@(CleanTableSize.Large)">
<CleanColumn Property="@(static (p) => p.Id)" />
<CleanColumn Property="@(static (p) => p.FullName)" />
<CleanColumn Property="@(static (p) => p.DateOfBirth)" Format="d" />
</CleanTable>
Striped
<CleanTable Items="@(people.AsQueryable())" Striped>
<CleanColumn Property="@(static (p) => p.Id)" />
<CleanColumn Property="@(static (p) => p.FullName)" />
<CleanColumn Property="@(static (p) => p.DateOfBirth)" Format="d" />
</CleanTable>
Hover
<CleanTable Items="@(people.AsQueryable())" Hoverable>
<CleanColumn Property="@(static (p) => p.Id)" />
<CleanColumn Property="@(static (p) => p.FullName)" />
<CleanColumn Property="@(static (p) => p.DateOfBirth)" Format="d" />
</CleanTable>
Bordered
<CleanTable Items="@(people.AsQueryable())" Bordered>
<CleanColumn Property="@(static (p) => p.Id)" />
<CleanColumn Property="@(static (p) => p.FullName)" />
<CleanColumn Property="@(static (p) => p.DateOfBirth)" Format="d" />
</CleanTable>
Borderless
<CleanTable Items="@(people.AsQueryable())" Borderless>
<CleanColumn Property="@(static (p) => p.Id)" />
<CleanColumn Property="@(static (p) => p.FullName)" />
<CleanColumn Property="@(static (p) => p.DateOfBirth)" Format="d" />
</CleanTable>
Responsive
A 'responsive' table allows users to scroll through the table's content when the screen is too small to display all its content.
You can set the Responsiveness parameter to a breakpoint to only make the table responsive up until that breakpoint.
<CleanTable Items="@(people.AsQueryable())" Responsiveness="@(CleanTableResponsiveness.Always)">
@for (var i = 0; i < 20; i++)
{
<CleanColumn Property="@(static (p) => p.Id)" />
}
</CleanTable>