Skip to content
Data Table

Table

A data table with sortable columns.

On this page

Examples

Sortable table

Team members
Status
Lindsay WaltonFront-end developerMar 2024Active
Courtney HenryDesignerNov 2023Active
Tom CookDirector of productJun 2022Away
Whitney FrancisCopywriterJan 2025Active
Razor
<div class="w-full">
    <KlyTable Items="People" Caption="Team members" Class="rounded-xl border border-(--klyroo-border)">
        <KlyColumn Title="Name" Field="p => p.Name" Sortable Class="font-medium text-(--klyroo-text)" />
        <KlyColumn Title="Role" Field="p => p.Role" Sortable />
        <KlyColumn Title="Joined" Field="p => p.Joined" Sortable>
            <Template>@context.Joined.ToString("MMM yyyy")</Template>
        </KlyColumn>
        <KlyTemplateColumn TItem="Person" Title="Status">
            <Template>
                <KlyBadge Label="@context.Status" Variant="KlyVariant.Subtle" Size="KlySize.Sm"
                         Color="@(context.Status == "Active" ? KlyColor.Success : KlyColor.Neutral)" />
            </Template>
        </KlyTemplateColumn>
    </KlyTable>
</div>

@code {
    private sealed record Person(string Name, string Role, DateOnly Joined, string Status);

    private static readonly Person[] People =
    [
        new("Lindsay Walton", "Front-end developer", new(2024, 3, 1), "Active"),
        new("Courtney Henry", "Designer", new(2023, 11, 15), "Active"),
        new("Tom Cook", "Director of product", new(2022, 6, 1), "Away"),
        new("Whitney Francis", "Copywriter", new(2025, 1, 20), "Active"),
    ];
}

A column takes a Footer (or a FooterTemplate), Align, Numeric and Mono; Max with Step cuts the rows behind a Show more button.

Order lines
ItemQuantitySKUPrice
Keyboard4KB-100$480.00
Monitor2MN-27$640.00
Cable10CB-01$40.00
Total19$1,190.00
Razor
<div class="w-full">
    <KlyTable Items="Lines" Caption="Order lines" Max="3" Step="3" Class="rounded-xl border border-(--klyroo-border)">
        <KlyColumn Title="Item" Field="l => l.Item" Footer="Total" />
        <KlyColumn Title="Quantity" Field="l => l.Quantity" Numeric Footer="19" />
        <KlyColumn Title="SKU" Field="l => l.Sku" Mono />
        <KlyColumn Title="Price" Field="l => l.Price" Numeric Footer="$1,190.00">
            <Template>@context.Price.ToString("C2", System.Globalization.CultureInfo.GetCultureInfo("en-US"))</Template>
        </KlyColumn>
    </KlyTable>
</div>

@code {
    private sealed record Line(string Item, int Quantity, string Sku, decimal Price);

    private static readonly Line[] Lines =
    [
        new("Keyboard", 4, "KB-100", 480m), new("Monitor", 2, "MN-27", 640m), new("Cable", 10, "CB-01", 40m),
        new("Dock", 1, "DK-3", 30m), new("Mouse", 2, "MS-9", 0m),
    ];
}

API

KlyTable<TItem>

Table of items whose columns are declared with KlyColumn2 and KlyTemplateColumn1 children, with optional sorting and custom cells.

Parameters

Name Type Default Description
Caption string Describes the table for assistive technologies (visually hidden).
Class string Classes added to the root element, merged last so they win over the theme.
Items IEnumerable<TItem> The rows to show. The columns come from the KlyColumn2 and KlyTemplateColumn1 children.
Max int? The number of rows shown before a Show more button (all rows when null ). The rows are cut after sorting.
Step int? The number of rows each click on Show more reveals (all the remaining ones when null ).
Sticky bool false Keeps the header visible while the table scrolls (give the table a max height through Class).
Ui TableUi Per-instance class overrides of the slots of the table, see TableUi . They are merged after the theme and the Class parameter wins on the root slot.

