ShellUI Logo
ShellUI

Table

Structured data presentation component with customizable styling

The Table component provides a flexible and accessible way to display tabular data with proper semantic HTML structure and responsive design.

Basic Usage

<Table>
  <TableHeader>
    <TableRow>
      <TableHead>Name</TableHead>
      <TableHead>Email</TableHead>
      <TableHead>Role</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    <TableRow>
      <TableCell>John Doe</TableCell>
      <TableCell>john@example.com</TableCell>
      <TableCell>Admin</TableCell>
    </TableRow>
    <TableRow>
      <TableCell>Jane Smith</TableCell>
      <TableCell>jane@example.com</TableCell>
      <TableCell>User</TableCell>
    </TableRow>
  </TableBody>
</Table>

Table Structure

Tables are composed of several sub-components:

TableHeader

Contains the column headers at the top of the table.

<TableHeader>
  <TableRow>
    <TableHead>Name</TableHead>
    <TableHead>Email</TableHead>
    <TableHead>Actions</TableHead>
  </TableRow>
</TableHeader>

TableBody

Contains the data rows of the table.

<TableBody>
  @foreach (var item in items)
  {
    <TableRow>
      <TableCell>@item.Name</TableCell>
      <TableCell>@item.Email</TableCell>
      <TableCell>
        <Button Size="sm">Edit</Button>
      </TableCell>
    </TableRow>
  }
</TableBody>

TableRow

Represents a single row in the table.

TableHead

Represents a header cell in the table.

TableCell

Represents a data cell in the table.

Dynamic Data

@code {
    private List<User> users = new()
    {
        new User { Name = "Alice Johnson", Email = "alice@example.com", Role = "Admin" },
        new User { Name = "Bob Wilson", Email = "bob@example.com", Role = "User" },
        new User { Name = "Carol Brown", Email = "carol@example.com", Role = "Moderator" }
    };
}

<Table>
  <TableHeader>
    <TableRow>
      <TableHead>Name</TableHead>
      <TableHead>Email</TableHead>
      <TableHead>Role</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    @foreach (var user in users)
    {
      <TableRow>
        <TableCell>@user.Name</TableCell>
        <TableCell>@user.Email</TableCell>
        <TableCell>
          <Badge Variant="@GetRoleVariant(user.Role)">@user.Role</Badge>
        </TableCell>
      </TableRow>
    }
  </TableBody>
</Table>

@code {
    private string GetRoleVariant(string role) => role.ToLower() switch
    {
        "admin" => "destructive",
        "moderator" => "secondary",
        _ => "default"
    };

    private class User
    {
        public string Name { get; set; } = "";
        public string Email { get; set; } = "";
        public string Role { get; set; } = "";
    }
}

Table with Actions

<Table>
  <TableHeader>
    <TableRow>
      <TableHead>Name</TableHead>
      <TableHead>Email</TableHead>
      <TableHead>Status</TableHead>
      <TableHead>Actions</TableHead>
    </TableRow>
  </TableHeader>
  <TableBody>
    @foreach (var user in users)
    {
      <TableRow>
        <TableCell>@user.Name</TableCell>
        <TableCell>@user.Email</TableCell>
        <TableCell>
          <Badge Variant="@(user.IsActive ? "default" : "secondary")">
            @(user.IsActive ? "Active" : "Inactive")
          </Badge>
        </TableCell>
        <TableCell>
          <div class="flex space-x-2">
            <Button Size="sm" Variant="outline">Edit</Button>
            <Button Size="sm" Variant="destructive">Delete</Button>
          </div>
        </TableCell>
      </TableRow>
    }
  </TableBody>
</Table>

Responsive Tables

For mobile devices, tables automatically adapt. You can also use custom responsive classes:

<div class="overflow-x-auto">
  <Table>
    <!-- Table content -->
  </Table>
</div>

API Reference

Table Component

PropertyTypeDefaultDescription
ClassstringnullAdditional CSS classes

TableHeader Component

PropertyTypeDefaultDescription
ClassstringnullAdditional CSS classes

TableBody Component

PropertyTypeDefaultDescription
ClassstringnullAdditional CSS classes

TableRow Component

PropertyTypeDefaultDescription
ClassstringnullAdditional CSS classes

TableHead Component

PropertyTypeDefaultDescription
ClassstringnullAdditional CSS classes

TableCell Component

PropertyTypeDefaultDescription
ClassstringnullAdditional CSS classes

Styling

Tables use Tailwind CSS classes and can be customized:

/* Custom table styling */
.table {
  --table-border: #e5e7eb;
  --table-header-bg: #f9fafb;
}

.table-row:hover {
  --table-row-hover: #f3f4f6;
}

Accessibility

The Table component includes:

  • Proper semantic HTML (<table>, <thead>, <tbody>, etc.)
  • Screen reader compatibility
  • Keyboard navigation support
  • ARIA attributes where needed

Performance Tips

For large datasets, consider:

  • Using pagination
  • Implementing virtual scrolling with the ScrollArea component
  • Lazy loading data
  • Optimizing re-renders with @key directives

Installation

shellui add table

On this page