import { Table } from 'element-ui';
export default {
name: 'AdminTable',
props: Object.assign({}, Table.props, {
columns: { type: Array, default: null },
rowClass: { type: Function, default: null }
}),
data() {
return {};
},
methods: {
renderChildrenCols: function (h, column) {
let this_ = this;
let itemArr = [];
column.children.forEach(function (item) {
itemArr.push(this_.renderItem(h, item));
});
return h(
'el-table-column',
{
props: column
},
itemArr
);
},
renderItem: function (h, column) {
return column.children ? this.renderChildrenCols(h, column) : this.renderColsItem(h, column);
},
renderColsItem: function (h, item) {
let customSlot = this.$scopedSlots[item.customSlot];
return h('el-table-column', {
props: item,
scopedSlots: customSlot
? {
default: props => customSlot({ ...props, colItem: item })
}
: {}
});
},
renderTable: function (h, colsTree) {
let this_ = this;
let arr = [];
colsTree.forEach(function (item, i) {
arr.push(this_.renderItem(h, item, '0', i));
});
return arr;
}
},
render(createElement) {
return createElement(
Table,
{
props: {
...this.$props
},
ref: 'elementRef',
style: {
width: '100%'
},
class: 'admin-table-ui',
on: {
'selection-change': selection => {
this.$emit('selection-change', selection);
},
select: (selection, row) => {
this.$emit('select', selection, row);
},
'expand-change': (row, expanded) => {
this.$emit('expand-change', row, expanded);
}
}
},
this.renderTable(createElement, this.columns)
);
}
};