1.1.18 • Published 4 years ago

tree-table-vue-extend v1.1.18

Weekly downloads
181
License
MIT
Repository
-
Last release
4 years ago

tree-table-vue-exend

A table (with tree-grid) component which based on tree-table-vue v1.1.0 for Vue.js 2.0 and add some features based on team's own need. @MisterTaki) and @lison16

当前版本v1.1.18

其他特性

添加排序,在需要排序的列column对象中添加sortable: true属性,同时使用@on-sort-change绑定排序变更事件

提供表头单元格合并功能,详细用法请参考example/Example.vue

数据更新后已展开节点不会收折(可以通过keep-tree-expand关闭),可以通过idProp属性指定数据中唯一key(如默认的id字段: idProp="id")

快速添加子项,自定义template,用法如下(按钮及表单为iView组件)

getCheckedProp为getCheckedProps方法,入参为行数据的属性key的数组,如'id', 'name'就可以获取id和name的值

优化tree-icon-click时间回调参数isExpanded,用于异步拉去数据,如果为true说明是展开事件

通过this.$refs.table.treeLoadingTrigger(row[$idProp], true)将唯一标志指定行的展开图标变换为loading图标,其中$idProp需要替换为id-prop属性值

使用方式

<!-- 调用tree-table,并指定属性create-data-obj -->
<tree-table :create-data-obj="createDataObj">
  <template slot="$createdata" slot-scope="createdata">
    <!-- 自定义部分开始 -->
    <!-- 创建父级数据按钮 -->
    <div style="margin-left: 50px;padding: 5px;" v-show="!createdata.tmpData.status && createdata.rowIndex == -1">
      <Button type="info" style="margin-left: 10px" @click="showCreateDataForm(createdata)">Add</Button>
    </div>
    <!-- 创建数据表单 -->
    <div style="margin-left: 50px;padding: 5px;" v-show="createdata.tmpData.status">
      <Form :model="createdata.tmpData.data" inline>
        <FormItem prop="name">
            <Input type="text" v-model="createdata.tmpData.data.name" placeholder="name">
            </Input>
        </FormItem>
        <FormItem prop="sex">
            <Input type="text" v-model="createdata.tmpData.data.sex" placeholder="sex">
            </Input>
        </FormItem>
        <FormItem>
            <Button type="primary" @click="addDataAndHideForm(createdata)">Add</Button>
        </FormItem>
      </Form>
    </div>
    <!-- 自定义部分结束 -->
  </template>
</tree-table>

其中scope对象createdata包含三个对象row-当前操作列,rowIndex-当前操作列索引号(从-1开始),tmpData-当前操作列状态信息(包含表单对象属性data和表单显示状态属性status),同时需要通过props指定表单对象模板属性create-data-obj,该属性为需要新增的表单对像;

Example

Example

Installation

Use npm:

npm i tree-table-vue-extend -S

Or use yarn:

yarn add tree-table-vue-extend

Usage

import Vue from 'vue'
import TreeTable from 'tree-table-vue-extend'

Vue.use(TreeTable)

Or

import Vue from 'vue'
import TreeTable from 'tree-table-vue-extend'

Vue.component(TreeTable.name, TreeTable)

more information please see example..., or git clone this repository and open dev mode (I will give it a homepage later...).

API

Table Attributes

属性说明类型参数默认值
data表格各行的数据Array-[]
empty-text表格数据为空时显示的文字String-'暂无数据'
columns表格各列的配置(具体见下文:Columns Configs)Array-[]
expand-key需要显示展开按钮的列的key(columns列对象里的prop)String-默认是第一列的prop
show-header是否显示表头Boolean-true
show-index是否显示数据索引Boolean-false
index-text数据索引名称String-'序号'
show-summary是否显示表尾合计行Boolean-false
sum-text表尾合计行首列名称String-'合计'
summary-method表尾合计行计算方法Functiondata, column, columnIndex-
max-height最大高度String, Number-'auto'
stripe是否显示间隔斑马纹Boolean-false
border是否显示纵向边框Boolean-false
show-row-hover鼠标悬停时,是否高亮当前行Boolean-true
tree-type是否为树形表格Boolean-false
children-prop树形表格中遍历的属性名称String-'children'
expand-type是否为展开行类型表格(为 True 时,需要添加名称为 '$expand' 的作用域插槽, 它可以获取到 row, rowIndex)Boolean-false
selectable是否为多选类型表格Boolean-false
select-type选择列渲染的形式, radio或checkboxString-checkbox
loading是否显示载入中状态(可通过slot方式自定义载入样式<tree-table><div slot="loading">数据载入中...</div></tree-table>)Boolean-false
id-prop指定行数据唯一标识的列keyString-'id'
keep-tree-expand保持已展开列的展开状态Boolean-false
force-expand-icon-prop用于通过该属性指定的列key来判断该行数据是否有子集(用于异步操作)String-'isBase'
checkedRows初始化已选行,数组的值需要为id-prop指定列的值Array-[]
disabledRows初始化禁选行,数组的值需要为id-prop指定列的值Array-[]
row-key行数据的 Key,用来优化 Table 的渲染Functionrow, rowIndexrowIndex
row-class-name额外的表格行的类名String, Functionrow, rowIndex-
cell-class-name额外的表格行的类名String, Functionrow, rowIndex, column, columnIndex-
row-style额外的表格行的样式Object, Functionrow, rowIndex-
cell-style额外的表格单元格的样式Object, Functionrow, rowIndex, column, columnIndex-

Columns Configs

属性说明类型默认值
title列标题名称String''
key对应列内容的属性名String''
align对应列内容的对齐方式,可选值有 'center', 'right'String'left'
headerAlign对应列标题的对齐方式,可选值有 'center', 'right'String'left'
width列宽度String, Number'auto'
minWidth列最小宽度String, Number'80px'
type列类型,可选值有 'template'(自定义列模板)String''
sortable列类型,是否启用排序,默认falseBooleanfalse
className列类型,自定义inner样式,e.g. 'my-class-1','my-class-2'Array[]
template列类型为 'template'(自定义列模板) 时,对应的作用域插槽(它可以获取到 row, rowIndex, column, columnIndex)名称String''

Table Events

事件名说明参数
cell-click单击某一单元格row, rowIndex, column, columnIndex, $event
cell-dblclick双击某一单元格row, rowIndex, column, columnIndex, $event
cell-contextmenu在某一单元格上点击鼠标右键row, rowIndex, column, columnIndex, $event
cell-mouseenter鼠标滑入某一单元格row, rowIndex, column, columnIndex, $event
cell-mouseleave鼠标滑出某一单元格row, rowIndex, column, columnIndex, $event
row-click单击某一行row, rowIndex, $event
row-dblclick双击某一行row, rowIndex, $event
row-contextmenu在某一行上点击鼠标右键row, rowIndex, $event
row-mouseenter鼠标滑入某一行row, rowIndex, $event
row-mouseleave鼠标滑出某一行row, rowIndex, $event
checkbox-click鼠标单击checkboxrow, rowIndex, $event
tree-icon-click鼠标单击树形iconrow, column, columnIndex, $event, isExpanded(表示当前是展开(true)还是收则(false))
expand-cell-click鼠标单击展开单元格row, rowIndex, $event
on-sort-change排序变更事件column, orderType(descascnormal)

Table Methods

方法名说明参数
getCheckedProp当表格为多选类型表格时,用于获取当前所选项的属性,返回一个数组;属性默认为'index'array
getExpandedRows获取当前展开的列
foldAll全部展开/收折boolean
setDefaultExpandItems唯一标识的行展开,需要更新dataarray
1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.15

4 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago