update Table
update Table
This commit is contained in:
parent
e7e8c8ffb3
commit
abdec99d22
3 changed files with 59 additions and 15 deletions
|
@ -4,26 +4,28 @@
|
||||||
<div :class="[prefixCls + '-header']" v-if="showHeader" v-el:header>
|
<div :class="[prefixCls + '-header']" v-if="showHeader" v-el:header>
|
||||||
<table cellspacing="0" cellpadding="0" border="0" :style="tableStyle">
|
<table cellspacing="0" cellpadding="0" border="0" :style="tableStyle">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col v-for="column in columns" :width="setCellWidth(column, $index)">
|
<col v-for="column in cloneColumns" :width="setCellWidth(column, $index)">
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<thead
|
<thead
|
||||||
is="table-head"
|
is="table-head"
|
||||||
:prefix-cls="prefixCls"
|
:prefix-cls="prefixCls"
|
||||||
:clone-data.sync="cloneData"
|
:clone-data.sync="cloneData"
|
||||||
:columns="columns"></thead>
|
:columns="cloneColumns"></thead>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div :class="[prefixCls + '-body']" :style="bodyStyle">
|
<div :class="[prefixCls + '-body']" :style="bodyStyle">
|
||||||
<table cellspacing="0" cellpadding="0" border="0" :style="tableStyle" v-el:tbody>
|
<table cellspacing="0" cellpadding="0" border="0" :style="tableStyle" v-el:tbody>
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col v-for="column in columns" :width="setCellWidth(column, $index)">
|
<col v-for="column in cloneColumns" :width="setCellWidth(column, $index)">
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<tbody :class="[prefixCls + '-tbody']" v-el:render>
|
<tbody :class="[prefixCls + '-tbody']" v-el:render>
|
||||||
<tr
|
<tr
|
||||||
v-for="(index, row) in data"
|
v-for="(index, row) in data"
|
||||||
:class="[prefixCls + '-row', rowClsName(index), {[prefixCls + '-row-highlight']: cloneData[index] && cloneData[index]._isHighlight}]"
|
:class="[prefixCls + '-row', rowClsName(index), {[prefixCls + '-row-highlight']: cloneData[index] && cloneData[index]._isHighlight, [prefixCls + '-row-hover']: cloneData[index] && cloneData[index]._isHover}]"
|
||||||
|
@mouseenter.stop="handleMouseIn(index)"
|
||||||
|
@mouseleave.stop="handleMouseOut(index)"
|
||||||
@click.stop="highlightCurrentRow(index)">
|
@click.stop="highlightCurrentRow(index)">
|
||||||
<td v-for="column in columns" :class="alignCls(column)">
|
<td v-for="column in cloneColumns" :class="alignCls(column)">
|
||||||
<div :class="[prefixCls + '-cell']">
|
<div :class="[prefixCls + '-cell']">
|
||||||
<template v-if="column.type === 'selection'">
|
<template v-if="column.type === 'selection'">
|
||||||
<Checkbox :checked="cloneData[index] && cloneData[index]._isChecked" @on-change="toggleSelect(index)"></Checkbox>
|
<Checkbox :checked="cloneData[index] && cloneData[index]._isChecked" @on-change="toggleSelect(index)"></Checkbox>
|
||||||
|
@ -34,6 +36,12 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
|
<div :class="[prefixCls + '-fixed']">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div :class="[prefixCls + '-fixed-right']">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div :class="[prefixCls + '-footer']" v-if="showSlotFooter" v-el:footer><slot name="footer"></slot></div>
|
<div :class="[prefixCls + '-footer']" v-if="showSlotFooter" v-el:footer><slot name="footer"></slot></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -99,6 +107,7 @@
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
compiledUids: [],
|
compiledUids: [],
|
||||||
cloneData: deepCopy(this.data),
|
cloneData: deepCopy(this.data),
|
||||||
|
cloneColumns: deepCopy(this.columns),
|
||||||
showSlotHeader: true,
|
showSlotHeader: true,
|
||||||
showSlotFooter: true,
|
showSlotFooter: true,
|
||||||
bodyHeight: 0
|
bodyHeight: 0
|
||||||
|
@ -155,8 +164,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const $el = this.$els.render;
|
const $el = this.$els.render;
|
||||||
for (let i = 0; i < this.columns.length; i++) {
|
for (let i = 0; i < this.cloneColumns.length; i++) {
|
||||||
const column = this.columns[i];
|
const column = this.cloneColumns[i];
|
||||||
if (column.render) {
|
if (column.render) {
|
||||||
for (let j = 0; j < this.data.length; j++) {
|
for (let j = 0; j < this.data.length; j++) {
|
||||||
// todo 做一个缓存,只在需要改render时再重新编译,data改变时不用再编译
|
// todo 做一个缓存,只在需要改render时再重新编译,data改变时不用再编译
|
||||||
|
@ -191,6 +200,22 @@
|
||||||
setCellWidth (column, index) {
|
setCellWidth (column, index) {
|
||||||
return column.width ? column.width : this.columnsWidth[index];
|
return column.width ? column.width : this.columnsWidth[index];
|
||||||
},
|
},
|
||||||
|
assignRow (index, obj) {
|
||||||
|
return Object.assign({}, this.cloneData[index], obj);
|
||||||
|
},
|
||||||
|
handleMouseIn (index) {
|
||||||
|
if (this.cloneData[index]._isHover) return;
|
||||||
|
const row = this.assignRow(index, {
|
||||||
|
_isHover: true
|
||||||
|
});
|
||||||
|
this.cloneData.$set(index, row);
|
||||||
|
},
|
||||||
|
handleMouseOut (index) {
|
||||||
|
const row = this.assignRow(index, {
|
||||||
|
_isHover: false
|
||||||
|
});
|
||||||
|
this.cloneData.$set(index, row);
|
||||||
|
},
|
||||||
highlightCurrentRow (index) {
|
highlightCurrentRow (index) {
|
||||||
if (!this.highlightRow || this.cloneData[index]._isHighlight) return;
|
if (!this.highlightRow || this.cloneData[index]._isHighlight) return;
|
||||||
|
|
||||||
|
@ -202,7 +227,7 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const row = Object.assign({}, this.cloneData[index], {
|
const row = this.assignRow(index, {
|
||||||
_isHighlight: true
|
_isHighlight: true
|
||||||
});
|
});
|
||||||
this.cloneData.$set(index, row);
|
this.cloneData.$set(index, row);
|
||||||
|
@ -220,7 +245,7 @@
|
||||||
},
|
},
|
||||||
toggleSelect (index) {
|
toggleSelect (index) {
|
||||||
const status = !this.cloneData[index]._isChecked;
|
const status = !this.cloneData[index]._isChecked;
|
||||||
const row = Object.assign({}, this.cloneData[index], {
|
const row = this.assignRow(index, {
|
||||||
_isChecked: status
|
_isChecked: status
|
||||||
});
|
});
|
||||||
this.cloneData.$set(index, row);
|
this.cloneData.$set(index, row);
|
||||||
|
@ -243,9 +268,25 @@
|
||||||
this.bodyHeight = this.height - titleHeight - headerHeight - footerHeight;
|
this.bodyHeight = this.height - titleHeight - headerHeight - footerHeight;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
parseColumns () {
|
||||||
|
let left = [];
|
||||||
|
let right = [];
|
||||||
|
let center = [];
|
||||||
|
this.cloneColumns.forEach((col) => {
|
||||||
|
if (col.fixed && col.fixed === 'left') {
|
||||||
|
left.push(col);
|
||||||
|
} else if (col.fixed && col.fixed === 'right') {
|
||||||
|
right.push(col);
|
||||||
|
} else {
|
||||||
|
center.push(col);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.cloneColumns = left.concat(center).concat(right);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
compiled () {
|
compiled () {
|
||||||
|
this.parseColumns();
|
||||||
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, '') !== '';
|
||||||
},
|
},
|
||||||
|
@ -267,6 +308,7 @@
|
||||||
},
|
},
|
||||||
columns: {
|
columns: {
|
||||||
handler () {
|
handler () {
|
||||||
|
this.parseColumns();
|
||||||
this.compileRender(true);
|
this.compileRender(true);
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
|
|
|
@ -122,7 +122,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tr:hover{
|
tr&-row-hover{
|
||||||
td{
|
td{
|
||||||
background-color: @table-td-hover-bg;
|
background-color: @table-td-hover-bg;
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
&-row-highlight,
|
&-row-highlight,
|
||||||
tr&-row-highlight:hover,
|
tr&-row-highlight&-row-hover,
|
||||||
&-stripe &-body tr&-row-highlight:nth-child(2n)
|
&-stripe &-body tr&-row-highlight:nth-child(2n)
|
||||||
{
|
{
|
||||||
td{
|
td{
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
<br>
|
<br>
|
||||||
<i-table
|
<i-table
|
||||||
border
|
border
|
||||||
:height="height"
|
|
||||||
highlight-row
|
highlight-row
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:data="data"
|
:data="data"
|
||||||
|
@ -41,13 +40,15 @@
|
||||||
title: '姓名',
|
title: '姓名',
|
||||||
key: 'name',
|
key: 'name',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
// width: 100
|
fixed: 'left',
|
||||||
|
width: 100
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '年龄',
|
title: '年龄',
|
||||||
key: 'age',
|
key: 'age',
|
||||||
align: 'right',
|
align: 'right',
|
||||||
// width: 100
|
fixed: 'left',
|
||||||
|
width: 100
|
||||||
// render (row) {
|
// render (row) {
|
||||||
// return `<i-button>${row.age}</i-button>`
|
// return `<i-button>${row.age}</i-button>`
|
||||||
// }
|
// }
|
||||||
|
@ -68,7 +69,8 @@
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
// width: 200,
|
fixed: 'right',
|
||||||
|
width: 200,
|
||||||
render (row, column, index) {
|
render (row, column, index) {
|
||||||
return `<i-button @click="edit(${index})">编辑</i-button>`
|
return `<i-button @click="edit(${index})">编辑</i-button>`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue