表格
将数据组织为行和列。支持 Markdown 表格和 Table 组件,并提供排序、高亮和跨行列合并功能。
表格用于将数据组织为行和列。简单的表格可使用 Markdown 表格快速创建;如需高亮、对齐等更多选项,请使用 Table 组件。
用法
<Table>
<Row header>
<Cell>Name</Cell>
<Cell>Type</Cell>
</Row>
<Row>
<Cell>id</Cell>
<Cell>string</Cell>
</Row>
</Table>
Markdown 表格
这是创建表格最快的方式。使用竖线(|)分隔列,使用连字符(-)构成表头行:
| Name | Type | Description |
|------|------|-------------|
| id | string | Unique identifier |
| email | string | User email address |
| Name | Type | Description |
|---|---|---|
| id | string | Unique identifier |
| string | User email address |
对于简单的参考数据,请使用 Markdown 表格。如需高亮、对齐或视觉强调,请切换到 Table 组件。
Table 组件
如需更多控制,请使用 <Table>、<Row> 和 <Cell> 组件:
<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>
| Name | Type | Description |
|---|---|---|
| id | string | Unique identifier |
| string | User email address |
斑马纹行
添加交替的行背景色,提升可读性:
<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>
| Parameter | Value |
|---|---|
| timeout | 30s |
| retries | 3 |
| backoff | exponential |
| maxDelay | 60s |
边框与紧凑布局
在单元格之间添加边框,并减少内边距:
<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>
| A | B | C |
|---|---|---|
| 1 | 2 | 3 |
高亮行
高亮整行以引起注意:
<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>
| Field | Required | Description |
|---|---|---|
| api_key | Yes | Your API authentication key |
| limit | No | Maximum results (default: 100) |
可用的高亮颜色:primary、success、warning、error、info
高亮单元格
高亮单个单元格,用作状态指示:
<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>
| Service | Status |
|---|---|
| API | Operational |
| Database | Degraded |
| Storage | Outage |
单元格对齐
按单元格控制文本对齐方式:
<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>
| Left | Center | Right |
|---|---|---|
| Text | Text | $99.99 |
跨列与跨行
跨列或跨行合并单元格:
<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>
| Category | Item | Price |
|---|---|---|
| Fruits | Apple | $1.00 |
| Banana | $0.50 | |
| Subtotal | $1.50 | |
可见标题
在表格上方显示无障碍表格标题:
<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>
| Region | Revenue |
|---|---|
| North America | $1.2M |
可排序列
使用 sortable 属性开启列排序。点击列标题即可排序:
<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>
| Name | Price | Stock |
|---|---|---|
| Widget A | $29.99 | 150 |
| Gadget B | $49.99 | 75 |
| Tool C | $19.99 | 200 |
| Device D | $99.99 | 25 |
点击列标题一次为升序排列,再点击一次为降序,第三次点击恢复原始顺序。数字按数值排序,文本按字母顺序排序。
将 sortable 与 striped 等其他属性组合使用:
<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>
| Team | Wins | Losses |
|---|---|---|
| Eagles | 12 | 4 |
| Bears | 8 | 8 |
| Lions | 10 | 6 |
属性
Table
| Prop | Type | Default | Description |
|---|---|---|---|
striped | boolean | false | 交替行背景色 |
bordered | boolean | false | 所有单元格之间添加边框 |
compact | boolean | false | 减少单元格内边距 |
fullWidth | boolean | true | 表格占满整个宽度 |
caption | string | - | 表格标题文本 |
captionVisible | boolean | false | 视觉上显示标题(默认仅供屏幕阅读器使用) |
stickyHeader | boolean | false | 滚动时保持表头可见 |
sortable | boolean | false | 启用列标题点击排序 |
Row
| Prop | Type | Default | Description |
|---|---|---|---|
header | boolean | false | 渲染为表头行 |
highlight | boolean | false | 高亮该行 |
highlightColor | string | primary | 颜色:primary、success、warning、error、info |
Cell
| Prop | Type | Default | Description |
|---|---|---|---|
align | string | left | 文本对齐:left、center、right |
colSpan | number | - | 跨越的列数 |
rowSpan | number | - | 跨越的行数 |
highlight | boolean | false | 高亮该单元格 |
highlightColor | string | primary | 颜色:primary、success、warning、error、info |
header | boolean | false | 强制使用表头样式 |
