---
title: 表格
description: 将数据整理为行和列，支持 Markdown 表格和具备排序、高亮及跨行跨列功能的 Table 组件。
---

> **For AI agents:** the complete documentation index is at [llms.txt](/docs/llms.txt). Append `.md` to any page URL for its markdown version.

表格用于将数据整理为行和列。Jamdesk 支持两种方式：使用 **Markdown 表格**快速创建简单表格，或使用 **Table 组件**实现高亮和对齐等增强功能。

## 用法

```mdx
<Table>
  <Row header>
    <Cell>Name</Cell>
    <Cell>Type</Cell>
  </Row>
  <Row>
    <Cell>id</Cell>
    <Cell>string</Cell>
  </Row>
</Table>
```

## Markdown 表格

创建表格最快的方法。使用竖线（`|`）分隔列，并使用连字符（`-`）创建表头行：

```markdown
| Name | Type | Description |
|------|------|-------------|
| id | string | Unique identifier |
| email | string | User email address |
```

| 名称 | 类型 | 描述 |
|------|------|------|
| id | string | 唯一标识符 |
| email | string | 用户电子邮件地址 |

<Tip>
Markdown 表格适合简单的参考数据。当需要高亮、对齐或视觉强调时，Table 组件可以提供更多控制。
</Tip>

## Table 组件

如需更多控制，请使用 `<Table>`、`<Row>` 和 `<Cell>` 组件：

```mdx
<Table>
  <Row header>
    <Cell>Name</Cell>
    <Cell>Type</Cell>
    <Cell>Description</Cell>
  </Row>
  <Row>
    <Cell>id</Cell>
    <Cell>string</Cell>
    <Cell>Unique identifier</Cell>
  </Row>
  <Row>
    <Cell>email</Cell>
    <Cell>string</Cell>
    <Cell>User email address</Cell>
  </Row>
</Table>
```

<Table>
  <Row header>
    <Cell>名称</Cell>
    <Cell>类型</Cell>
    <Cell>描述</Cell>
  </Row>
  <Row>
    <Cell>id</Cell>
    <Cell>string</Cell>
    <Cell>唯一标识符</Cell>
  </Row>
  <Row>
    <Cell>email</Cell>
    <Cell>string</Cell>
    <Cell>用户电子邮件地址</Cell>
  </Row>
</Table>

## 斑马纹行

添加交替的行背景色，提升可读性：

```mdx
<Table striped>
  <Row header>
    <Cell>Parameter</Cell>
    <Cell>Value</Cell>
  </Row>
  <Row><Cell>timeout</Cell><Cell>30s</Cell></Row>
  <Row><Cell>retries</Cell><Cell>3</Cell></Row>
  <Row><Cell>backoff</Cell><Cell>exponential</Cell></Row>
  <Row><Cell>maxDelay</Cell><Cell>60s</Cell></Row>
</Table>
```

<Table striped>
  <Row header>
    <Cell>参数</Cell>
    <Cell>值</Cell>
  </Row>
  <Row><Cell>timeout</Cell><Cell>30s</Cell></Row>
  <Row><Cell>retries</Cell><Cell>3</Cell></Row>
  <Row><Cell>backoff</Cell><Cell>exponential</Cell></Row>
  <Row><Cell>maxDelay</Cell><Cell>60s</Cell></Row>
</Table>

## 边框与紧凑布局

在单元格之间添加边框并减少内边距：

```mdx
<Table bordered compact>
  <Row header>
    <Cell>A</Cell>
    <Cell>B</Cell>
    <Cell>C</Cell>
  </Row>
  <Row>
    <Cell>1</Cell>
    <Cell>2</Cell>
    <Cell>3</Cell>
  </Row>
</Table>
```

<Table bordered compact>
  <Row header>
    <Cell>A</Cell>
    <Cell>B</Cell>
    <Cell>C</Cell>
  </Row>
  <Row>
    <Cell>1</Cell>
    <Cell>2</Cell>
    <Cell>3</Cell>
  </Row>
</Table>

## 高亮行

高亮整行以吸引注意：

```mdx
<Table>
  <Row header>
    <Cell>Field</Cell>
    <Cell>Required</Cell>
    <Cell>Description</Cell>
  </Row>
  <Row highlight highlightColor="warning">
    <Cell>api_key</Cell>
    <Cell>Yes</Cell>
    <Cell>Your API authentication key</Cell>
  </Row>
  <Row>
    <Cell>limit</Cell>
    <Cell>No</Cell>
    <Cell>Maximum results (default: 100)</Cell>
  </Row>
</Table>
```

<Table>
  <Row header>
    <Cell>字段</Cell>
    <Cell>必填</Cell>
    <Cell>描述</Cell>
  </Row>
  <Row highlight highlightColor="warning">
    <Cell>api_key</Cell>
    <Cell>是</Cell>
    <Cell>您的 API 身份验证密钥</Cell>
  </Row>
  <Row>
    <Cell>limit</Cell>
    <Cell>否</Cell>
    <Cell>最大结果数（默认值：100）</Cell>
  </Row>
</Table>

可用的高亮颜色：`primary`、`success`、`warning`、`error`、`info`

## 高亮单元格

高亮单个单元格以显示状态指示：

```mdx
<Table>
  <Row header>
    <Cell>Service</Cell>
    <Cell>Status</Cell>
  </Row>
  <Row>
    <Cell>API</Cell>
    <Cell highlight highlightColor="success">Operational</Cell>
  </Row>
  <Row>
    <Cell>Database</Cell>
    <Cell highlight highlightColor="warning">Degraded</Cell>
  </Row>
  <Row>
    <Cell>Storage</Cell>
    <Cell highlight highlightColor="error">Outage</Cell>
  </Row>
</Table>
```

<Table>
  <Row header>
    <Cell>服务</Cell>
    <Cell>状态</Cell>
  </Row>
  <Row>
    <Cell>API</Cell>
    <Cell highlight highlightColor="success">正常运行</Cell>
  </Row>
  <Row>
    <Cell>数据库</Cell>
    <Cell highlight highlightColor="warning">性能下降</Cell>
  </Row>
  <Row>
    <Cell>存储</Cell>
    <Cell highlight highlightColor="error">中断</Cell>
  </Row>
</Table>

## 单元格对齐

控制每个单元格的文本对齐方式：

```mdx
<Table>
  <Row header>
    <Cell align="left">Left</Cell>
    <Cell align="center">Center</Cell>
    <Cell align="right">Right</Cell>
  </Row>
  <Row>
    <Cell align="left">Text</Cell>
    <Cell align="center">Text</Cell>
    <Cell align="right">$99.99</Cell>
  </Row>
</Table>
```

<Table>
  <Row header>
    <Cell align="left">左对齐</Cell>
    <Cell align="center">居中</Cell>
    <Cell align="right">右对齐</Cell>
  </Row>
  <Row>
    <Cell align="left">文本</Cell>
    <Cell align="center">文本</Cell>
    <Cell align="right">$99.99</Cell>
  </Row>
</Table>

## 跨列与跨行

合并跨列或跨行的单元格：

```mdx
<Table bordered>
  <Row header>
    <Cell>Category</Cell>
    <Cell>Item</Cell>
    <Cell>Price</Cell>
  </Row>
  <Row>
    <Cell rowSpan={2}>Fruits</Cell>
    <Cell>Apple</Cell>
    <Cell>$1.00</Cell>
  </Row>
  <Row>
    <Cell>Banana</Cell>
    <Cell>$0.50</Cell>
  </Row>
  <Row>
    <Cell colSpan={2}>Subtotal</Cell>
    <Cell>$1.50</Cell>
  </Row>
</Table>
```

<Table bordered>
  <Row header>
    <Cell>类别</Cell>
    <Cell>商品</Cell>
    <Cell>价格</Cell>
  </Row>
  <Row>
    <Cell rowSpan={2}>水果</Cell>
    <Cell>苹果</Cell>
    <Cell>$1.00</Cell>
  </Row>
  <Row>
    <Cell>香蕉</Cell>
    <Cell>$0.50</Cell>
  </Row>
  <Row>
    <Cell colSpan={2}>小计</Cell>
    <Cell>$1.50</Cell>
  </Row>
</Table>

## 可见标题

在表格上方显示无障碍表格标题：

```mdx
<Table caption="Monthly Revenue by Region" captionVisible>
  <Row header>
    <Cell>Region</Cell>
    <Cell align="right">Revenue</Cell>
  </Row>
  <Row>
    <Cell>North America</Cell>
    <Cell align="right">$1.2M</Cell>
  </Row>
</Table>
```

<Table caption="按地区统计的月收入" captionVisible>
  <Row header>
    <Cell>地区</Cell>
    <Cell align="right">收入</Cell>
  </Row>
  <Row>
    <Cell>北美洲</Cell>
    <Cell align="right">$1.2M</Cell>
  </Row>
