项目作者: huanglong6828

项目描述 :
基于vue和优秀的iView组件库的树型表格(tree-table/tree-grid)
高级语言: Vue
项目地址: git://github.com/huanglong6828/vue-tree-grid.git
创建时间: 2017-07-19T09:29:47Z
项目社区:https://github.com/huanglong6828/vue-tree-grid

开源协议:

下载


tree-grid

基于vue和iview组件库的树型表格
主要使用了 iview(checkbox组件,icon组件,button组件) 同时部分表格渲染模仿iview表格 支持iview

DEMO 如果对您如果有帮助的话,给颗星谢谢

版本支持

VUE1.0/2.0 使用时请下载对应iview

自适应功能新增

  1. 1. width 字段增加
  2. 2. td总和大于容器宽宽度 出现滚动条 否则表格自适应 需要使用者下载组件后 修改源码中 document.body.clientWidth 修改为 document.getElementsByClassName('你的容器')[0].clientWidth

新增默认选中

  1. 1. _checked字段增加
  2. 2. data项设置特殊 key _checked: true

2.0 多选框样式错乱,默认选中问题

  1. 1. 修改为元素checkbox 样式大概调整
  2. 2. 如果样式不好看 可以自行修改或者使用其他组件ui checkbox

API

props

属性 说明 类型
items 显示的结构化数据 Array
columns 表格列的配置描述 Array

columns

属性 说明 类型 默认值
title 列头显示文字 String #
key 对应列内容的字段名 String #
width 列宽名 Number #
sortable 排序功能 Boolean false
type ‘selection’:多选功能 String #
type ‘action’ 操作功能, 必填参数:actions:[{}] String #

events

事件名 说明 返回值
@on-row-click 单击行或者单击操作按钮方法 data,$event,index
@on-selection-change 返回选中数组 arr
@on-sort-change 表格列的配置描述 key和排序规则(值为 asc 或 desc)

使用方式

  1. <template>
  2. <tree-grid
  3. :items='data'
  4. :columns='columns'
  5. @on-row-click='rowClick'
  6. @on-selection-change='selectionClick'
  7. @on-sort-change='sortClick'
  8. ></tree-grid>
  9. </template>
  10. <script>
  11. import TreeGrid from './components/TreeGrid'
  12. export default {
  13. data() {
  14. return {
  15. columns: [{
  16. type: 'selection',
  17. width: '50',
  18. }, {
  19. title: '编码',
  20. key: 'code',
  21. sortable: true,
  22. width: '150',
  23. }, {
  24. title: '名称',
  25. key: 'name',
  26. width: '150',
  27. }, {
  28. title: '状态',
  29. key: 'status',
  30. width: '150',
  31. }, {
  32. title: '备注',
  33. key: 'remark',
  34. width: '150',
  35. }, {
  36. title: '操作',
  37. type: 'action',
  38. actions: [{
  39. type: 'primary',
  40. text: '编辑'
  41. }, {
  42. type: 'error',
  43. text: '删除'
  44. }],
  45. width: '150',
  46. }],
  47. data: [{
  48. id: '1',
  49. code: '0001',
  50. name: '测试数据1',
  51. status: '启用',
  52. remark: '测试数据测试数据',
  53. _checked: true
  54. }, {
  55. id: '2',
  56. code: '0002',
  57. name: '测试数据2',
  58. status: '启用',
  59. remark: '测试数据测试数据',
  60. children: [{
  61. id: '01',
  62. code: '00001',
  63. name: '测试数据01',
  64. status: '启用',
  65. remark: '测试数据测试数据',
  66. }, {
  67. id: '02',
  68. code: '00002',
  69. name: '测试数据02',
  70. status: '启用',
  71. remark: '测试数据测试数据',
  72. }]
  73. }, {
  74. id: '3',
  75. code: '0003',
  76. name: '测试数据3',
  77. status: '启用',
  78. remark: '测试数据测试数据'
  79. }, {
  80. id: '4',
  81. code: '0004',
  82. name: '测试数据4',
  83. status: '启用',
  84. remark: '测试数据测试数据'
  85. }]
  86. }
  87. },
  88. components: {
  89. TreeGrid
  90. },
  91. methods: {
  92. rowClick(data, index, event) {
  93. console.log('当前行数据:' + data)
  94. console.log('点击行号:' + index)
  95. console.log('点击事件:' + event)
  96. },
  97. selectionClick(arr) {
  98. console.log('选中数据id数组:' + arr)
  99. },
  100. sortClick(key, type) {
  101. console.log('排序字段:' + key)
  102. console.log('排序规则:' + type)
  103. }
  104. }
  105. }
  106. </script>

使用方式

  1. # 安装依赖
  2. npm install iview
  3. main.js 引入
  4. import iView from 'iview';
  5. import 'iview/dist/styles/iview.css';
  6. Vue.use(iView);
  7. treeGird 放入工程项目 例如 components/treeGird