V1.0.0
Skip to content

WTable 表格组件

表格组件,基于 WinDesignNext WTable 封装,用于渲染表格数据。

基础用法

单元格渲染方式

WTableColumn 支持 两种渲染方式,根据需求选择:

方式一:prop 自动渲染(推荐简单场景)

json
{
  "id": "col_age",
  "component": "WTableColumn",
  "label": "年龄",
  "prop": "age"
}

自动渲染 scope.row.age 的值,无需额外配置。

方式二:children 自定义渲染(推荐复杂场景)

当需要:

  • 添加文本样式(颜色、大小)
  • 嵌套其他组件(按钮、标签)
  • 自定义格式化逻辑

使用 children 配置:

json
{
  "id": "col_name",
  "component": "WTableColumn",
  "label": "姓名",
  "children": ["col_name_text"]
},
{
  "id": "col_name_text",
  "component": "WText",
  "type": "success",
  "text": {
    "path": "@row.name"
  }
}

关键注意点

使用 children 时,必须使用 scope 路径 (@row.xxx) 获取当前行数据!

json
// ❌ 错误 - 无法获取当前行数据
"text": { "path": "/userData/name" }

// ✅ 正确 - 使用 scope 路径
"text": { "path": "@row.name" }

Scope 路径详解

在表格自定义渲染中,每行都有独立的 scope 对象:

js
scope = {
  row: { name: '张三', age: 28 },  // 当前行数据
  column: { ... },                  // 列配置
  $index: 0                         // 行索引
}

路径格式

写法含义示例
@row.xxx当前行的 xxx 字段(推荐)@row.name
scope.row.xxx同上(完整格式)scope.row.name
@row.xxx.yy嵌套字段@row.user.name

属性参考

WTable

属性类型说明默认值
idstring组件唯一标识-
componentstring固定值 WTable-
dataSourcestring数据路径,如 /tableData-
childrenstring[]列组件 ID 数组[]
borderboolean是否显示边框false
stripeboolean是否显示斑马纹false
heightnumber表格高度-
showHeaderboolean是否显示表头true

path 支持说明

通用绑定格式见 path 数据绑定速查

属性支持 path说明
WTable.dataSource字符串路径,指向 dataModel 中的表格行数组
单元格自定义渲染子组件使用 @row.xxx 访问当前行数据
WTableColumn.prop⚠️使用 @fieldName 表示字段名(非 dataModel 路径)
border / stripe / height静态配置

dataSource 绑定示例:

json
{
  "component": "WTable",
  "dataSource": "/tableData",
  "children": ["col_name"]
}

单元格 scope 路径示例:

json
{
  "component": "WText",
  "text": { "path": "@row.name" },
  "type": "primary"
}

WTableColumn

属性类型说明默认值
idstring组件唯一标识-
componentstring固定值 WTableColumn-
labelstring列标题-
propstring对应数据字段名(自动渲染)-
childrenstring[]自定义单元格组件(scope渲染)[]
widthnumber列宽度-
minWidthnumber最小列宽度-
fixedstring固定位置 left/right-
typestringselection/index-