Skip to main content
twblazor
Home
  • Get started
  • Tailwind with Blazor
  • Why twblazor?
  • Theme
  • Class Merge
    • Configuring localization
    • RTL Provider
  • Breadcrumb
  • Card
  • Carousel
  • Collapse
  • Context Menu
  • Drawer
  • Footer
  • Menu
  • Navbar
  • On This Page
  • Separator
  • Sidebar
  • Stepper
  • Tabs
  • Tree List
  • Container
  • Flex
  • Grid
  • Text
  • Link
  • Button
  • Form
    • AutocompleteNew
    • Checkbox
    • Color Picker
    • Date Picker
    • Date Range Picker
    • Datetime Picker
    • Datetime Range Picker
    • File Upload
    • Input GroupNew
    • NumericNew
    • Masked InputNew
    • Radio Button
    • Range SliderNew
    • RatingNew
    • Select
    • Slider
    • Switch
    • Tag InputNew
    • Text EditorNew
    • Textfield
    • Time Picker
    • Time Range Picker
  • Toggle
  • Toggle Group
  • Alert
  • Avatar
  • Badge
  • Chip
  • Empty
  • Icon
  • Popover
  • Progress
  • Skeleton
  • Spinner
  • Tooltip
  • Data Table
  • SpreadsheetNew
  • Column Filter Editor
  • Pagination
  • Pick List
  • Barcode
  • QR Code
  • Calendar
  • Table
  • Attachment
  • Overview
    • Bar
    • Bullet
    • Column
    • Dot Plot
    • Dumbbell
    • Icon
    • Lollipop
    • Radial Bar
    • Range
    • Word Cloud
    • Area
    • Bump
    • Bump Area
    • Candlestick
    • Gantt
    • Horizon
    • Line
    • Slope
    • Small Multiples
    • Stream Graph
    • Funnel
    • Gauge
    • Marimekko
    • Nightingale
    • Pie
    • Treemap
    • Waffle
    • Waterfall
    • Circular Treemap
    • Convex Treemap
    • Dendrogram
    • Sunburst
    • Barcode
    • Beeswarm
    • Box Plot
    • Density Plot
    • Histogram
    • Radial Histogram
    • Ridgeline
    • Strip Plot
    • Violin Plot
    • Categorical Scatter
    • Contour
    • Hexagonal Binning
    • Quadrant
    • Scatter
    • Heatmap
    • Matrix
    • Parallel Coordinates
    • Radar
    • Arc Diagram
    • Chord Diagram
    • Flowchart
    • Network Diagram
    • Sankey
    • Euler Diagram
    • Venn Diagram
  • Bubble
  • Marker
  • Message
  • Dialog Service
  • Toast Service
API DocumentationAI Agents & Skills
Home Get Started

Data

TwDataTable

TwDataTable is a Blazor data table component with pagination, search, sortable columns and custom row classes for displaying structured data.

Last updated 19 October 2026

Basic data table with pagination

A feature-rich data table with pagination and search functionality.
Product Category Price Stock
Apple MacBook Pro 17" Laptop £2,999.00 15
Microsoft Surface Pro Laptop £1,999.00 8
Magic Mouse 2 Accessories £99.00 50
Apple Watch Series 9 Wearables £499.00 25
iPad Air Tablet £799.00 5
RAZOR
<TwDataTable TItem="Product"
             Items="@products"
             EnablePagination
             RowsPerPage="5">
    <TableHeader>
        <tr>
            <th scope="col" class="px-6 py-3">Product</th>
            <th scope="col" class="px-6 py-3">Category</th>
            <th scope="col" class="px-6 py-3">Price</th>
            <th scope="col" class="px-6 py-3">Stock</th>
        </tr>
    </TableHeader>
    <TableRow Context="product">
        <td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">@product.Name</td>
        <td class="px-6 py-4">@product.Category</td>
        <td class="px-6 py-4">£@product.Price.ToString("N2")</td>
        <td class="px-6 py-4">@product.Stock</td>
    </TableRow>
</TwDataTable>
CSHARP
@code {
    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public string Category { get; set; } = string.Empty;
        public decimal Price { get; set; }
        public int Stock { get; set; }
    }
}

Searchable data table

