表格
表格
表格使用标准 markdown 语法以行和列的形式显示数据。对于较长的数据集,您可以使用在滚动时保持可见的粘性表头。
用法
使用标准 markdown 语法创建表格,使用管道符 (|) 和连字符 (-):
变体
粘性表头
<StickyTable> 组件添加了一个在滚动时保持可见的固定表头。对于需要用户在整个表格中参考列表头的较长数据集,请使用粘性表格。
| Plant | Light Requirements | Water |
|---|---|---|
| Fern | Partial shade | Weekly |
| Snake Plant | Low to bright indirect | Bi-weekly |
| Monstera | Bright indirect | Weekly |
| Pothos | Low to bright indirect | Weekly |
| Fiddle Leaf Fig | Bright indirect | Weekly |
| Peace Lily | Low to medium indirect | Weekly |
| Rubber Plant | Bright indirect | Weekly |
| ZZ Plant | Low to bright indirect | Bi-weekly |
| Philodendron | Medium to bright indirect | Weekly |
| Aloe Vera | Bright direct | Bi-weekly |
| Boston Fern | Partial shade | 2-3x weekly |
| Spider Plant | Medium to bright indirect | Weekly |
| Dracaena | Medium indirect | Weekly |
| Bird of Paradise | Bright indirect to direct | Weekly |
| Calathea | Medium indirect | Weekly |
可搜索表格
<SearchableTable> 组件为大型表格启用客户端过滤。表格上方会出现一个搜索输入框,使用不区分大小写的子字符串匹配实时过滤行。使用 placeholder 属性自定义搜索输入占位符文本。
粘性可搜索表格
<StickySearchableTable> 组件结合了粘性表头和搜索功能:
| Plant | Light Requirements | Water |
|---|---|---|
| Fern | Partial shade | Weekly |
| Snake Plant | Low to bright indirect | Bi-weekly |
| Monstera | Bright indirect | Weekly |
| Pothos | Low to bright indirect | Weekly |
| Fiddle Leaf Fig | Bright indirect | Weekly |
| Peace Lily | Low to medium indirect | Weekly |
| Rubber Plant | Bright indirect | Weekly |
| ZZ Plant | Low to bright indirect | Bi-weekly |
| Philodendron | Medium to bright indirect | Weekly |
| Aloe Vera | Bright direct | Bi-weekly |
| Boston Fern | Partial shade | 2-3x weekly |
| Spider Plant | Medium to bright indirect | Weekly |
| Dracaena | Medium indirect | Weekly |
| Bird of Paradise | Bright indirect to direct | Weekly |
| Calathea | Medium indirect | Weekly |
HTML 可搜索表格
或者,为 HTML 表格元素添加 searchable 属性:
您可以将 searchable 与 sticky 结合使用来创建同时具有两种功能的表格:
带粘性表头的 HTML 表格
在开始的 <table> 标签中添加 sticky 属性。您的表格语法无需进一步更改。
| Plant | Light Requirements | Water |
|---|---|---|
| Fern | Partial shade | Weekly |
| Snake Plant | Low to bright indirect | Bi-weekly |
| Monstera | Bright indirect | Weekly |
| Pothos | Low to bright indirect | Weekly |
| Fiddle Leaf Fig | Bright indirect | Weekly |
| Peace Lily | Low to medium indirect | Weekly |
| Rubber Plant | Bright indirect | Weekly |
| ZZ Plant | Low to bright indirect | Bi-weekly |
| Philodendron | Medium to bright indirect | Weekly |
| Aloe Vera | Bright direct | Bi-weekly |
| Boston Fern | Partial shade | 2-3x weekly |
| Spider Plant | Medium to bright indirect | Weekly |
| Dracaena | Medium indirect | Weekly |
| Bird of Paradise | Bright indirect to direct | Weekly |
| Calathea | Medium indirect | Weekly |
自定义样式
粘性表格可以独立于常规表格进行样式设置。要添加自定义样式,请使用 .fern-table.sticky 选择器:
属性
<StickyTable> 属性
要显示带有粘性表头的 markdown 表格。表格必须使用标准 markdown 表格语法格式化。
<SearchableTable> 属性
要显示带有搜索功能的 markdown 表格。表格必须使用标准 markdown 表格语法格式化。
搜索输入的自定义占位符文本。默认为 "Search..."。
<StickySearchableTable> 属性
要显示同时具有粘性表头和搜索功能的 markdown 表格。表格必须使用标准 markdown 表格语法格式化。
搜索输入的自定义占位符文本。默认为 "Search..."。
HTML <table> 属性
当在 HTML 表格元素上设置时,使表格表头在滚动时保持粘性。
当在 HTML 表格元素上设置时,在表格上方添加一个搜索输入框,使用不区分大小写的子字符串匹配实时过滤行。
当启用 searchable 时搜索输入的自定义占位符文本。默认为 "Search..."。
应用于表格的 CSS 类名。使用 fern-table 获得默认的 Fern 样式。