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

View file

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

View file

@ -122,6 +122,9 @@
default () {
return '';
}
},
content: {
type: Object
}
},
data () {
@ -243,23 +246,25 @@
let autoWidthIndex = -1;
if (allWidth) autoWidthIndex = this.cloneColumns.findIndex(cell => !cell.width);//todo
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
const column = this.cloneColumns[i];
if (this.data.length) {
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
const column = this.cloneColumns[i];
let width = parseInt(getStyle($td[i], 'width'));
if (i === autoWidthIndex) {
width = parseInt(getStyle($td[i], 'width')) - 1;
}
if (column.width) width = column.width;
this.cloneColumns[i]._width = width;
columnsWidth[column._index] = {
width: width
let width = parseInt(getStyle($td[i], 'width'));
if (i === autoWidthIndex) {
width = parseInt(getStyle($td[i], 'width')) - 1;
}
if (column.width) width = column.width;
this.cloneColumns[i]._width = width;
columnsWidth[column._index] = {
width: width
}
}
this.columnsWidth = columnsWidth;
}
this.columnsWidth = columnsWidth;
});
});
},
@ -502,6 +507,7 @@
}
},
compiled () {
if (!this.content) this.content = this.$parent;
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.rebuildData = this.makeDataWithSortAndFilter();