Data table with search functionality to filter results.
Product Category Price Stock
Apple MacBook Pro 17" Laptop £2,999.00 15
Microsoft Surface Pro Laptop £1,999.00 8
Magic Mouse 2 Accessories £99.00 50
Apple Watch Series 9 Wearables £499.00 25
iPad Air Tablet £799.00 5
Samsung Galaxy S24 Phone £1,199.00 30
Sony WH-1000XM5 Accessories £399.00 12
Dell XPS 15 Laptop £2,199.00 18
Google Pixel 8 Pro Phone £999.00 22
AirPods Pro Accessories £249.00 40
RAZOR
<TwDataTable TItem="Product"
             Items="@products"
             Searchable
             EnablePagination
             RowsPerPage="10">
    <TableHeader>
        <tr>
            <th scope="col" class="px-6 py-3">Product</th>
            <th scope="col" class="px-6 py-3">Category</th>
            <th scope="col" class="px-6 py-3">Price</th>
            <th scope="col" class="px-6 py-3">Stock</th>
        </tr>
    </TableHeader>
    <TableRow Context="product">
        <td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">@product.Name</td>
        <td class="px-6 py-4">@product.Category</td>
        <td class="px-6 py-4">£@product.Price.ToString("N2")</td>
        <td class="px-6 py-4">@product.Stock</td>
    </TableRow>
    <EmptyContent>
        <div class="text-center py-8">
            <p class="text-gray-500 dark:text-gray-400">No products found matching your search.</p>
        </div>
    </EmptyContent>
</TwDataTable>
CSHARP
@code {
    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public string Category { get; set; } = string.Empty;
        public decimal Price { get; set; }
        public int Stock { get; set; }
    }
}

Data table without pagination

Display all data without pagination controls.
Name Department Role
John Doe Engineering Developer
Jane Smith Product Designer
Bob Johnson Operations Manager
Alice Williams Engineering Developer
Charlie Brown Quality QA Engineer
RAZOR
<TwDataTable TItem="User"
             Items="@users"
             EnablePagination="false"
             Searchable
             SearchPlaceholder="Search users...">
    <TableHeader>
        <tr>
            <th scope="col" class="px-6 py-3">Name</th>
            <th scope="col" class="px-6 py-3">Department</th>
            <th scope="col" class="px-6 py-3">Role</th>
        </tr>
    </TableHeader>
    <TableRow Context="user">
        <td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">@user.Name</td>
        <td class="px-6 py-4">@user.Department</td>
        <td class="px-6 py-4">@user.Role</td>
    </TableRow>
</TwDataTable>
CSHARP
@code {
    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public string Department { get; set; } = string.Empty;
        public string Role { get; set; } = string.Empty;
    }
}

Custom row classes

Data table with custom row styling based on conditions.
Product Category Price Stock
Apple MacBook Pro 17" Laptop £2,999.00 15
Microsoft Surface Pro Laptop £1,999.00 8 (Low Stock)
Magic Mouse 2 Accessories £99.00 50
Apple Watch Series 9 Wearables £499.00 25
iPad Air Tablet £799.00 5 (Low Stock)
RAZOR
<TwDataTable TItem="Product"
             Items="@products"
             RowsPerPage="5"
             EnablePagination
             DefineTableRows>
    <TableHeader>
        <tr>
            <th scope="col" class="px-6 py-3">Product</th>
            <th scope="col" class="px-6 py-3">Category</th>
            <th scope="col" class="px-6 py-3">Price</th>
            <th scope="col" class="px-6 py-3">Stock</th>
        </tr>
    </TableHeader>
    <TableRow Context="product">
        @{
            var rowClass = product.Stock < 10 ? "bg-red-50 dark:bg-red-900/20" : "";
        }
        <tr class="@rowClass">
            <td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">@product.Name</td>
            <td class="px-6 py-4">@product.Category</td>
            <td class="px-6 py-4">£@product.Price.ToString("N2")</td>
            <td class="px-6 py-4">
                @if (product.Stock < 10)
                {
                    <span class="text-red-700 dark:text-red-400 font-semibold">@product.Stock (Low Stock)</span>
                }
                else
                {
                    <span>@product.Stock</span>
                }
            </td>
        </tr>
    </TableRow>
</TwDataTable>
CSHARP
@code {
    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public string Category { get; set; } = string.Empty;
        public decimal Price { get; set; }
        public int Stock { get; set; }
    }
}

Sortable data table with columns

