On this page
manage_search
网格布局
网格布局让您在组内将字段定位在 CSS 网格中,实现多列表单设计。
网格布局功能让您使用 gridformat<> appearance 标签在组内将问题排列在多列网格中。这对于需要多个相关字段并排显示而不是垂直堆叠的密集数据录入表单很有用。
工作原理
网格布局在两个层级上应用:
- 组 — 设置
appearance: field-list grid(weight=N)以定义网格有多少列 - 组内的每个字段 — 设置
appearance: gridformat<row=R col=C colspan=S/>以定位字段
网格使用 12 列 Bootstrap 式系统。weight=N 定义您的网格有多少逻辑列;每列占 12/N 个 Bootstrap 列。
组级别 appearance
| Appearance | 描述 |
|---|---|
field-list grid(weight=2) | 2 列网格(每列 = 6 个 Bootstrap 列) |
field-list grid(weight=3) | 3 列网格(每列 = 4 个 Bootstrap 列) |
field-list grid(weight=4) | 4 列网格(每列 = 3 个 Bootstrap 列) |
field-list grid(weight=6) | 6 列网格(每列 = 2 个 Bootstrap 列) |
字段级别 gridformat<> 语法
gridformat<row=R col=C colspan=S/>
gridformat<row=R col=C colspan=S backgroundcolor=COLOR/>
| 属性 | 描述 |
|---|---|
row | 行号(从 1 开始) |
col | 列号(从 1 开始,在 weight 定义的网格内) |
colspan | 此字段跨越的列数(默认 1) |
backgroundcolor | 字段背景的可选 CSS 颜色(例如,#f0f0f0、lightblue) |
示例:2 列家庭调查章节
| type | name | label | appearance |
|---|---|---|---|
| begin_group | demographics | 人口统计 | field-list grid(weight=2) |
| text | first_name | 名字 | gridformat<row=1 col=1/> |
| text | last_name | 姓氏 | gridformat<row=1 col=2/> |
| integer | age | 年龄 | gridformat<row=2 col=1/> |
| select_one gender | gender | 性别 | gridformat<row=2 col=2/> |
| text | address | 完整地址 | gridformat<row=3 col=1 colspan=2/> |
| end_group |
这将渲染为:
[ 名字 ] [ 姓氏 ]
[ 年龄 ] [ 性别 ]
[ 完整地址(跨两列) ]
示例:3 列地块数据录入
| type | name | label | appearance |
|---|---|---|---|
| begin_group | plot_data | 地块详情 | field-list grid(weight=3) |
| text | plot_id | 地块 ID | gridformat<row=1 col=1/> |
| decimal | area_ha | 面积(公顷) | gridformat<row=1 col=2/> |
| select_one crop_type | crop | 农作物类型 | gridformat<row=1 col=3/> |
| decimal | yield | 产量(千克) | gridformat<row=2 col=1/> |
| decimal | revenue | 收入 | gridformat<row=2 col=2/> |
| text | notes | 备注 | gridformat<row=2 col=3/> |
| end_group |
背景颜色
使用 backgroundcolor 在视觉上区分章节:
| type | name | label | appearance |
|---|---|---|---|
| note | section_a | A 部分 | gridformat<row=1 col=1 colspan=2 backgroundcolor=#e8f4f8/> |
最佳实践
- 仅对数据录入密集型屏幕使用网格布局,其中并排字段真正减少了滚动。
- 保持
colspan=1字段简短(ID、代码、短选择)——宽标签在窄网格列中截断效果很差。 - 对标签较长或多行文本输入的字段使用
colspan=N。 - 在您期望枚举员使用的最小屏幕尺寸上测试——4 列网格在手机上会很拥挤。
- 网格布局最适合网页和平板电脑表单;在手机上,2 列布局通常是最大的舒适宽度。
限制
gridformat<>只在具有grid(weight=N)appearance 的组内有效——在顶层没有效果。- 网格布局是 rtSurvey 网页表单扩展,在其他 ODK 兼容客户端中可能无法正确渲染。
- 行和列定位在表单构建时不进行验证——重叠的字段都会渲染但可能看起来有问题。
此页面有帮助吗?