@weilan/el-tree-table v0.1.7
el-tree-table
简介
el-tree-table组件基于vue和element-ui,在 vue-element-admin 的实现基础上增加一些新特性。 并在此声明treetable的业务实现再来上述开源项目,如有冒犯,请及时联系。 共同依据element-ui的el-table写成。
扩展主要包括:显示边框、固定高度、显示复选框、复选框选中是否遵循父子关联、复选框禁用条件。
在线访问 - GitHub
这里有一个兄弟组件-树形穿梭框:在线访问 - GitHub
快速上手
npm i @weilan/el-tree-table --save
或
npm i @weilan/el-tree-table -S
import TreeTable from '@weilan/el-tree-table'
Vue.use(TreeTable)
示例
<div id="app" class="example"> <treeTable :data="tree_table" :columns="columns" checkBox expandAll parentChild border :options="{key:'id', children:'Children'}" @treeTableSelect="getTreeTableSelect" /> </div> </template>
<script>
export default {
name: 'app',
data(){
return {
columns: [
{
value: "id",
text: "值",
},
{
value: "name",
text: "名字"
}
],
tree_table:[
{
id: "1",
name: "第1级",
Children: [
{
id: "1-1",
name: "第1-1级",
Children: [
/* {
id: "1-1-1",
name: "第1-1-1级",
}, */
{
id: "1-1-2",
name: "第1-1-2级",
Children: [
{
id: "1-1-2-1",
name: "第1-1-2-1级",
},
{
id: "1-1-2-2",
name: "第1-2-2-2级",
},
]
},
]
},
{
id: "1-2",
name: "第1-2级",
Children: [
{
id: "1-2-1",
name: "第1-2-1级",
},
{
id: "1-2-2",
name: "第1-2-2级",
},
]
},
]
}
]
}
},
methods: {
getTreeTableSelect(val){
console.log(val);
}
},
}
</script>文档
参数:
data说明:树形数据类型:Array, Object必填:true补充:对象或数组参数:
columns说明:列属性类型:Array必填:false补充:text: 显示在表头的文字,value: 对应data的key。treeTable将显示相应的value, width: 每列的宽度,为一个数字(可选),如果你想要每个字段都有自定义的样式或者嵌套其他组件,columns可不提供,直接像在el-table一样写即可,如果没有自定义内容,提供columns将更加的便捷方便参数:
expandAll说明:是否展开全部类型:Boolean必填:false参数:
evalFunc说明:解析函数类型:Function参数:
evalArgs说明:解析函数参数类型:Array
以上说明详见(https://github.com/PanJiaChen/vue-element-admin/tree/master/src/components/TreeTable)。
参数:
options说明:nodekey字段及children字段类型:Boolean必填:false补充:重要!根据id和children盒子字段来父子关联处理数据,默认{key: "id", children: "children"},如需自定义,请一块修改参数:
checkBox说明:是否显示复选框类型:Boolean必填:false参数:
height说明:用于固定表头类型:Number必填:false参数:
border说明:显示边框类型:Boolean必填:false补充:默认为true显示边框参数:
disabled说明:当checkBox为true显示复选框时可用,判断是否禁用字段类型:String补充:此参数传入内容为:data中表示复选框是否禁用的数据字段 例{isDisabled: true, id: 1, children:[]},则disabled: 'isDisabled'参数:
parentChild说明:当checkBox为true显示复选框时可用,表示是否遵循父子关联类型:Boolean补充:默认false事件:
openChildren说明:点击图标展开子元素事件回调:function(row, status), 返回点击行Object, 展开状态Boolean事件:
treeTableClick说明:点击列表行事件回调:function(row), 返回点击行,注意:重复点击则取消选中并返回{}事件:
treeTableSelect说明:复选框选中事件回调:function(val), 返回选中数据slot:
这是一个自定义列的插槽slot和columns属性可同时存在,columns里面的数据列会在slot自定义列的左边展示