Data table with per-column sortability. Click column headers to sort. Some columns are sortable (with icons), others are not.
Product Name
Category
Price
Stock
Apple MacBook Pro 17"Laptop£2,999.0015
Microsoft Surface ProLaptop£1,999.008 (Low Stock)
Magic Mouse 2Accessories£99.0050
Apple Watch Series 9Wearables£499.0025
iPad AirTablet£799.005 (Low Stock)
Samsung Galaxy S24Phone£1,199.0030
Sony WH-1000XM5Accessories£399.0012
Dell XPS 15Laptop£2,199.0018
Google Pixel 8 ProPhone£999.0022
AirPods ProAccessories£249.0040
RAZOR
<TwDataTable TItem="Product"
             Items="@products"
             Columns="@_productColumns"
             Searchable
             EnablePagination
             RowsPerPage="10">
    <EmptyContent>
        <div class="text-center py-8">
            <p class="text-gray-500 dark:text-gray-400">No products found.</p>
        </div>
    </EmptyContent>
</TwDataTable>
CSHARP
@code {
    // Define columns with per-column sortability
    private readonly List<TwDataTableColumn<Product>> _productColumns = new()
    {
        new TwDataTableColumn<Product>
        {
            Name = "name",
            Title = "Product Name",
            PropertySelector = p => p.Name,
            IsSortable = true,  // Sortable with alpha icons (auto-detected)
        },
        new TwDataTableColumn<Product>
        {
            Name = "category",
            Title = "Category",
            PropertySelector = p => p.Category,
            IsSortable = false,  // Sortable disabled.
        },
        new TwDataTableColumn<Product>
        {
            Name = "price",
            Title = "Price",
            PropertySelector = p => p.Price,
            IsSortable = true,  // Sortable with numeric icons (auto-detected from decimal type)
            CellFormatter = p => $"£{p.Price:N2}"
        },
        new TwDataTableColumn<Product>
        {
            Name = "stock",
            Title = "Stock",
            PropertySelector = p => p.Stock,
            CellFormatter = p => p.Stock < 10
                ? $"{p.Stock} (Low Stock)"
                : p.Stock.ToString(),
            IsSortable = true
        }
    };
}

Column widths and fixed layout

Give a column a Width to size it. Any CSS length works, such as 40% or 8rem, and columns without a width share the rest. Add FixedLayout so the columns keep their widths as you page, sort and search, instead of jumping to fit each page's content. With TableHeader and TableRow, pass a ColumnGroup of TwTableColumn elements instead, as on TwTable.
Product Name
Category
Price
Apple MacBook Pro 17"Laptop£2,999.00
Microsoft Surface ProLaptop£1,999.00
Magic Mouse 2Accessories£99.00
Apple Watch Series 9Wearables£499.00
iPad AirTablet£799.00
RAZOR
<TwDataTable TItem="Product"
             Items="@products"
             Columns="@_sizedColumns"
             FixedLayout
             Searchable
             RowsPerPage="5"
             AriaLabel="Products with fixed column widths" />
CSHARP
@code {
    private readonly List<TwDataTableColumn<Product>> _sizedColumns = new()
    {
        new TwDataTableColumn<Product> { Name = "name", Title = "Product Name", PropertySelector = p => p.Name, IsSortable = true },
        new TwDataTableColumn<Product> { Name = "category", Title = "Category", PropertySelector = p => p.Category, Width = "25%" },
        new TwDataTableColumn<Product> { Name = "price", Title = "Price", PropertySelector = p => p.Price, IsSortable = true, Width = "8rem", CellFormatter = p => $"£{p.Price:N2}" }
    };
}

Column menu

Set ColumnMenu and each column header gains an options button that opens a TwMenu. It sorts the column, groups by it when it is Groupable, moves it left or right, and hides it. Its Columns group ticks any column on or off, so a hidden column can be shown again, and Reset columns puts everything back. Set Hideable = false on a column that identifies each row so it cannot be hidden, and Visible = false on a column that should start hidden. Every change is announced to screen readers.
Product Name
Product Name column options
Category
Category column options
Price
Price column options
Apple MacBook Pro 17"Laptop£2,999.00
Microsoft Surface ProLaptop£1,999.00
Magic Mouse 2Accessories£99.00
Apple Watch Series 9Wearables£499.00
iPad AirTablet£799.00
RAZOR
<TwDataTable TItem="Product"
             Id="column-menu-table"
             Items="@products"
             Columns="@_panelColumns"
             ColumnMenu
             RowsPerPage="5"
             AriaLabel="Products with column menus" />
CSHARP
@code {
    private readonly List<TwDataTableColumn<Product>> _panelColumns = new()
    {
        // The name identifies each row, so it always stays visible.
        new TwDataTableColumn<Product> { Name = "name", Title = "Product Name", PropertySelector = p => p.Name, IsSortable = true, Hideable = false },
        new TwDataTableColumn<Product> { Name = "category", Title = "Category", PropertySelector = p => p.Category },
        new TwDataTableColumn<Product> { Name = "price", Title = "Price", PropertySelector = p => p.Price, IsSortable = true, CellFormatter = p => $"£{p.Price:N2}" },
        // Starts hidden; people can show it from the panel.
        new TwDataTableColumn<Product> { Name = "stock", Title = "Stock", PropertySelector = p => p.Stock, IsSortable = true, Visible = false }
    };
}

Filtering columns

Set Filterable on a column and its header gains a filter button. It opens a filter with up to two conditions, joined with And or Or, then Filter applies them and Clear removes them. The conditions and the value field suit the column's values: text conditions such as Contains and Starts with, comparisons such as Is greater than for numbers and dates, and a list for true or false values and enums. Set FilterType when the type cannot be worked out, such as before an ItemsProvider has loaded any rows, and FilterOperators to choose the conditions on offer. Filters are saved with the table's state, sent to an ItemsProvider in Filters, and announced with the number of rows they leave.
Product Name Filter Product Name
Product Name column options
Category Filter Category
Category column options
Price Filter Price
Price column options
Stock Filter Stock
Stock column options
Apple MacBook Pro 17"Laptop£2,999.0015
Microsoft Surface ProLaptop£1,999.008
Magic Mouse 2Accessories£99.0050
Apple Watch Series 9Wearables£499.0025
iPad AirTablet£799.005
RAZOR
<TwDataTable TItem="Product"
             Id="filtering-table"
             Items="@products"
             Columns="@_filterColumns"
             ColumnMenu
             RowsPerPage="5"
             AriaLabel="Products you can filter" />
CSHARP
@code {
    private readonly List<TwDataTableColumn<Product>> _filterColumns = new()
    {
        new TwDataTableColumn<Product> { Name = "name", Title = "Product Name", PropertySelector = p => p.Name, IsSortable = true, Filterable = true },
        new TwDataTableColumn<Product> { Name = "category", Title = "Category", PropertySelector = p => p.Category, Filterable = true },
        // Numbers get comparisons such as "is greater than", and the value is a number field.
        new TwDataTableColumn<Product> { Name = "price", Title = "Price", PropertySelector = p => p.Price, IsSortable = true, Filterable = true, CellFormatter = p => $"£{p.Price:N2}" },
        new TwDataTableColumn<Product> { Name = "stock", Title = "Stock", PropertySelector = p => p.Stock, IsSortable = true, Filterable = true }
    };
}

Resizable columns

Set ResizableColumns and every column's border becomes a resize handle, from TwTable. Drag it, or focus it with Tab and press Arrow Left or Arrow Right, holding Shift for bigger steps. Screen readers hear each border as "Resize Price" with the column's width. The widths are saved with the table's state. Resizable = false keeps a column at its width.
Product Name
Category
Price
Stock
Apple MacBook Pro 17"Laptop£2,999.0015
Microsoft Surface ProLaptop£1,999.008 (Low Stock)
Magic Mouse 2Accessories£99.0050
Apple Watch Series 9Wearables£499.0025
iPad AirTablet£799.005 (Low Stock)
RAZOR
<TwDataTable TItem="Product"
             Id="resizable-columns-table"
             Items="@products"
             Columns="@_productColumns"
             ResizableColumns
             RowsPerPage="5"
             AriaLabel="Products with resizable columns" />

Grouping rows

