Table 表格

用法

基本用法

基础表格
当有大量的结构化的数据需要展示的时候,可以使用表格组件;需要指定每列的数据和数据源
点击查看代码
<wd-table
  :columns="[{title: 'ID', dataIndex: 'id'}, {title: '商品名', dataIndex: 'goods_name'}, {title: '价格', dataIndex: 'price'}, {title: '生产日期', dataIndex: 'ctime'}]"
  :data-source="[{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'}]"
></wd-table>
1
2
3
4

带边框

带边框表格
设置bordered或者bordered=true,表格会带边框
点击查看代码
<wd-table
  :columns="[{title: 'ID', dataIndex: 'id'}, {title: '商品名', dataIndex: 'goods_name'}, {title: '价格', dataIndex: 'price'}, {title: '生产日期', dataIndex: 'ctime'}]"
  :data-source="[{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'}]"
  bordered
></wd-table>
1
2
3
4
5

自动省略

单元格内容自动省略
如果设置了单元格自动省略,当内容过长时会显示省略号
点击查看代码
<wd-table
  :columns="[{title: 'ID', dataIndex: 'id'}, {title: '商品名', dataIndex: 'goods_name'}, {title: '价格', dataIndex: 'price'}, {title: '生产日期', dataIndex: 'ctime'}]"
  :data-source="[{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'}]"
  :cell-wrap="true"
></wd-table>
1
2
3
4
5

固定表头

固定表头
设置sticky=true后,表头会固定,只有表体部分可以滚动
点击查看代码
<wd-table
  :columns="[{title: 'ID', dataIndex: 'id'}, {title: '商品名', dataIndex: 'goods_name'}, {title: '价格', dataIndex: 'price'}, {title: '生产日期', dataIndex: 'ctime'}]"
  :data-source="[{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'}]"
  :sticky="true"
></wd-table>
1
2
3
4
5

选择行

表格行选择
在设置columns属性时,如果列的type为checkbox,则该列为选择列
点击查看代码
<wd-table
  :columns="[{title: '', dataIndex: '', type: 'checkbox'}, {title: 'ID', dataIndex: 'id'}, {title: '商品名', dataIndex: 'goods_name'}, {title: '价格', dataIndex: 'price'}, {title: '生产日期', dataIndex: 'ctime'}]"
  :data-source="[{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'},{id: '1', goods_name: 'sk2', price: '123', ctime: '2021-09-26'}]"
  :sticky="true"
></wd-table>
1
2
3
4
5

属性

参数说明类型可选值默认值
bordered是否显示边框booleantrue / falsefalse
columns列的配置array--
current-page当前页number-1
data-source数据源array--
height表格高度string--
header-align表头文字位置stringleft / center / rightleft
page-count总页数number / string-1
page-size每页数据个数number / string-15
pagination-position分页器位置stringleft / center / rightleft
total数据总数number / string--

事件

事件名称说明回调参数
current-change当前页变化的回调函数Function(currentPage)
select-change选择行变化的回调函数Function(selectedRows)
cell-click单元格点击Function({ row, rowIndex, dataIndex, value })
row-click行的点击Function(currentRow)
next-click分页器下一页点击的回调函数Function(currentPage)
prev-click分页器上一页点击的回调函数Function(currentPage)