Table add content prop to compile custom component

Table add content prop to compile custom component
This commit is contained in:
梁灏 2016-12-01 11:02:06 +08:00
parent 224a3ae539
commit d0e206c501
4 changed files with 57 additions and 34 deletions

View file

@ -27,7 +27,8 @@
data () { data () {
return { return {
renderType: '', renderType: '',
uid: -1 uid: -1,
content: this.$parent.$parent.content
} }
}, },
computed: { computed: {
@ -43,7 +44,7 @@
methods: { methods: {
compile () { compile () {
if (this.column.render) { if (this.column.render) {
const $parent = this.$parent.$parent.$parent; const $parent = this.content;
const template = this.column.render(this.row, this.column, this.index); const template = this.column.render(this.row, this.column, this.index);
const cell = document.createElement('div'); const cell = document.createElement('div');
cell.innerHTML = template; cell.innerHTML = template;
@ -59,7 +60,7 @@
} }
}, },
destroy () { destroy () {
const $parent = this.$parent.$parent.$parent; const $parent = this.content;
for (let i = 0; i < $parent.$children.length; i++) { for (let i = 0; i < $parent.$children.length; i++) {
if ($parent.$children[i]._uid === this.uid) { if ($parent.$children[i]._uid === this.uid) {
$parent.$children[i].$destroy(); $parent.$children[i].$destroy();

View file

@ -34,7 +34,7 @@
</div> </div>
</div> </div>
<div slot="content" :class="[prefixCls + '-filter-list']" v-else> <div slot="content" :class="[prefixCls + '-filter-list']" v-else>
<ul> <ul :class="[prefixCls + '-filter-list-single']">
<li <li
:class="[prefixCls + '-filter-select-item', {[prefixCls + '-filter-select-item-selected']: !column._filterChecked.length}]" :class="[prefixCls + '-filter-select-item', {[prefixCls + '-filter-select-item-selected']: !column._filterChecked.length}]"
@click="handleReset($index)">全部</li> @click="handleReset($index)">全部</li>

View file

@ -122,6 +122,9 @@
default () { default () {
return ''; return '';
} }
},
content: {
type: Object
} }
}, },
data () { data () {
@ -243,6 +246,7 @@
let autoWidthIndex = -1; let autoWidthIndex = -1;
if (allWidth) autoWidthIndex = this.cloneColumns.findIndex(cell => !cell.width);//todo if (allWidth) autoWidthIndex = this.cloneColumns.findIndex(cell => !cell.width);//todo
if (this.data.length) {
const $td = this.$refs.tbody.$el.querySelectorAll('tbody tr')[0].querySelectorAll('td'); const $td = this.$refs.tbody.$el.querySelectorAll('tbody tr')[0].querySelectorAll('td');
for (let i = 0; i < $td.length; i++) { // can not use forEach in Firefox for (let i = 0; i < $td.length; i++) { // can not use forEach in Firefox
const column = this.cloneColumns[i]; const column = this.cloneColumns[i];
@ -260,6 +264,7 @@
} }
} }
this.columnsWidth = columnsWidth; this.columnsWidth = columnsWidth;
}
}); });
}); });
}, },
@ -502,6 +507,7 @@
} }
}, },
compiled () { compiled () {
if (!this.content) this.content = this.$parent;
this.showSlotHeader = this.$els.title.innerHTML.replace(/\n/g, '').replace(/<!--[\w\W\r\n]*?-->/gmi, '') !== ''; this.showSlotHeader = this.$els.title.innerHTML.replace(/\n/g, '').replace(/<!--[\w\W\r\n]*?-->/gmi, '') !== '';
this.showSlotFooter = this.$els.footer.innerHTML.replace(/\n/g, '').replace(/<!--[\w\W\r\n]*?-->/gmi, '') !== ''; this.showSlotFooter = this.$els.footer.innerHTML.replace(/\n/g, '').replace(/<!--[\w\W\r\n]*?-->/gmi, '') !== '';
this.rebuildData = this.makeDataWithSortAndFilter(); this.rebuildData = this.makeDataWithSortAndFilter();

View file

@ -1,27 +1,38 @@
<template> <template>
<i-table border :columns="columns1" :data="data1"></i-table> <Card>
<i-table :content="self" border :columns="columns7" :data="data6"></i-table>
</Card>
</template> </template>
<script> <script>
export default { export default {
data () { data () {
return { return {
columns1: [ self: this,
columns7: [
// {
// title: '',
// key: 'name',
// render (row, column, index) {
// return `<strong>${row.name}</strong>`;
// }
// },
// {
// title: '',
// key: 'age'
// },
// {
// title: '',
// key: 'address'
// },
{ {
title: '姓名', title: '操作',
key: 'name' key: 'action',
}, render (row, column, index) {
{ return `<i-button type="primary" size="small" @click="show(${index})">查看</i-button> <i-button type="error" size="small" @click="remove(${index})">删除</i-button>`;
title: '年龄', }
key: 'age',
fixed: 'left',
// width: 200
},
{
title: '地址',
key: 'address'
} }
], ],
data1: [ data6: [
{ {
name: '王小明', name: '王小明',
age: 18, age: 18,
@ -44,6 +55,11 @@
} }
] ]
} }
},
methods: {
remove (index) {
this.data6.splice(index, 1);
}
} }
} }
</script> </script>