Set Groupable on the columns people can group by, and a Group by list appears above the table. GroupBy picks the grouping the table starts with. Each group sits under a header row with a button that expands or collapses it, and Expand all groups and Collapse all groups work on every group at once. Rows keep the table's sort inside each group. A page that starts part way through a group repeats its header. Use GroupHeaderTemplate to add a summary to each header, such as a total.
Product Name
Category
Price
Stock level
Stock value £19,698
Magic Mouse 2Accessories£99.00In stock
Sony WH-1000XM5Accessories£399.00In stock
AirPods ProAccessories£249.00In stock
Stock value £22,491
Canon EOS R6Camera£2,499.00Low
Stock value £5,215
Kindle PaperwhiteE-Reader£149.00In stock
Stock value £6,584
Nintendo SwitchGaming£299.00Low
RAZOR
<TwDataTable TItem="Product"
             Id="grouped-table"
             Items="@products"
             Columns="@_groupColumns"
             GroupBy="category"
             RowsPerPage="10"
             AriaLabel="Products grouped by category">
    <GroupHeaderTemplate Context="group">
        <span class="text-sm text-gray-600 dark:text-gray-300">Stock value £@group.Items.Sum(p => p.Price * p.Stock).ToString("N0")</span>
    </GroupHeaderTemplate>
</TwDataTable>
CSHARP
@code {
    private readonly List<TwDataTableColumn<Product>> _groupColumns = new()
    {
        new TwDataTableColumn<Product> { Name = "name", Title = "Product Name", PropertySelector = p => p.Name, IsSortable = true },
        new TwDataTableColumn<Product> { Name = "category", Title = "Category", PropertySelector = p => p.Category, IsSortable = true, Groupable = true },
        new TwDataTableColumn<Product> { Name = "price", Title = "Price", PropertySelector = p => p.Price, IsSortable = true, CellFormatter = p => $"£{p.Price:N2}" },
        // Groups by the stock level's label rather than every distinct number.
        new TwDataTableColumn<Product> { Name = "level", Title = "Stock level", PropertySelector = p => p.Stock < 10 ? "Low" : "In stock", Groupable = true }
    };
}

Virtualizing thousands of rows

Set EnableVirtualization and the table renders only the rows scrolled into view, so it stays fast with tens of thousands of rows. The rows scroll inside the table instead of being paged, and the header stays in view. Change the height with Height. Keep each row to one line, about ItemSize pixels tall. Screen readers are told the full row count and each row's place, so they still read "row 5000 of 10000". Sorting, searching, filtering, the column menu and grouping all work as before.
Order
Customer
Placed
Total
RAZOR
<TwDataTable TItem="Order"
             Id="virtualized-table"
             Items="@orders"
             Columns="@_orderColumns"
             EnableVirtualization
             Searchable
             Height="24rem"
             AriaLabel="Ten thousand orders" />
CSHARP
@code {
    private readonly List<Order> orders = [.. Enumerable.Range(1, 10_000).Select(i => new Order(
        i,
        $"Customer {(i * 37) % 900 + 1}",
        new DateTime(2026, 1, 1, 0, 0, 0, DateTimeKind.Local).AddHours(i * 7),
        Math.Round(5 + (i * 7919 % 50_000) / 100m, 2)))];
    
    private readonly List<TwDataTableColumn<Order>> _orderColumns = new()
    {
        new TwDataTableColumn<Order> { Name = "number", Title = "Order", PropertySelector = o => o.Number, IsSortable = true },
        new TwDataTableColumn<Order> { Name = "customer", Title = "Customer", PropertySelector = o => o.Customer, IsSortable = true },
        new TwDataTableColumn<Order> { Name = "placed", Title = "Placed", PropertySelector = o => o.Placed, IsSortable = true, CellFormatter = o => o.Placed.ToString("dd/MM/yyyy HH:mm") },
        new TwDataTableColumn<Order> { Name = "total", Title = "Total", PropertySelector = o => o.Total, IsSortable = true, CellFormatter = o => $"£{o.Total:N2}" }
    };
    
    public record Order(int Number, string Customer, DateTime Placed, decimal Total);
}

Loading rows from a server

For data that is too big to load at once, give the table an ItemsProvider in place of Items. The table asks it for one page at a time, passing the sort, search and column filters, so your database or API does the work and returns just those rows with the total count. Combine it with EnableVirtualization to load rows as they scroll into view. While rows load the table is marked busy, and the search result count is announced once they arrive. Call RefreshDataAsync after the data changes elsewhere.
Order
Customer
Placed
Total
Loading…
RAZOR
<TwDataTable TItem="Order"
             Id="provider-table"
             Columns="@_orderColumns"
             ItemsProvider="@LoadOrdersAsync"
             Searchable
             RowsPerPage="5"
             AriaLabel="Orders loaded from the server" />