Slots

Name Type Description
Empty RenderFragment Shown when there are no items.
ChildContent RenderFragment The columns: KlyColumn and KlyTemplateColumn components.

Ui slots

Ui takes a TableUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyTable`1 , after the theme and the app configuration.
Base Classes merged into the base slot of KlyTable`1 , after the theme and the app configuration.
Caption Classes merged into the caption slot of KlyTable`1 , after the theme and the app configuration.
Thead Classes merged into the thead slot of KlyTable`1 , after the theme and the app configuration.
Tr Classes merged into the tr slot of KlyTable`1 , after the theme and the app configuration.
Th Classes merged into the th slot of KlyTable`1 , after the theme and the app configuration.
SortButton Classes merged into the sortButton slot of KlyTable`1 , after the theme and the app configuration.
SortIcon Classes merged into the sortIcon slot of KlyTable`1 , after the theme and the app configuration.
Tbody Classes merged into the tbody slot of KlyTable`1 , after the theme and the app configuration.
Td Classes merged into the td slot of KlyTable`1 , after the theme and the app configuration.
Empty Classes merged into the empty slot of KlyTable`1 , after the theme and the app configuration.
Tfoot Classes merged into the tfoot slot of KlyTable`1 , after the theme and the app configuration.
Tf Classes merged into the tf slot of KlyTable`1 , after the theme and the app configuration.
CellEnd Classes merged into the cellEnd slot of KlyTable`1 , after the theme and the app configuration.
CellNumeric Classes merged into the cellNumeric slot of KlyTable`1 , after the theme and the app configuration.
CellMono Classes merged into the cellMono slot of KlyTable`1 , after the theme and the app configuration.
More Classes merged into the more slot of KlyTable`1 , after the theme and the app configuration.
MoreIcon Classes merged into the moreIcon slot of KlyTable`1 , after the theme and the app configuration.

KlyColumn<TItem, TValue>

A column of KlyTable1 that shows a value of each item. It is also the sort key when Sortable , compared with the default comparer of . Give a Template to show markup in the cells while Field still sorts them; for a column that has no value to sort by use KlyTemplateColumn1 .

Parameters

Name Type Default Description
Align KlyColumnAlign KlyColumnAlign.Start The alignment of the header, the cells and the footer of the column: Start (the default) or End . Values: Start, End.
Class string Classes added to the cells of this column.
Field (required) Func<TItem, TValue> Value shown in the cell, and the sort key when Sortable . Dates and numbers are shown with the culture of the page ( null shows nothing).
Footer string Text of the cell of this column in the footer row. The footer row shows when any column has a Footer or a FooterTemplate .
Mono bool false Renders the cells in a monospace font.
Numeric bool false Aligns the column to the end and uses tabular figures, so digits line up.
Sortable bool false Sorts the table by Field when the header is clicked.
Title (required) string "" Text of the column header.

Slots

Name Type Description
FooterTemplate RenderFragment Markup of the cell of this column in the footer row, instead of Footer .
Template RenderFragment<TItem> Cell content built from the item, shown instead of the text of Field , which still orders the column.

KlyTemplateColumn<TItem>

A column of KlyTable1 whose cells are markup built from the item. It cannot be sorted: use KlyColumn2 for that.

Parameters

Name Type Default Description
Align KlyColumnAlign KlyColumnAlign.Start The alignment of the header, the cells and the footer of the column: Start (the default) or End . Values: Start, End.
Class string Classes added to the cells of this column.
Footer string Text of the cell of this column in the footer row. The footer row shows when any column has a Footer or a FooterTemplate .
Mono bool false Renders the cells in a monospace font.
Numeric bool false Aligns the column to the end and uses tabular figures, so digits line up.
Title (required) string "" Text of the column header.

Slots

Name Type Description
FooterTemplate RenderFragment Markup of the cell of this column in the footer row, instead of Footer .
Template (required) RenderFragment<TItem> The content of the cell of an item.