The el-tree-table component is based on vue and element-ui, and adds some new features based on the implementation of vue-element-admin. And hereby declare that treetable's business implementation will come from the above-mentioned open source projects. If there is any offense, please contact us in time. It is written based on the el-table of element-ui.
The extension mainly includes: displaying borders, fixed height, displaying check boxes, whether check box selection follows parent-child association, and check box disabling conditions.
npm i @weilan/el-tree-table --save
or
npm i @weilan/el-tree-table -S
import TreeTable from '@weilan/el-tree-table'
Vue.use(TreeTable)
Example
<treeTable :data="tree_table" :columns="columns" checkBox expandAll parentChild border :options="{key:'id', children:'Children'}" @treeTableSelect="getTreeTableSelect" />
<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>
Parameters: data Description:树形数据type: Array, Object Required: true Supplement:对象或数组
Parameters: columns Description:列属性type: Array Required: false Supplementary: text: 显示在表头的文字,value: 对应data的key。treeTable将显示相应的value, width: 每列的宽度,为一个数字(可选),如果你想要每个字段都有自定义的样式或者嵌套其他组件,columns可不提供,直接像在el-table一样写即可,如果没有自定义内容,提供columns将更加的便捷方便
Parameters: expandAll Description:是否展开全部types: Boolean Required: false
Parameters: evalFunc Description:解析函数type: Function
Parameters: evalArgs Description:解析函数参数type: Array
For the above description, please see (https://github.com/PanJiaChen/vue-element-admin/tree/master/src/components/TreeTable).
Parameters: options description: nodekey字段及children字段type: Boolean required: false Supplement:重要!根据id和children盒子字段来父子关联处理数据,默认{key: "id", children: "children"},如需自定义,请一块修改
Parameters: checkBox Description:是否显示复选框Type: Boolean Required: false
Parameters: height description:用于固定表头type: Number required: false
Parameters: border description:显示边框type: Boolean Required: false Supplement:默认为true显示边框
Parameters: disabled Description:当checkBox为true显示复选框时可用,判断是否禁用字段: String supplement:此参数传入内容为:data中表示复选框是否禁用的数据字段例{isDisabled: true, id: 1, children:[]},则disabled: 'isDisabled'
Parameters: parentChild Description:当checkBox为true显示复选框时可用,表示是否遵循父子关联Type: Boolean Supplement:默认false
Event: openChildren Description:点击图标展开子元素事件callback: function(row, status), 返回点击行Object, 展开状态Boolean
Event: treeTableClick Description:点击列表行事件callback: function(row), 返回点击行,注意:重复点击则取消选中并返回{}
Event: treeTableSelect Description:复选框选中事件callback: function(val), 返回选中数据
slot:这是一个自定义列的插槽slot and columns属性can exist at the same time. The data columns in the columns will be displayed to the left of the slot custom column.