CSHARP
@code {
    // Stands in for a database query: in a real app, pass the request on to your API or Entity Framework.
    private async ValueTask<TwDataTableItemsResult<Order>> LoadOrdersAsync(TwDataTableItemsRequest request)
    {
        await Task.Delay(300, request.CancellationToken);
    
        IEnumerable<Order> query = orders;
        if (!string.IsNullOrWhiteSpace(request.SearchQuery))
        {
            query = query.Where(o => o.Customer.Contains(request.SearchQuery, StringComparison.OrdinalIgnoreCase));
        }
    
        query = (request.SortColumn, request.SortDirection) switch
        {
            ("number", SortDirection.Descending) => query.OrderByDescending(o => o.Number),
            ("customer", SortDirection.Ascending) => query.OrderBy(o => o.Customer),
            ("customer", SortDirection.Descending) => query.OrderByDescending(o => o.Customer),
            ("placed", SortDirection.Ascending) => query.OrderBy(o => o.Placed),
            ("placed", SortDirection.Descending) => query.OrderByDescending(o => o.Placed),
            ("total", SortDirection.Ascending) => query.OrderBy(o => o.Total),
            ("total", SortDirection.Descending) => query.OrderByDescending(o => o.Total),
            _ => query
        };
    
        var matching = query.ToList();
        var page = matching.Skip(request.StartIndex).Take(request.Count ?? matching.Count).ToList();
        return new TwDataTableItemsResult<Order>(page, matching.Count);
    }
}

Editing rows

Set Editable to add an Actions column with an Edit button on each row. Editing turns the row's Editable columns into editors that match their values: a text field, a number field, a checkbox, a date picker or a list for an enum. Give a column an EditTemplate for any other editor. Save runs each column's Validator, marks any field that needs fixing and moves focus to it. Once every value is fine, each ValueSetter writes its value to the row and RowSaved is raised with the old and new values, ready to send to your API. Escape or Cancel leaves the row as it was, and focus goes back to the row's Edit button.
Product Name
Category
Price
Stock
Actions
KettleKitchen3014 Edit Kettle
ArmchairFurniture2503 Edit Armchair
Desk lampLighting4522 Edit Desk lamp
BlenderKitchen608 Edit Blender

RAZOR
<TwDataTable TItem="Product"
             Id="editable-table"
             Items="@editableProducts"
             Columns="@_editableColumns"
             Editable
             RowSaved="OnProductSaved"
             RowsPerPage="5"
             AriaLabel="Products you can edit" />
<p class="mt-4" role="status">@lastSaved</p>
CSHARP
@code {
    private readonly List<Product> editableProducts =
    [
        new Product { Id = 1, Name = "Kettle", Category = "Kitchen", Price = 30, Stock = 14 },
        new Product { Id = 2, Name = "Armchair", Category = "Furniture", Price = 250, Stock = 3 },
        new Product { Id = 3, Name = "Desk lamp", Category = "Lighting", Price = 45, Stock = 22 },
        new Product { Id = 4, Name = "Blender", Category = "Kitchen", Price = 60, Stock = 8 }
    ];
    
    private readonly List<TwDataTableColumn<Product>> _editableColumns = new()
    {
        new TwDataTableColumn<Product>
        {
            Name = "name", Title = "Product Name", PropertySelector = p => p.Name, IsSortable = true, Editable = true,
            ValueSetter = (p, value) => p.Name = (string?)value ?? string.Empty,
            Validator = (_, value) => string.IsNullOrWhiteSpace(value as string) ? "Enter a product name" : null
        },
        new TwDataTableColumn<Product> { Name = "category", Title = "Category", PropertySelector = p => p.Category },
        new TwDataTableColumn<Product>
        {
            Name = "price", Title = "Price", PropertySelector = p => p.Price, Editable = true,
            ValueSetter = (p, value) => p.Price = (decimal)value!,
            Validator = (_, value) => value is decimal price && price <= 0 ? "Enter a price above £0" : null
        },
        new TwDataTableColumn<Product>
        {
            Name = "stock", Title = "Stock", PropertySelector = p => p.Stock, Editable = true,
            ValueSetter = (p, value) => p.Stock = (int)value!
        }
    };
    
    private string lastSaved = string.Empty;
    
    private Task OnProductSaved(TwDataTableRowEdit<Product> edit)
    {
        // Send the change to your API here; OriginalValues can put the row back if that fails.
        var changed = string.Join(", ", edit.ChangedColumns);
        lastSaved = changed.Length == 0 ? $"{edit.Item.Name} saved with no changes." : $"{edit.Item.Name} saved: {changed} changed.";
        return Task.CompletedTask;
    }
}

