update Table
update Table
This commit is contained in:
parent
b2012015da
commit
486d4fda19
9 changed files with 132 additions and 106 deletions
|
@ -2,15 +2,17 @@
|
|||
<div :class="classes">
|
||||
<template v-if="renderType === 'index'">{{naturalIndex + 1}}</template>
|
||||
<template v-if="renderType === 'selection'">
|
||||
<Checkbox :checked="checked" @on-change="toggleSelect" :disabled="disabled"></Checkbox>
|
||||
<Checkbox :value="checked" @on-change="toggleSelect" :disabled="disabled"></Checkbox>
|
||||
</template>
|
||||
<template v-if="renderType === 'normal'">{{{ row[column.key] }}}</template>
|
||||
<template v-if="renderType === 'normal'"><span v-html="row[column.key]"></span></template>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import Vue from 'vue';
|
||||
import Checkbox from '../checkbox/checkbox.vue';
|
||||
|
||||
export default {
|
||||
name: 'TableCell',
|
||||
components: { Checkbox },
|
||||
props: {
|
||||
prefixCls: String,
|
||||
|
@ -29,7 +31,7 @@
|
|||
return {
|
||||
renderType: '',
|
||||
uid: -1,
|
||||
content: this.$parent.$parent.content
|
||||
content: this.$parent.$parent.currentContent
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -51,14 +53,34 @@
|
|||
const cell = document.createElement('div');
|
||||
cell.innerHTML = template;
|
||||
const _oldParentChildLen = $parent.$children.length;
|
||||
$parent.$compile(cell); // todo 这里无法触发 ready 钩子
|
||||
// $parent.$compile(cell); // todo 这里无法触发 ready 钩子
|
||||
const _newParentChildLen = $parent.$children.length;
|
||||
|
||||
if (_oldParentChildLen !== _newParentChildLen) { // if render normal html node, do not tag
|
||||
this.uid = $parent.$children[$parent.$children.length - 1]._uid; // tag it, and delete when data or columns update
|
||||
}
|
||||
this.$el.innerHTML = '';
|
||||
this.$el.appendChild(cell);
|
||||
// this.$el.appendChild(cell);
|
||||
let methods = {};
|
||||
let $_parent = this.$parent;
|
||||
while($_parent != null && $_parent._name != '<Table>'){
|
||||
$_parent = $_parent.$parent;
|
||||
}
|
||||
if ($_parent) {
|
||||
Object.keys($_parent).forEach(key => {
|
||||
const func = this.$parent.$parent.$parent[`${key}`];
|
||||
if(typeof(func) === 'function' &&func.name === 'boundFn'){
|
||||
methods[`${key}`] = func;
|
||||
}
|
||||
});
|
||||
}
|
||||
const res = Vue.compile(cell.outerHTML);
|
||||
const compt = new Vue({
|
||||
render: res.render,
|
||||
staticRenderFns: res.staticRenderFns,
|
||||
methods: methods
|
||||
});
|
||||
compt.$mount(this.$el);
|
||||
}
|
||||
},
|
||||
destroy () {
|
||||
|
@ -73,7 +95,7 @@
|
|||
this.$parent.$parent.toggleSelect(this.index);
|
||||
}
|
||||
},
|
||||
compiled () {
|
||||
created () {
|
||||
if (this.column.type === 'index') {
|
||||
this.renderType = 'index';
|
||||
} else if (this.column.type === 'selection') {
|
||||
|
@ -84,8 +106,10 @@
|
|||
this.renderType = 'normal';
|
||||
}
|
||||
},
|
||||
ready () {
|
||||
this.compile();
|
||||
mounted () {
|
||||
this.$nextTick(() => {
|
||||
this.compile();
|
||||
});
|
||||
},
|
||||
beforeDestroy () {
|
||||
this.destroy();
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<template>
|
||||
<table cellspacing="0" cellpadding="0" border="0" :style="style">
|
||||
<table cellspacing="0" cellpadding="0" border="0" :style="styleObject">
|
||||
<colgroup>
|
||||
<col v-for="column in columns" :width="setCellWidth(column, $index, false)">
|
||||
<col v-for="(column, index) in columns" :width="setCellWidth(column, index, false)">
|
||||
</colgroup>
|
||||
<tbody :class="[prefixCls + '-tbody']">
|
||||
<tr
|
||||
v-for="(index, row) in data"
|
||||
v-for="(row, index) in data"
|
||||
:class="rowClasses(row._index)"
|
||||
@mouseenter.stop="handleMouseIn(row._index)"
|
||||
@mouseleave.stop="handleMouseOut(row._index)"
|
||||
|
@ -32,11 +32,12 @@
|
|||
import Mixin from './mixin';
|
||||
|
||||
export default {
|
||||
name: 'TableBody',
|
||||
mixins: [ Mixin ],
|
||||
components: { Cell },
|
||||
props: {
|
||||
prefixCls: String,
|
||||
style: Object,
|
||||
styleObject: Object,
|
||||
columns: Array,
|
||||
data: Array, // rebuildData
|
||||
objData: Object,
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
<template>
|
||||
<table cellspacing="0" cellpadding="0" border="0" :style="styles">
|
||||
<colgroup>
|
||||
<col v-for="column in columns" :width="setCellWidth(column, $index, true)">
|
||||
<col v-for="(column, index) in columns" :width="setCellWidth(column, index, true)">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th v-for="(index, column) in columns" :class="alignCls(column)">
|
||||
<th v-for="(column, index) in columns" :class="alignCls(column)">
|
||||
<div :class="cellClasses(column)">
|
||||
<template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template>
|
||||
<template v-if="column.type === 'selection'"><Checkbox :value="isSelectAll" @on-change="selectAll"></Checkbox></template>
|
||||
<template v-else>
|
||||
{{{ renderHeader(column, $index) }}}
|
||||
<span v-html="renderHeader(column, index)"></span>
|
||||
<span :class="[prefixCls + '-sort']" v-if="column.sortable">
|
||||
<i class="ivu-icon ivu-icon-arrow-up-b" :class="{on: column._sortType === 'asc'}" @click="handleSort($index, 'asc')"></i>
|
||||
<i class="ivu-icon ivu-icon-arrow-down-b" :class="{on: column._sortType === 'desc'}" @click="handleSort($index, 'desc')"></i>
|
||||
<i class="ivu-icon ivu-icon-arrow-up-b" :class="{on: column._sortType === 'asc'}" @click="handleSort(index, 'asc')"></i>
|
||||
<i class="ivu-icon ivu-icon-arrow-down-b" :class="{on: column._sortType === 'desc'}" @click="handleSort(index, 'desc')"></i>
|
||||
</span>
|
||||
<Poptip
|
||||
v-if="isPopperShow(column)"
|
||||
:visible.sync="column._filterVisible"
|
||||
:visible="column._filterVisible"
|
||||
placement="bottom"
|
||||
@on-popper-hide="handleFilterHide($index)">
|
||||
@on-popper-hide="handleFilterHide(index)">
|
||||
<span :class="[prefixCls + '-filter']">
|
||||
<i class="ivu-icon ivu-icon-funnel" :class="{on: column._isFiltered}"></i>
|
||||
</span>
|
||||
<div slot="content" :class="[prefixCls + '-filter-list']" v-if="column._filterMultiple">
|
||||
<div :class="[prefixCls + '-filter-list-item']">
|
||||
<checkbox-group :model.sync="column._filterChecked">
|
||||
<checkbox-group v-model="column._filterChecked">
|
||||
<checkbox v-for="item in column.filters" :value="item.value">{{ item.label }}</checkbox>
|
||||
</checkbox-group>
|
||||
</div>
|
||||
<div :class="[prefixCls + '-filter-footer']">
|
||||
<i-button type="text" size="small" :disabled="!column._filterChecked.length" @click="handleFilter($index)">{{ t('i.table.confirmFilter') }}</i-button>
|
||||
<i-button type="text" size="small" @click="handleReset($index)">{{ t('i.table.resetFilter') }}</i-button>
|
||||
<i-button type="text" size="small" :disabled="!column._filterChecked.length" @click.native="handleFilter(index)">{{ t('i.table.confirmFilter') }}</i-button>
|
||||
<i-button type="text" size="small" @click.native="handleReset(index)">{{ t('i.table.resetFilter') }}</i-button>
|
||||
</div>
|
||||
</div>
|
||||
<div slot="content" :class="[prefixCls + '-filter-list']" v-else>
|
||||
<ul :class="[prefixCls + '-filter-list-single']">
|
||||
<li
|
||||
:class="itemAllClasses(column)"
|
||||
@click="handleReset($index)">{{ t('i.table.clearFilter') }}</li>
|
||||
@click="handleReset(index)">{{ t('i.table.clearFilter') }}</li>
|
||||
<li
|
||||
:class="itemClasses(column, item)"
|
||||
v-for="item in column.filters"
|
||||
|
@ -61,11 +61,12 @@
|
|||
import Locale from '../../mixins/locale';
|
||||
|
||||
export default {
|
||||
name: 'TableHead',
|
||||
mixins: [ Mixin, Locale ],
|
||||
components: { CheckboxGroup, Checkbox, Poptip, iButton },
|
||||
props: {
|
||||
prefixCls: String,
|
||||
style: Object,
|
||||
styleObject: Object,
|
||||
columns: Array,
|
||||
objData: Object,
|
||||
data: Array, // rebuildData
|
||||
|
@ -77,8 +78,8 @@
|
|||
},
|
||||
computed: {
|
||||
styles () {
|
||||
const style = Object.assign({}, this.style);
|
||||
const width = this.$parent.bodyHeight === 0 ? parseInt(this.style.width) : parseInt(this.style.width) + this.$parent.scrollBarWidth;
|
||||
const style = Object.assign({}, this.styleObject);
|
||||
const width = this.$parent.bodyHeight === 0 ? parseInt(this.styleObject.width) : parseInt(this.styleObject.width) + this.$parent.scrollBarWidth;
|
||||
style.width = `${width}px`;
|
||||
return style;
|
||||
},
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
<template>
|
||||
<div :class="wrapClasses" :style="styles">
|
||||
<div :class="classes">
|
||||
<div :class="[prefixCls + '-title']" v-if="showSlotHeader" v-el:title><slot name="header"></slot></div>
|
||||
<div :class="[prefixCls + '-header']" v-if="showHeader" v-el:header @mousewheel="handleMouseWheel">
|
||||
<div :class="[prefixCls + '-title']" v-if="showSlotHeader" ref="title"><slot name="header"></slot></div>
|
||||
<div :class="[prefixCls + '-header']" v-if="showHeader" ref="header" @mousewheel="handleMouseWheel">
|
||||
<table-head
|
||||
:prefix-cls="prefixCls"
|
||||
:style="tableStyle"
|
||||
:styleObject="tableStyle"
|
||||
:columns="cloneColumns"
|
||||
:obj-data="objData"
|
||||
:columns-width="columnsWidth"
|
||||
:data="rebuildData"></table-head>
|
||||
</div>
|
||||
<div :class="[prefixCls + '-body']" :style="bodyStyle" v-el:body @scroll="handleBodyScroll"
|
||||
<div :class="[prefixCls + '-body']" :style="bodyStyle" ref="body" @scroll="handleBodyScroll"
|
||||
v-show="!((!!noDataText && (!data || data.length === 0)) || (!!noFilteredDataText && (!rebuildData || rebuildData.length === 0)))">
|
||||
<table-body
|
||||
v-ref:tbody
|
||||
ref="tbody"
|
||||
:prefix-cls="prefixCls"
|
||||
:style="tableStyle"
|
||||
:styleObject="tableStyle"
|
||||
:columns="cloneColumns"
|
||||
:data="rebuildData"
|
||||
:columns-width="columnsWidth"
|
||||
|
@ -24,12 +24,13 @@
|
|||
</div>
|
||||
<div
|
||||
:class="[prefixCls + '-tip']"
|
||||
v-else>
|
||||
v-show="((!!noDataText && (!data || data.length === 0)) || (!!noFilteredDataText && (!rebuildData || rebuildData.length === 0)))">
|
||||
<table cellspacing="0" cellpadding="0" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td :style="{ 'height': bodyStyle.height }">
|
||||
{{{!data || data.length === 0 ? noDataText : noFilteredDataText}}}
|
||||
<span v-html="noDataText" v-if="!data || data.length === 0"></span>
|
||||
<span v-html="noFilteredDataText" v-else></span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -40,17 +41,17 @@
|
|||
<table-head
|
||||
fixed="left"
|
||||
:prefix-cls="prefixCls"
|
||||
:style="fixedTableStyle"
|
||||
:styleObject="fixedTableStyle"
|
||||
:columns="leftFixedColumns"
|
||||
:obj-data="objData"
|
||||
:columns-width.sync="columnsWidth"
|
||||
:data="rebuildData"></table-head>
|
||||
</div>
|
||||
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" v-el:fixed-body>
|
||||
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" ref="fixedBody">
|
||||
<table-body
|
||||
fixed="left"
|
||||
:prefix-cls="prefixCls"
|
||||
:style="fixedTableStyle"
|
||||
:styleObject="fixedTableStyle"
|
||||
:columns="leftFixedColumns"
|
||||
:data="rebuildData"
|
||||
:columns-width="columnsWidth"
|
||||
|
@ -62,24 +63,24 @@
|
|||
<table-head
|
||||
fixed="right"
|
||||
:prefix-cls="prefixCls"
|
||||
:style="fixedRightTableStyle"
|
||||
:styleObject="fixedRightTableStyle"
|
||||
:columns="rightFixedColumns"
|
||||
:obj-data="objData"
|
||||
:columns-width.sync="columnsWidth"
|
||||
:columns-width="columnsWidth"
|
||||
:data="rebuildData"></table-head>
|
||||
</div>
|
||||
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" v-el:fixed-right-body>
|
||||
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" ref="fixedRightBody">
|
||||
<table-body
|
||||
fixed="right"
|
||||
:prefix-cls="prefixCls"
|
||||
:style="fixedRightTableStyle"
|
||||
:styleObject="fixedRightTableStyle"
|
||||
:columns="rightFixedColumns"
|
||||
:data="rebuildData"
|
||||
:columns-width="columnsWidth"
|
||||
:obj-data="objData"></table-body>
|
||||
</div>
|
||||
</div>
|
||||
<div :class="[prefixCls + '-footer']" v-if="showSlotFooter" v-el:footer><slot name="footer"></slot></div>
|
||||
<div :class="[prefixCls + '-footer']" v-if="showSlotFooter" ref="footer"><slot name="footer"></slot></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -93,6 +94,7 @@
|
|||
const prefixCls = 'ivu-table';
|
||||
|
||||
export default {
|
||||
name: 'Table',
|
||||
components: { tableHead, tableBody },
|
||||
props: {
|
||||
data: {
|
||||
|
@ -170,7 +172,8 @@
|
|||
showSlotFooter: true,
|
||||
bodyHeight: 0,
|
||||
bodyRealHeight: 0,
|
||||
scrollBarWidth: getScrollBarSize()
|
||||
scrollBarWidth: getScrollBarSize(),
|
||||
currentContent: this.content
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -415,9 +418,9 @@
|
|||
fixedHeader () {
|
||||
if (this.height) {
|
||||
this.$nextTick(() => {
|
||||
const titleHeight = parseInt(getStyle(this.$els.title, 'height')) || 0;
|
||||
const headerHeight = parseInt(getStyle(this.$els.header, 'height')) || 0;
|
||||
const footerHeight = parseInt(getStyle(this.$els.footer, 'height')) || 0;
|
||||
const titleHeight = parseInt(getStyle(this.$refs.title, 'height')) || 0;
|
||||
const headerHeight = parseInt(getStyle(this.$refs.header, 'height')) || 0;
|
||||
const footerHeight = parseInt(getStyle(this.$refs.footer, 'height')) || 0;
|
||||
this.bodyHeight = this.height - titleHeight - headerHeight - footerHeight;
|
||||
});
|
||||
} else {
|
||||
|
@ -428,14 +431,14 @@
|
|||
this.cloneColumns.forEach((col) => col._filterVisible = false);
|
||||
},
|
||||
handleBodyScroll (event) {
|
||||
if (this.showHeader) this.$els.header.scrollLeft = event.target.scrollLeft;
|
||||
if (this.isLeftFixed) this.$els.fixedBody.scrollTop = event.target.scrollTop;
|
||||
if (this.isRightFixed) this.$els.fixedRightBody.scrollTop = event.target.scrollTop;
|
||||
if (this.showHeader) this.$refs.header.scrollLeft = event.target.scrollLeft;
|
||||
if (this.isLeftFixed) this.$refs.fixedBody.scrollTop = event.target.scrollTop;
|
||||
if (this.isRightFixed) this.$refs.fixedRightBody.scrollTop = event.target.scrollTop;
|
||||
this.hideColumnFilter();
|
||||
},
|
||||
handleMouseWheel (event) {
|
||||
const deltaX = event.deltaX;
|
||||
const $body = this.$els.body;
|
||||
const $body = this.$refs.body;
|
||||
|
||||
if (deltaX > 0) {
|
||||
$body.scrollLeft = $body.scrollLeft + 10;
|
||||
|
@ -639,13 +642,13 @@
|
|||
ExportCsv.download(params.filename, data);
|
||||
}
|
||||
},
|
||||
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, '') !== '';
|
||||
created () {
|
||||
if (!this.content) this.currentContent = this.$parent;
|
||||
this.showSlotHeader = this.$refs.title !== undefined;
|
||||
this.showSlotFooter = this.$refs.footer !== undefined;
|
||||
this.rebuildData = this.makeDataWithSortAndFilter();
|
||||
},
|
||||
ready () {
|
||||
mounted () {
|
||||
this.handleResize();
|
||||
this.fixedHeader();
|
||||
this.$nextTick(() => this.ready = true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue