# 数据表格

- 页面: https://jiguang132.com/zh/resources/daisyui/docs/table
- 资源: daisyUI (https://jiguang132.com/zh/resources/daisyui.md)
- 全部指南: https://jiguang132.com/zh/resources/daisyui/docs.md

保留 table、表头和单元格语义，必要时加 caption。固定行列需要受控滚动容器；排序、分页和虚拟化需另行实现，窄屏不能直接裁掉数据。

## 安装与初始化

```bash
npm install -D tailwindcss@4.2.1 @tailwindcss/cli@4.2.1 daisyui@5.7.47
```

这是原生 CSS 插件，不是 React 组件导入。先用 Tailwind 4 和 daisyUI 插件生成并加载样式，再复制示例。完整步骤见随附安装指南；不要盲目覆盖宿主的 React 或 Tailwind 版本。

```css
@import "tailwindcss";
@plugin "daisyui" { themes: light --default, dark --prefersdark; }
```

## 源码与真实交互

源码文件保留原始代码块、注释和演示文字。$$ 类名前缀占位符需按你的插件配置处理：未配置前缀时，$$btn 改为 btn。复制所选示例列出的全部源文件，按框架组合 HTML、CSS、JavaScript 并保留原生事件。预览的已审查事件适配器不是后端，也不会随 npm 命令自动安装到你的应用。

## 首个完整示例

```html
<div class="overflow-x-auto">
  <table class="$$table">
    <!-- head -->
    <thead>
      <tr>
        <th></th>
        <th>Name</th>
        <th>Job</th>
        <th>Favorite Color</th>
      </tr>
    </thead>
    <tbody>
      <!-- row 1 -->
      <tr>
        <th>1</th>
        <td>Cy Ganderton</td>
        <td>Quality Control Specialist</td>
        <td>Blue</td>
      </tr>
      <!-- row 2 -->
      <tr>
        <th>2</th>
        <td>Hart Hagerty</td>
        <td>Desktop Support Technician</td>
        <td>Purple</td>
      </tr>
      <!-- row 3 -->
      <tr>
        <th>3</th>
        <td>Brice Swyre</td>
        <td>Tax Accountant</td>
        <td>Red</td>
      </tr>
    </tbody>
  </table>
</div>
```

## 全部可运行示例

### 基础表格

`table-1`

```bash
npm install -D tailwindcss@4.2.1 @tailwindcss/cli@4.2.1 daisyui@5.7.47
```

- `examples/table/block-0.html`

### 边框与背景

`table-2`

```bash
npm install -D tailwindcss@4.2.1 @tailwindcss/cli@4.2.1 daisyui@5.7.47
```

- `examples/table/block-1.html`

### 激活行

`table-3`

```bash
npm install -D tailwindcss@4.2.1 @tailwindcss/cli@4.2.1 daisyui@5.7.47
```

- `examples/table/block-2.html`

### 悬停高亮行

`table-4`

```bash
npm install -D tailwindcss@4.2.1 @tailwindcss/cli@4.2.1 daisyui@5.7.47
```

- `examples/table/block-3.html`

### 斑马纹

`table-5`

```bash
npm install -D tailwindcss@4.2.1 @tailwindcss/cli@4.2.1 daisyui@5.7.47
```

- `examples/table/block-4.html`

### 可视化单元格

`table-6`

```bash
npm install -D tailwindcss@4.2.1 @tailwindcss/cli@4.2.1 daisyui@5.7.47
```

- `examples/table/block-5.html`

### 超小尺寸

`table-7`

```bash
npm install -D tailwindcss@4.2.1 @tailwindcss/cli@4.2.1 daisyui@5.7.47
```

- `examples/table/block-6.html`

### 固定表头行

`table-8`

```bash
npm install -D tailwindcss@4.2.1 @tailwindcss/cli@4.2.1 daisyui@5.7.47
```

- `examples/table/block-7.html`

### 固定行与列

`table-9`

```bash
npm install -D tailwindcss@4.2.1 @tailwindcss/cli@4.2.1 daisyui@5.7.47
```

- `examples/table/block-8.html`

## 主题、无障碍与验证

使用原生 data-theme 主题边界。验证键盘、标签、可见焦点、适用的禁用／错误状态、深浅色、移动端和减少动画。检查目标浏览器的 dialog、popover 和 CSS 特性支持；类名不会补齐未实现的 JavaScript 或业务服务。卸载时清理计时器和第三方实例；复制命令不等于安装成功。

## 来源与许可证

https://github.com/saadeghi/daisyui/tree/c51f50130ffefb293179e6fce8de7ad3f307e45f

本页是 JGuang 编写的双语实用说明，不声称全文翻译上游文档。原始 Markdown、代码和 CSS 保留在源码查看器。保留 MIT 与各依赖独立声明；保守附上整个原生环境的许可，包括构建工具，但不分发构建二进制或远程演示图片。实际项目请替换为有使用权的素材，不包含商业模板。

---

JGuang 全部资源索引: https://jiguang132.com/llms.txt