Exporting to CSV and Excel

Set Exportable to add Export CSV and Export Excel buttons. An export holds the columns on screen in their current order, and by default every row that matches the search in its current sort, across all pages. Change that with ExportScope, or pick the buttons with ExportFormats. The Excel file keeps numbers, dates and true or false values as their own types, so they can be summed and filtered. Give a column an ExportFormatter to write a different value from the one on screen, or set Exportable = false to leave it out. Text that a spreadsheet would run as a formula is escaped.
Product Name
Category
Price
Stock
Apple MacBook Pro 17"Laptop£2,999.0015
Microsoft Surface ProLaptop£1,999.008
Magic Mouse 2Accessories£99.0050
Apple Watch Series 9Wearables£499.0025
iPad AirTablet£799.005
RAZOR
<TwDataTable TItem="Product"
             Id="export-table"
             Items="@products"
             Columns="@_exportColumns"
             Exportable
             ExportFileName="products"
             Searchable
             RowsPerPage="5"
             AriaLabel="Products you can export" />
CSHARP
@code {
    private readonly List<TwDataTableColumn<Product>> _exportColumns = new()
    {
        new TwDataTableColumn<Product> { Name = "name", Title = "Product Name", PropertySelector = p => p.Name, IsSortable = true },
        new TwDataTableColumn<Product> { Name = "category", Title = "Category", PropertySelector = p => p.Category },
        // On screen the price reads "£2,999.00"; the export keeps the number so a spreadsheet can total it.
        new TwDataTableColumn<Product> { Name = "price", Title = "Price", PropertySelector = p => p.Price, IsSortable = true, CellFormatter = p => $"£{p.Price:N2}" },
        new TwDataTableColumn<Product> { Name = "stock", Title = "Stock", PropertySelector = p => p.Stock, ExportFormatter = p => p.Stock < 10 ? "Low" : "In stock" }
    };
}

To build the file yourself, call GetCsv or GetExcel on the table, or use TwDataTableExport with any rows and columns, for example to send a report from the server.

CSHARP
byte[] workbook = TwDataTableExport.ToExcel(orders, columns, sheetName: "Orders");
string csv = TwDataTableExport.ToCsv(orders, columns);

Saving the table's state

Give the table a StateStorageKey and it remembers its sort, search, page, page size and columns in the browser, so it comes back the way the person left it. Sort or hide a column below, then reload the page. ResetStateAsync puts it back to how the parameters define it.
Product Name
Product Name column options
Category
Category column options
Price
Price column options
Apple MacBook Pro 17"Laptop£2,999.00
Microsoft Surface ProLaptop£1,999.00
Magic Mouse 2Accessories£99.00
Apple Watch Series 9Wearables£499.00
iPad AirTablet£799.00
RAZOR
<TwDataTable @ref="storedTable"
             TItem="Product"
             Id="stored-state-table"
             Items="@products"
             Columns="@_panelColumns"
             StateStorageKey="docs-products-table"
             ColumnMenu
             ResizableColumns
             Searchable
             RowsPerPage="5"
             AriaLabel="Products that remember their state" />
<TwButton Class="mt-4" Label="Reset table" Variant="ButtonVariant.Outlined" OnClick="ResetStoredTableAsync" />
CSHARP
@code {
    private TwDataTable<Product>? storedTable;
    
    private async Task ResetStoredTableAsync()
    {
        if (storedTable is not null)
        {
            await storedTable.ResetStateAsync();
        }
    }
}

Managing the state yourself

To keep the state somewhere else, such as a user's profile or the page address, bind @bind-State. The table raises a new TwDataTableState after every change, and restores whichever state you pass in. It is made of plain values, so it serializes to JSON as it is. Columns are matched by Name, so a saved state survives columns being added or removed.
Product Name
Category
Price
Stock
Apple MacBook Pro 17"Laptop£2,999.0015
Microsoft Surface ProLaptop£1,999.008 (Low Stock)
Magic Mouse 2Accessories£99.0050
Apple Watch Series 9Wearables£499.0025
iPad AirTablet£799.005 (Low Stock)

The current state:

JSON
Sort, search or change page to see the state.
RAZOR
<TwDataTable TItem="Product"
             Id="bound-state-table"
             Items="@products"
             Columns="@_productColumns"
             @bind-State="tableState"
             Searchable
             RowsPerPage="5"
             AriaLabel="Products with state you manage" />