</Table>

## 可排序列

使用 `sortable` 属性启用交互式列排序。用户可以点击列标题进行排序：

```mdx
<Table sortable>
  <Row header>
    <Cell>Name</Cell>
    <Cell>Price</Cell>
    <Cell>Stock</Cell>
  </Row>
  <Row><Cell>Widget A</Cell><Cell>$29.99</Cell><Cell>150</Cell></Row>
  <Row><Cell>Gadget B</Cell><Cell>$49.99</Cell><Cell>75</Cell></Row>
  <Row><Cell>Tool C</Cell><Cell>$19.99</Cell><Cell>200</Cell></Row>
  <Row><Cell>Device D</Cell><Cell>$99.99</Cell><Cell>25</Cell></Row>
</Table>
```

<Table sortable>
  <Row header>
    <Cell>名称</Cell>
    <Cell>价格</Cell>
    <Cell>库存</Cell>
  </Row>
  <Row><Cell>Widget A</Cell><Cell>$29.99</Cell><Cell>150</Cell></Row>
  <Row><Cell>Gadget B</Cell><Cell>$49.99</Cell><Cell>75</Cell></Row>
  <Row><Cell>Tool C</Cell><Cell>$19.99</Cell><Cell>200</Cell></Row>
  <Row><Cell>Device D</Cell><Cell>$99.99</Cell><Cell>25</Cell></Row>
</Table>

<Tip>
点击列标题一次按升序排序，再次点击按降序排序，第三次点击重置排序。数字按数值排序，文本按字母顺序排序。
</Tip>

可排序功能可以与斑马纹行等其他功能结合使用：

```mdx
<Table sortable striped>
  <Row header>
    <Cell>Team</Cell>
    <Cell>Wins</Cell>
    <Cell>Losses</Cell>
  </Row>
  <Row><Cell>Eagles</Cell><Cell>12</Cell><Cell>4</Cell></Row>
  <Row><Cell>Bears</Cell><Cell>8</Cell><Cell>8</Cell></Row>
  <Row><Cell>Lions</Cell><Cell>10</Cell><Cell>6</Cell></Row>
</Table>
```

<Table sortable striped>
  <Row header>
    <Cell>队伍</Cell>
    <Cell>胜场</Cell>
    <Cell>负场</Cell>
  </Row>
  <Row><Cell>Eagles</Cell><Cell>12</Cell><Cell>4</Cell></Row>
  <Row><Cell>Bears</Cell><Cell>8</Cell><Cell>8</Cell></Row>
  <Row><Cell>Lions</Cell><Cell>10</Cell><Cell>6</Cell></Row>
</Table>

## 属性

### Table

| 属性 | 类型 | 默认值 | 描述 |
|------|------|---------|-------------|
| `striped` | boolean | false | 交替的行背景色 |
| `bordered` | boolean | false | 所有单元格之间的边框 |
| `compact` | boolean | false | 减少单元格内边距 |
| `fullWidth` | boolean | true | 表格占满全部宽度 |
| `caption` | string | - | 表格标题文本 |
| `captionVisible` | boolean | false | 以视觉方式显示标题（默认仅屏幕阅读器可见） |
| `stickyHeader` | boolean | false | 滚动时保持表头可见 |
| `sortable` | boolean | false | 启用点击列标题排序 |

### Row

| 属性 | 类型 | 默认值 | 描述 |
|------|------|---------|-------------|
| `header` | boolean | false | 渲染为表头行 |
| `highlight` | boolean | false | 高亮该行 |
| `highlightColor` | string | primary | 颜色：primary、success、warning、error、info |

### Cell

| 属性 | 类型 | 默认值 | 描述 |
|------|------|---------|-------------|
| `align` | string | left | 文本对齐方式：left、center、right |
| `colSpan` | number | - | 要跨越的列数 |
| `rowSpan` | number | - | 要跨越的行数 |
| `highlight` | boolean | false | 高亮该单元格 |
| `highlightColor` | string | primary | 颜色：primary、success、warning、error、info |
| `header` | boolean | false | 强制使用表头样式 |

## 下一步

<Columns cols={2}>
  <Card title="组件概览" icon="puzzle-piece" href="/cn/components/overview">
    浏览所有可用组件
  </Card>
  <Card title="MDX 基础" icon="file-code" href="/cn/content/mdx-basics">
    了解如何在 MDX 中使用组件
  </Card>
</Columns>