<p class="mt-4 mb-2 font-medium">The current state:</p>
<TwCodeBlock Content="@tableStateJson" Language="json" />
CSHARP
@code {
    private TwDataTableState? tableState;
    
    private string tableStateJson => tableState is null
        ? "Sort, search or change page to see the state."
        : System.Text.Json.JsonSerializer.Serialize(tableState, new System.Text.Json.JsonSerializerOptions(System.Text.Json.JsonSerializerDefaults.Web) { WriteIndented = true });
}

Keyboard navigation

The table is read as a native table. Its controls are ordinary buttons, menus and fields, and sort, search, filter, page, grouping and column changes are announced. With ResizableColumns, each column's border is a separator that reports the column's width.
Key What it does
Tab or Shift+ plus Tab Moves through the toolbar, each column's sort, filter and options buttons, the resize separators, the table's scroll area and the pagination.
Enter or Space On a sort button: sorts by that column, then reverses the order, then clears it.
Arrow Left or Arrow Right or Arrow Up or Arrow Down or Pg.Up or Pg.Down In the table's scroll area: scrolls a table that is wider or taller than its container. A virtualized table renders the rows as they scroll into view.
Enter Commits the search text.
Enter or Space or Arrow Down or Arrow Up On a column's options button: opens its menu, on the first or last item.
Arrow Up or Arrow Down or Enter or Space or Escape In a column's menu: moves between its items, chooses one, or closes it. A column toggle flips and the menu stays open.
Enter or Space On a column's filter button: opens its filter with focus on the first condition.
Tab or Enter or Escape In a filter: moves between its fields and buttons, applies the filter, or closes it without changing it. Focus returns to the filter button.
Arrow Left or Arrow Right On a resize separator: makes the column wider or narrower, in bigger steps with Shift. The key moves the border the way it points, in either text direction.
Enter or Space On an export button: downloads the table, then announces how many rows it holds.
Enter or Space On a group header's button: expands or collapses that group. The button says whether the group is expanded.
Enter or Space or Arrow Down On the Group by list: opens it to choose a column to group by, or No grouping.
Enter or Space On a row's Edit button: turns the row into editors and moves focus to the first one.
Tab or Shift+ plus Tab While a row is edited: moves between its editors and the Save and Cancel buttons.
Escape While a row is edited: cancels the edit and returns focus to the row's Edit button. A picker or list open in the row closes first.

Theme configuration

Styling is controlled by TwBlazorTheme.Components (a TwTableTheme), configured via the AddTwBlazor() options callback described on the Get Started page. Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.

Inherited from TwTable - this component reuses that theme rather than defining its own.

Property Type Controls
Wrapper string
ContainerClip string
Base string
Bordered string
FixedLayout string
Header string
StickyHeader string
Body string
BodyStriped string
BodyHoverable string
RowDivider string
Footer string
SearchColumn string
SortIcon string
HeaderCellPadding string
BodyCellPadding string
EmptyState string
ResizeHandle string
GroupByColumn string
GroupRow string
GroupToggle string
GroupCount string
LoadingCell string
ActionsCell string
EditingRow string
FilterPanel string
FilterHeading string

Full reference: TwTableTheme on the API docs.

On this page

  • Basic data table with pagination
  • Searchable data table
  • Data table without pagination
  • Custom row classes
  • Sortable data table with columns
  • Column widths and fixed layout
  • Column menu
  • Filtering columns
  • Resizable columns
  • Grouping rows
  • Virtualizing thousands of rows
  • Loading rows from a server
  • Editing rows
  • Exporting to CSV and Excel
  • Saving the table's state
  • Managing the state yourself
  • Keyboard navigation
  • Theme configuration
twblazor

The Tailwind CSS component library for Blazor. Accessible, themeable and MIT licensed.

Discord (opens in a new tab) GitHub(opens in a new tab)

Get started

  • Install guide
  • Theming
  • Class merging
  • Localization

Guides

  • Tailwind CSS with Blazor
  • Why twblazor?
  • Right to left
  • AI agents and skills

Resources

  • API documentation (opens in a new tab)
  • llms.txt (opens in a new tab)
  • MIT License (opens in a new tab)

Community

  • Contributing (opens in a new tab)
  • Code of conduct (opens in a new tab)
  • Report an issue (opens in a new tab)

twblazor is and always will be free and open source.

An unhandled error has occurred. Reload