2016-11-23 16:27:17 +08:00
|
|
|
<template>
|
2016-11-29 13:25:25 +08:00
|
|
|
<div :class="wrapClasses" :style="styles">
|
2016-11-29 18:42:34 +08:00
|
|
|
<div :class="classes">
|
2017-03-09 14:11:22 +08:00
|
|
|
<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">
|
2016-11-27 20:43:54 +08:00
|
|
|
<table-head
|
2016-11-29 18:42:34 +08:00
|
|
|
:prefix-cls="prefixCls"
|
2017-03-09 14:11:22 +08:00
|
|
|
:styleObject="tableStyle"
|
2016-11-29 18:42:34 +08:00
|
|
|
:columns="cloneColumns"
|
|
|
|
:obj-data="objData"
|
2016-11-30 16:12:10 +08:00
|
|
|
:columns-width="columnsWidth"
|
2016-11-29 18:42:34 +08:00
|
|
|
:data="rebuildData"></table-head>
|
2016-11-27 20:43:54 +08:00
|
|
|
</div>
|
2017-03-09 14:11:22 +08:00
|
|
|
<div :class="[prefixCls + '-body']" :style="bodyStyle" ref="body" @scroll="handleBodyScroll"
|
2017-03-30 16:05:20 +08:00
|
|
|
v-show="!((!!localeNoDataText && (!data || data.length === 0)) || (!!localeNoFilteredDataText && (!rebuildData || rebuildData.length === 0)))">
|
2016-11-27 20:43:54 +08:00
|
|
|
<table-body
|
2017-03-09 14:11:22 +08:00
|
|
|
ref="tbody"
|
2016-11-29 18:42:34 +08:00
|
|
|
:prefix-cls="prefixCls"
|
2017-03-09 14:11:22 +08:00
|
|
|
:styleObject="tableStyle"
|
2016-11-29 18:42:34 +08:00
|
|
|
:columns="cloneColumns"
|
|
|
|
:data="rebuildData"
|
2016-11-30 16:12:10 +08:00
|
|
|
:columns-width="columnsWidth"
|
2016-11-29 18:42:34 +08:00
|
|
|
:obj-data="objData"></table-body>
|
2016-11-27 20:43:54 +08:00
|
|
|
</div>
|
2017-01-13 01:53:34 -06:00
|
|
|
<div
|
|
|
|
:class="[prefixCls + '-tip']"
|
2017-03-30 16:05:20 +08:00
|
|
|
v-show="((!!localeNoDataText && (!data || data.length === 0)) || (!!localeNoFilteredDataText && (!rebuildData || rebuildData.length === 0)))">
|
2017-01-13 01:53:34 -06:00
|
|
|
<table cellspacing="0" cellpadding="0" border="0">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td :style="{ 'height': bodyStyle.height }">
|
2017-03-30 16:05:20 +08:00
|
|
|
<span v-html="localeNoDataText" v-if="!data || data.length === 0"></span>
|
|
|
|
<span v-html="localeNoFilteredDataText" v-else></span>
|
2017-01-13 01:53:34 -06:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2016-12-01 11:14:26 +08:00
|
|
|
<div :class="[prefixCls + '-fixed']" :style="fixedTableStyle" v-if="isLeftFixed">
|
2017-07-19 13:58:20 +08:00
|
|
|
<div :class="fixedHeaderClasses" v-if="showHeader">
|
2016-11-29 13:25:25 +08:00
|
|
|
<table-head
|
2016-11-30 13:17:55 +08:00
|
|
|
fixed="left"
|
2016-11-29 18:42:34 +08:00
|
|
|
:prefix-cls="prefixCls"
|
2017-03-09 14:11:22 +08:00
|
|
|
:styleObject="fixedTableStyle"
|
2016-11-29 18:42:34 +08:00
|
|
|
:columns="leftFixedColumns"
|
|
|
|
:obj-data="objData"
|
2017-07-14 14:52:54 +08:00
|
|
|
:columns-width="columnsWidth"
|
2016-11-29 18:42:34 +08:00
|
|
|
:data="rebuildData"></table-head>
|
2016-11-29 13:25:25 +08:00
|
|
|
</div>
|
2017-03-09 14:11:22 +08:00
|
|
|
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" ref="fixedBody">
|
2016-11-29 13:25:25 +08:00
|
|
|
<table-body
|
2016-11-30 13:17:55 +08:00
|
|
|
fixed="left"
|
2016-11-29 18:42:34 +08:00
|
|
|
:prefix-cls="prefixCls"
|
2017-03-09 14:11:22 +08:00
|
|
|
:styleObject="fixedTableStyle"
|
2016-11-29 18:42:34 +08:00
|
|
|
:columns="leftFixedColumns"
|
|
|
|
:data="rebuildData"
|
2016-11-30 16:12:10 +08:00
|
|
|
:columns-width="columnsWidth"
|
2016-11-29 18:42:34 +08:00
|
|
|
:obj-data="objData"></table-body>
|
2016-11-29 13:25:25 +08:00
|
|
|
</div>
|
2016-11-27 20:43:54 +08:00
|
|
|
</div>
|
2016-12-01 11:14:26 +08:00
|
|
|
<div :class="[prefixCls + '-fixed-right']" :style="fixedRightTableStyle" v-if="isRightFixed">
|
2017-07-19 13:58:20 +08:00
|
|
|
<div :class="fixedHeaderClasses" v-if="showHeader">
|
2016-11-29 13:25:25 +08:00
|
|
|
<table-head
|
2016-11-30 13:17:55 +08:00
|
|
|
fixed="right"
|
2016-11-29 18:42:34 +08:00
|
|
|
:prefix-cls="prefixCls"
|
2017-03-09 14:11:22 +08:00
|
|
|
:styleObject="fixedRightTableStyle"
|
2016-11-29 18:42:34 +08:00
|
|
|
:columns="rightFixedColumns"
|
|
|
|
:obj-data="objData"
|
2017-03-09 14:11:22 +08:00
|
|
|
:columns-width="columnsWidth"
|
2016-11-29 18:42:34 +08:00
|
|
|
:data="rebuildData"></table-head>
|
2016-11-29 13:25:25 +08:00
|
|
|
</div>
|
2017-03-09 14:11:22 +08:00
|
|
|
<div :class="[prefixCls + '-fixed-body']" :style="fixedBodyStyle" ref="fixedRightBody">
|
2016-11-29 13:25:25 +08:00
|
|
|
<table-body
|
2016-11-30 13:17:55 +08:00
|
|
|
fixed="right"
|
2016-11-29 18:42:34 +08:00
|
|
|
:prefix-cls="prefixCls"
|
2017-03-09 14:11:22 +08:00
|
|
|
:styleObject="fixedRightTableStyle"
|
2016-11-29 18:42:34 +08:00
|
|
|
:columns="rightFixedColumns"
|
|
|
|
:data="rebuildData"
|
2016-11-30 16:12:10 +08:00
|
|
|
:columns-width="columnsWidth"
|
2016-11-29 18:42:34 +08:00
|
|
|
:obj-data="objData"></table-body>
|
2016-11-29 13:25:25 +08:00
|
|
|
</div>
|
2016-11-27 20:43:54 +08:00
|
|
|
</div>
|
2017-03-09 14:11:22 +08:00
|
|
|
<div :class="[prefixCls + '-footer']" v-if="showSlotFooter" ref="footer"><slot name="footer"></slot></div>
|
2016-11-23 16:27:17 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2016-11-26 08:57:09 +08:00
|
|
|
import tableHead from './table-head.vue';
|
|
|
|
import tableBody from './table-body.vue';
|
2017-01-05 13:15:26 +08:00
|
|
|
import { oneOf, getStyle, deepCopy, getScrollBarSize } from '../../utils/assist';
|
2017-07-10 13:49:26 +08:00
|
|
|
import { on, off } from '../../utils/dom';
|
2016-12-09 13:24:39 +08:00
|
|
|
import Csv from '../../utils/csv';
|
|
|
|
import ExportCsv from './export-csv';
|
2017-03-30 16:05:20 +08:00
|
|
|
import Locale from '../../mixins/locale';
|
|
|
|
|
2016-11-23 16:27:17 +08:00
|
|
|
const prefixCls = 'ivu-table';
|
|
|
|
|
2017-07-14 14:52:54 +08:00
|
|
|
let rowKey = 1;
|
|
|
|
let columnKey = 1;
|
|
|
|
|
2016-11-23 16:27:17 +08:00
|
|
|
export default {
|
2017-03-09 14:11:22 +08:00
|
|
|
name: 'Table',
|
2017-03-30 16:05:20 +08:00
|
|
|
mixins: [ Locale ],
|
2016-11-26 08:57:09 +08:00
|
|
|
components: { tableHead, tableBody },
|
2016-11-23 16:27:17 +08:00
|
|
|
props: {
|
|
|
|
data: {
|
|
|
|
type: Array,
|
|
|
|
default () {
|
2016-12-25 22:49:42 +08:00
|
|
|
return [];
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
columns: {
|
|
|
|
type: Array,
|
|
|
|
default () {
|
2016-12-25 22:49:42 +08:00
|
|
|
return [];
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
validator (value) {
|
2016-12-02 11:23:46 +08:00
|
|
|
return oneOf(value, ['small', 'large', 'default']);
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
|
|
|
},
|
2016-11-25 22:51:50 +08:00
|
|
|
width: {
|
|
|
|
type: [Number, String]
|
|
|
|
},
|
2016-11-24 17:32:43 +08:00
|
|
|
height: {
|
|
|
|
type: [Number, String]
|
|
|
|
},
|
2016-11-23 16:27:17 +08:00
|
|
|
stripe: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
border: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
showHeader: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
2016-11-24 15:27:46 +08:00
|
|
|
highlightRow: {
|
2016-11-23 16:27:17 +08:00
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2016-11-24 17:32:43 +08:00
|
|
|
},
|
|
|
|
rowClassName: {
|
|
|
|
type: Function,
|
|
|
|
default () {
|
|
|
|
return '';
|
|
|
|
}
|
2016-12-01 11:02:06 +08:00
|
|
|
},
|
2017-03-17 09:50:11 +08:00
|
|
|
context: {
|
2016-12-01 11:02:06 +08:00
|
|
|
type: Object
|
2017-01-04 16:42:27 -06:00
|
|
|
},
|
|
|
|
noDataText: {
|
2017-03-30 16:05:20 +08:00
|
|
|
type: String
|
2017-01-04 16:42:27 -06:00
|
|
|
},
|
|
|
|
noFilteredDataText: {
|
2017-03-30 16:05:20 +08:00
|
|
|
type: String
|
2017-06-07 14:19:31 +08:00
|
|
|
},
|
2017-06-09 17:06:20 +08:00
|
|
|
disabledHover: {
|
2017-06-07 14:19:31 +08:00
|
|
|
type: Boolean
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
2016-11-29 11:04:48 +08:00
|
|
|
ready: false,
|
2016-11-23 18:38:39 +08:00
|
|
|
tableWidth: 0,
|
2016-11-30 16:12:10 +08:00
|
|
|
columnsWidth: {},
|
2016-11-23 16:27:17 +08:00
|
|
|
prefixCls: prefixCls,
|
2016-11-24 15:27:46 +08:00
|
|
|
compiledUids: [],
|
2016-11-28 16:53:19 +08:00
|
|
|
objData: this.makeObjData(), // checkbox or highlight-row
|
2016-11-30 13:17:55 +08:00
|
|
|
rebuildData: [], // for sort or filter
|
2016-11-28 16:53:19 +08:00
|
|
|
cloneColumns: this.makeColumns(),
|
2016-11-24 17:32:43 +08:00
|
|
|
showSlotHeader: true,
|
|
|
|
showSlotFooter: true,
|
2017-01-05 13:15:26 +08:00
|
|
|
bodyHeight: 0,
|
2017-01-13 20:18:21 +08:00
|
|
|
bodyRealHeight: 0,
|
2017-03-09 14:11:22 +08:00
|
|
|
scrollBarWidth: getScrollBarSize(),
|
2017-03-17 09:50:11 +08:00
|
|
|
currentContext: this.context,
|
2017-03-15 15:50:28 +08:00
|
|
|
cloneData: deepCopy(this.data) // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data
|
2016-12-25 22:49:42 +08:00
|
|
|
};
|
2016-11-23 16:27:17 +08:00
|
|
|
},
|
|
|
|
computed: {
|
2017-03-30 16:05:20 +08:00
|
|
|
localeNoDataText () {
|
|
|
|
if (this.noDataText === undefined) {
|
|
|
|
return this.t('i.table.noDataText');
|
|
|
|
} else {
|
|
|
|
return this.noDataText;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
localeNoFilteredDataText () {
|
|
|
|
if (this.noFilteredDataText === undefined) {
|
|
|
|
return this.t('i.table.noFilteredDataText');
|
|
|
|
} else {
|
|
|
|
return this.noFilteredDataText;
|
|
|
|
}
|
|
|
|
},
|
2016-11-29 13:25:25 +08:00
|
|
|
wrapClasses () {
|
|
|
|
return [
|
|
|
|
`${prefixCls}-wrapper`,
|
|
|
|
{
|
2016-12-02 15:15:54 +08:00
|
|
|
[`${prefixCls}-hide`]: !this.ready,
|
|
|
|
[`${prefixCls}-with-header`]: this.showSlotHeader,
|
|
|
|
[`${prefixCls}-with-footer`]: this.showSlotFooter
|
2016-11-29 13:25:25 +08:00
|
|
|
}
|
2016-12-25 22:49:42 +08:00
|
|
|
];
|
2016-11-29 13:25:25 +08:00
|
|
|
},
|
2016-11-23 16:27:17 +08:00
|
|
|
classes () {
|
|
|
|
return [
|
|
|
|
`${prefixCls}`,
|
|
|
|
{
|
2016-11-24 15:27:46 +08:00
|
|
|
[`${prefixCls}-${this.size}`]: !!this.size,
|
|
|
|
[`${prefixCls}-border`]: this.border,
|
2016-11-24 17:32:43 +08:00
|
|
|
[`${prefixCls}-stripe`]: this.stripe,
|
|
|
|
[`${prefixCls}-with-fixed-top`]: !!this.height
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
2016-12-25 22:49:42 +08:00
|
|
|
];
|
2016-11-24 15:27:46 +08:00
|
|
|
},
|
2017-07-19 13:58:20 +08:00
|
|
|
fixedHeaderClasses () {
|
|
|
|
return [
|
|
|
|
`${prefixCls}-fixed-header`,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-fixed-header-with-empty`]: !this.rebuildData.length
|
|
|
|
}
|
|
|
|
];
|
|
|
|
},
|
2016-11-24 17:32:43 +08:00
|
|
|
styles () {
|
|
|
|
let style = {};
|
2017-01-05 13:15:26 +08:00
|
|
|
if (this.height) {
|
|
|
|
const height = (this.isLeftFixed || this.isRightFixed) ? parseInt(this.height) + this.scrollBarWidth : parseInt(this.height);
|
|
|
|
style.height = `${height}px`;
|
|
|
|
}
|
2016-12-25 22:49:42 +08:00
|
|
|
if (this.width) style.width = `${this.width}px`;
|
2016-11-24 17:32:43 +08:00
|
|
|
return style;
|
|
|
|
},
|
2016-11-24 15:27:46 +08:00
|
|
|
tableStyle () {
|
|
|
|
let style = {};
|
2017-01-05 13:15:26 +08:00
|
|
|
if (this.tableWidth !== 0) {
|
2017-01-13 20:18:21 +08:00
|
|
|
let width = '';
|
|
|
|
if (this.bodyHeight === 0) {
|
|
|
|
width = this.tableWidth;
|
|
|
|
} else {
|
|
|
|
if (this.bodyHeight > this.bodyRealHeight) {
|
|
|
|
width = this.tableWidth;
|
|
|
|
} else {
|
|
|
|
width = this.tableWidth - this.scrollBarWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// const width = this.bodyHeight === 0 ? this.tableWidth : this.tableWidth - this.scrollBarWidth;
|
2017-01-05 13:15:26 +08:00
|
|
|
style.width = `${width}px`;
|
|
|
|
}
|
2016-11-24 15:27:46 +08:00
|
|
|
return style;
|
2016-11-24 17:32:43 +08:00
|
|
|
},
|
2016-11-26 08:57:09 +08:00
|
|
|
fixedTableStyle () {
|
|
|
|
let style = {};
|
2016-11-30 13:17:55 +08:00
|
|
|
let width = 0;
|
|
|
|
this.leftFixedColumns.forEach((col) => {
|
2016-11-30 16:12:10 +08:00
|
|
|
if (col.fixed && col.fixed === 'left') width += col._width;
|
2016-11-30 13:17:55 +08:00
|
|
|
});
|
|
|
|
style.width = `${width}px`;
|
2016-11-26 08:57:09 +08:00
|
|
|
return style;
|
|
|
|
},
|
|
|
|
fixedRightTableStyle () {
|
|
|
|
let style = {};
|
2016-11-30 13:17:55 +08:00
|
|
|
let width = 0;
|
|
|
|
this.rightFixedColumns.forEach((col) => {
|
2016-11-30 16:12:10 +08:00
|
|
|
if (col.fixed && col.fixed === 'right') width += col._width;
|
2016-11-30 13:17:55 +08:00
|
|
|
});
|
2017-01-05 13:15:26 +08:00
|
|
|
width += this.scrollBarWidth;
|
2016-11-30 13:17:55 +08:00
|
|
|
style.width = `${width}px`;
|
2016-11-26 08:57:09 +08:00
|
|
|
return style;
|
|
|
|
},
|
2016-11-24 17:32:43 +08:00
|
|
|
bodyStyle () {
|
|
|
|
let style = {};
|
2017-01-05 13:15:26 +08:00
|
|
|
if (this.bodyHeight !== 0) {
|
|
|
|
// add a height to resolve scroll bug when browser has a scrollBar in fixed type and height prop
|
|
|
|
const height = (this.isLeftFixed || this.isRightFixed) ? this.bodyHeight + this.scrollBarWidth : this.bodyHeight;
|
|
|
|
style.height = `${height}px`;
|
|
|
|
}
|
2016-11-24 17:32:43 +08:00
|
|
|
return style;
|
2016-11-27 20:43:54 +08:00
|
|
|
},
|
|
|
|
fixedBodyStyle () {
|
|
|
|
let style = {};
|
2017-01-05 13:15:26 +08:00
|
|
|
if (this.bodyHeight !== 0) {
|
2017-01-13 20:18:21 +08:00
|
|
|
let height = this.bodyHeight + this.scrollBarWidth - 1;
|
|
|
|
|
|
|
|
if (this.width && this.width < this.tableWidth){
|
|
|
|
height = this.bodyHeight;
|
|
|
|
}
|
|
|
|
// style.height = this.scrollBarWidth > 0 ? `${this.bodyHeight}px` : `${this.bodyHeight - 1}px`;
|
|
|
|
style.height = this.scrollBarWidth > 0 ? `${height}px` : `${height - 1}px`;
|
2017-01-05 13:15:26 +08:00
|
|
|
}
|
2016-11-27 20:43:54 +08:00
|
|
|
return style;
|
2016-11-28 16:53:19 +08:00
|
|
|
},
|
|
|
|
leftFixedColumns () {
|
|
|
|
let left = [];
|
2016-11-30 13:17:55 +08:00
|
|
|
let other = [];
|
2016-11-28 16:53:19 +08:00
|
|
|
this.cloneColumns.forEach((col) => {
|
|
|
|
if (col.fixed && col.fixed === 'left') {
|
|
|
|
left.push(col);
|
2016-11-30 13:17:55 +08:00
|
|
|
} else {
|
|
|
|
other.push(col);
|
2016-11-28 16:53:19 +08:00
|
|
|
}
|
|
|
|
});
|
2016-11-30 13:17:55 +08:00
|
|
|
return left.concat(other);
|
2016-11-28 16:53:19 +08:00
|
|
|
},
|
|
|
|
rightFixedColumns () {
|
|
|
|
let right = [];
|
2016-11-30 13:17:55 +08:00
|
|
|
let other = [];
|
2016-11-28 16:53:19 +08:00
|
|
|
this.cloneColumns.forEach((col) => {
|
|
|
|
if (col.fixed && col.fixed === 'right') {
|
|
|
|
right.push(col);
|
2016-11-30 13:17:55 +08:00
|
|
|
} else {
|
|
|
|
other.push(col);
|
2016-11-28 16:53:19 +08:00
|
|
|
}
|
|
|
|
});
|
2016-11-30 13:17:55 +08:00
|
|
|
return right.concat(other);
|
2016-12-01 11:14:26 +08:00
|
|
|
},
|
|
|
|
isLeftFixed () {
|
|
|
|
return this.columns.some(col => col.fixed && col.fixed === 'left');
|
|
|
|
},
|
|
|
|
isRightFixed () {
|
|
|
|
return this.columns.some(col => col.fixed && col.fixed === 'right');
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2016-11-24 17:32:43 +08:00
|
|
|
rowClsName (index) {
|
|
|
|
return this.rowClassName(this.data[index], index);
|
|
|
|
},
|
2016-11-25 15:47:28 +08:00
|
|
|
handleResize () {
|
2016-11-23 16:27:17 +08:00
|
|
|
this.$nextTick(() => {
|
2016-11-30 16:12:10 +08:00
|
|
|
const allWidth = !this.columns.some(cell => !cell.width); // each column set a width
|
2016-11-25 15:47:28 +08:00
|
|
|
if (allWidth) {
|
|
|
|
this.tableWidth = this.columns.map(cell => cell.width).reduce((a, b) => a + b);
|
|
|
|
} else {
|
|
|
|
this.tableWidth = parseInt(getStyle(this.$el, 'width')) - 1;
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
2016-11-30 16:12:10 +08:00
|
|
|
this.columnsWidth = {};
|
2016-11-25 15:47:28 +08:00
|
|
|
this.$nextTick(() => {
|
2016-11-30 16:12:10 +08:00
|
|
|
let columnsWidth = {};
|
2016-11-25 17:01:27 +08:00
|
|
|
let autoWidthIndex = -1;
|
2016-11-30 16:12:10 +08:00
|
|
|
if (allWidth) autoWidthIndex = this.cloneColumns.findIndex(cell => !cell.width);//todo 这行可能有问题
|
2016-11-25 17:01:27 +08:00
|
|
|
|
2016-12-01 11:02:06 +08:00
|
|
|
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];
|
2016-11-30 16:12:10 +08:00
|
|
|
|
2016-12-01 11:02:06 +08:00
|
|
|
let width = parseInt(getStyle($td[i], 'width'));
|
|
|
|
if (i === autoWidthIndex) {
|
|
|
|
width = parseInt(getStyle($td[i], 'width')) - 1;
|
|
|
|
}
|
|
|
|
if (column.width) width = column.width;
|
2016-11-30 16:12:10 +08:00
|
|
|
|
2016-12-01 11:02:06 +08:00
|
|
|
this.cloneColumns[i]._width = width;
|
2016-11-30 16:12:10 +08:00
|
|
|
|
2016-12-01 11:02:06 +08:00
|
|
|
columnsWidth[column._index] = {
|
|
|
|
width: width
|
2016-12-25 22:49:42 +08:00
|
|
|
};
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
2016-12-01 11:02:06 +08:00
|
|
|
this.columnsWidth = columnsWidth;
|
2016-11-25 17:01:27 +08:00
|
|
|
}
|
2016-11-23 18:38:39 +08:00
|
|
|
});
|
2017-01-13 20:18:21 +08:00
|
|
|
// get table real height,for fixed when set height prop,but height < table's height,show scrollBarWidth
|
|
|
|
this.bodyRealHeight = parseInt(getStyle(this.$refs.tbody.$el, 'height'));
|
2016-11-23 18:38:39 +08:00
|
|
|
});
|
|
|
|
},
|
2016-11-28 15:43:19 +08:00
|
|
|
handleMouseIn (_index) {
|
2017-06-09 17:06:20 +08:00
|
|
|
if (this.disabledHover) return;
|
2016-11-28 15:43:19 +08:00
|
|
|
if (this.objData[_index]._isHover) return;
|
|
|
|
this.objData[_index]._isHover = true;
|
2016-11-25 08:50:06 +08:00
|
|
|
},
|
2016-11-28 15:43:19 +08:00
|
|
|
handleMouseOut (_index) {
|
2017-06-09 17:06:20 +08:00
|
|
|
if (this.disabledHover) return;
|
2016-11-28 15:43:19 +08:00
|
|
|
this.objData[_index]._isHover = false;
|
2016-11-25 08:50:06 +08:00
|
|
|
},
|
2016-11-28 15:43:19 +08:00
|
|
|
highlightCurrentRow (_index) {
|
|
|
|
if (!this.highlightRow || this.objData[_index]._isHighlight) return;
|
2016-11-24 15:27:46 +08:00
|
|
|
|
|
|
|
let oldIndex = -1;
|
2016-11-28 15:43:19 +08:00
|
|
|
for (let i in this.objData) {
|
|
|
|
if (this.objData[i]._isHighlight) {
|
|
|
|
oldIndex = parseInt(i);
|
|
|
|
this.objData[i]._isHighlight = false;
|
2016-11-24 15:27:46 +08:00
|
|
|
}
|
2016-11-28 15:43:19 +08:00
|
|
|
}
|
|
|
|
this.objData[_index]._isHighlight = true;
|
2017-03-15 15:50:28 +08:00
|
|
|
const oldData = oldIndex < 0 ? null : JSON.parse(JSON.stringify(this.cloneData[oldIndex]));
|
|
|
|
this.$emit('on-current-change', JSON.parse(JSON.stringify(this.cloneData[_index])), oldData);
|
2016-11-24 15:27:46 +08:00
|
|
|
},
|
2017-01-02 19:05:45 -06:00
|
|
|
clickCurrentRow (_index) {
|
|
|
|
this.highlightCurrentRow (_index);
|
2017-03-15 15:50:28 +08:00
|
|
|
this.$emit('on-row-click', JSON.parse(JSON.stringify(this.cloneData[_index])));
|
2017-01-02 19:05:45 -06:00
|
|
|
},
|
|
|
|
dblclickCurrentRow (_index) {
|
|
|
|
this.highlightCurrentRow (_index);
|
2017-03-15 15:50:28 +08:00
|
|
|
this.$emit('on-row-dblclick', JSON.parse(JSON.stringify(this.cloneData[_index])));
|
2017-01-02 19:05:45 -06:00
|
|
|
},
|
2016-11-24 15:27:46 +08:00
|
|
|
getSelection () {
|
|
|
|
let selectionIndexes = [];
|
2016-11-28 15:43:19 +08:00
|
|
|
for (let i in this.objData) {
|
|
|
|
if (this.objData[i]._isChecked) selectionIndexes.push(parseInt(i));
|
|
|
|
}
|
2016-11-24 15:27:46 +08:00
|
|
|
return JSON.parse(JSON.stringify(this.data.filter((data, index) => selectionIndexes.indexOf(index) > -1)));
|
|
|
|
},
|
2016-11-28 15:43:19 +08:00
|
|
|
toggleSelect (_index) {
|
2016-11-28 14:23:49 +08:00
|
|
|
let data = {};
|
2016-11-28 15:43:19 +08:00
|
|
|
|
|
|
|
for (let i in this.objData) {
|
|
|
|
if (parseInt(i) === _index) {
|
|
|
|
data = this.objData[i];
|
2016-11-28 14:23:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const status = !data._isChecked;
|
2016-11-28 15:43:19 +08:00
|
|
|
|
|
|
|
this.objData[_index]._isChecked = status;
|
2016-11-24 15:27:46 +08:00
|
|
|
|
|
|
|
const selection = this.getSelection();
|
2017-07-07 13:01:49 -05:00
|
|
|
this.$emit(status ? 'on-select' : 'on-select-cancel', selection, JSON.parse(JSON.stringify(this.data[_index])));
|
2016-11-24 15:27:46 +08:00
|
|
|
this.$emit('on-selection-change', selection);
|
|
|
|
},
|
2017-05-27 15:13:10 +08:00
|
|
|
toggleExpand (_index) {
|
|
|
|
let data = {};
|
|
|
|
|
|
|
|
for (let i in this.objData) {
|
|
|
|
if (parseInt(i) === _index) {
|
|
|
|
data = this.objData[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const status = !data._isExpanded;
|
|
|
|
this.objData[_index]._isExpanded = status;
|
|
|
|
this.$emit('on-expand', JSON.parse(JSON.stringify(this.cloneData[_index])), status);
|
|
|
|
},
|
2016-11-26 10:50:24 +08:00
|
|
|
selectAll (status) {
|
2017-02-23 16:51:43 +08:00
|
|
|
// this.rebuildData.forEach((data) => {
|
|
|
|
// if(this.objData[data._index]._isDisabled){
|
|
|
|
// this.objData[data._index]._isChecked = false;
|
|
|
|
// }else{
|
|
|
|
// this.objData[data._index]._isChecked = status;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
for(const data of this.rebuildData){
|
2017-02-20 11:17:47 +08:00
|
|
|
if(this.objData[data._index]._isDisabled){
|
2017-02-23 16:51:43 +08:00
|
|
|
continue;
|
2017-02-20 11:17:47 +08:00
|
|
|
}else{
|
|
|
|
this.objData[data._index]._isChecked = status;
|
|
|
|
}
|
2017-02-23 16:51:43 +08:00
|
|
|
}
|
2016-11-27 22:56:05 +08:00
|
|
|
const selection = this.getSelection();
|
2016-11-26 10:50:24 +08:00
|
|
|
if (status) {
|
2016-11-27 22:56:05 +08:00
|
|
|
this.$emit('on-select-all', selection);
|
2016-11-26 10:50:24 +08:00
|
|
|
}
|
2016-11-27 22:56:05 +08:00
|
|
|
this.$emit('on-selection-change', selection);
|
2016-11-24 17:32:43 +08:00
|
|
|
},
|
|
|
|
fixedHeader () {
|
2016-12-25 22:49:42 +08:00
|
|
|
if (this.height) {
|
2016-11-24 17:32:43 +08:00
|
|
|
this.$nextTick(() => {
|
2017-03-09 14:11:22 +08:00
|
|
|
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;
|
2016-11-24 17:32:43 +08:00
|
|
|
this.bodyHeight = this.height - titleHeight - headerHeight - footerHeight;
|
2016-12-25 22:49:42 +08:00
|
|
|
});
|
2016-12-02 11:23:46 +08:00
|
|
|
} else {
|
|
|
|
this.bodyHeight = 0;
|
2016-11-24 17:32:43 +08:00
|
|
|
}
|
2016-11-25 08:50:06 +08:00
|
|
|
},
|
2016-11-29 08:43:47 +08:00
|
|
|
hideColumnFilter () {
|
|
|
|
this.cloneColumns.forEach((col) => col._filterVisible = false);
|
|
|
|
},
|
2016-11-25 17:01:27 +08:00
|
|
|
handleBodyScroll (event) {
|
2017-03-09 14:11:22 +08:00
|
|
|
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;
|
2016-11-29 08:43:47 +08:00
|
|
|
this.hideColumnFilter();
|
2016-11-25 17:01:27 +08:00
|
|
|
},
|
2016-11-25 22:51:50 +08:00
|
|
|
handleMouseWheel (event) {
|
|
|
|
const deltaX = event.deltaX;
|
2017-03-09 14:11:22 +08:00
|
|
|
const $body = this.$refs.body;
|
2016-11-25 22:51:50 +08:00
|
|
|
|
|
|
|
if (deltaX > 0) {
|
|
|
|
$body.scrollLeft = $body.scrollLeft + 10;
|
|
|
|
} else {
|
|
|
|
$body.scrollLeft = $body.scrollLeft - 10;
|
|
|
|
}
|
2016-11-27 22:56:05 +08:00
|
|
|
},
|
2016-11-29 15:35:06 +08:00
|
|
|
sortData (data, type, index) {
|
|
|
|
const key = this.cloneColumns[index].key;
|
|
|
|
data.sort((a, b) => {
|
|
|
|
if (this.cloneColumns[index].sortMethod) {
|
2017-01-16 01:27:02 -06:00
|
|
|
return this.cloneColumns[index].sortMethod(a[key], b[key], type);
|
2016-11-29 15:35:06 +08:00
|
|
|
} else {
|
2016-12-01 16:11:14 +08:00
|
|
|
if (type === 'asc') {
|
|
|
|
return a[key] > b[key] ? 1 : -1;
|
|
|
|
} else if (type === 'desc') {
|
|
|
|
return a[key] < b[key] ? 1 : -1;
|
|
|
|
}
|
2016-11-29 15:35:06 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return data;
|
|
|
|
},
|
2016-11-27 22:56:05 +08:00
|
|
|
handleSort (index, type) {
|
2016-11-28 16:53:19 +08:00
|
|
|
this.cloneColumns.forEach((col) => col._sortType = 'normal');
|
|
|
|
|
|
|
|
const key = this.cloneColumns[index].key;
|
2016-11-28 21:30:59 +08:00
|
|
|
if (this.cloneColumns[index].sortable !== 'custom') { // custom is for remote sort
|
2016-11-29 15:35:06 +08:00
|
|
|
if (type === 'normal') {
|
2016-11-29 16:05:14 +08:00
|
|
|
this.rebuildData = this.makeDataWithFilter();
|
2016-11-29 15:35:06 +08:00
|
|
|
} else {
|
|
|
|
this.rebuildData = this.sortData(this.rebuildData, type, index);
|
2016-11-28 21:30:59 +08:00
|
|
|
}
|
2016-11-27 22:56:05 +08:00
|
|
|
}
|
2016-11-28 16:53:19 +08:00
|
|
|
this.cloneColumns[index]._sortType = type;
|
|
|
|
|
|
|
|
this.$emit('on-sort-change', {
|
|
|
|
column: JSON.parse(JSON.stringify(this.columns[this.cloneColumns[index]._index])),
|
|
|
|
key: key,
|
|
|
|
order: type
|
2016-11-29 15:35:06 +08:00
|
|
|
});
|
2016-11-28 14:23:49 +08:00
|
|
|
},
|
2016-11-29 11:04:48 +08:00
|
|
|
handleFilterHide (index) { // clear checked that not filter now
|
|
|
|
if (!this.cloneColumns[index]._isFiltered) this.cloneColumns[index]._filterChecked = [];
|
|
|
|
},
|
2016-11-29 14:55:25 +08:00
|
|
|
filterData (data, column) {
|
|
|
|
return data.filter((row) => {
|
2017-04-22 14:18:07 +08:00
|
|
|
//如果定义了远程过滤方法则忽略此方法
|
2017-04-24 01:10:01 +08:00
|
|
|
if (typeof column.filterRemote === 'function') return true;
|
2017-04-22 14:18:07 +08:00
|
|
|
|
2016-11-29 14:55:25 +08:00
|
|
|
let status = !column._filterChecked.length;
|
2016-11-29 11:04:48 +08:00
|
|
|
for (let i = 0; i < column._filterChecked.length; i++) {
|
|
|
|
status = column.filterMethod(column._filterChecked[i], row);
|
|
|
|
if (status) break;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
});
|
2016-11-29 14:55:25 +08:00
|
|
|
},
|
|
|
|
filterOtherData (data, index) {
|
2017-04-06 17:07:03 +08:00
|
|
|
let column = this.cloneColumns[index];
|
2017-04-22 14:18:07 +08:00
|
|
|
if (typeof column.filterRemote === 'function') {
|
|
|
|
column.filterRemote.call(this.$parent, column._filterChecked, column.key, column);
|
2017-04-06 17:07:03 +08:00
|
|
|
}
|
|
|
|
|
2016-11-29 14:55:25 +08:00
|
|
|
this.cloneColumns.forEach((col, colIndex) => {
|
|
|
|
if (colIndex !== index) {
|
|
|
|
data = this.filterData(data, col);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
handleFilter (index) {
|
|
|
|
const column = this.cloneColumns[index];
|
2016-11-29 15:35:06 +08:00
|
|
|
let filterData = this.makeDataWithSort();
|
2016-11-29 14:55:25 +08:00
|
|
|
|
|
|
|
// filter others first, after filter this column
|
|
|
|
filterData = this.filterOtherData(filterData, index);
|
|
|
|
this.rebuildData = this.filterData(filterData, column);
|
|
|
|
|
2016-11-29 11:04:48 +08:00
|
|
|
this.cloneColumns[index]._isFiltered = true;
|
|
|
|
this.cloneColumns[index]._filterVisible = false;
|
|
|
|
},
|
2016-11-29 13:25:25 +08:00
|
|
|
handleFilterSelect (index, value) {
|
|
|
|
this.cloneColumns[index]._filterChecked = [value];
|
|
|
|
this.handleFilter(index);
|
|
|
|
},
|
2016-11-29 11:04:48 +08:00
|
|
|
handleFilterReset (index) {
|
|
|
|
this.cloneColumns[index]._isFiltered = false;
|
2016-11-29 13:25:25 +08:00
|
|
|
this.cloneColumns[index]._filterVisible = false;
|
|
|
|
this.cloneColumns[index]._filterChecked = [];
|
2016-11-29 14:55:25 +08:00
|
|
|
|
2016-11-29 15:35:06 +08:00
|
|
|
let filterData = this.makeDataWithSort();
|
2016-11-29 14:55:25 +08:00
|
|
|
filterData = this.filterOtherData(filterData, index);
|
|
|
|
this.rebuildData = filterData;
|
2016-11-29 11:04:48 +08:00
|
|
|
},
|
2016-11-28 14:23:49 +08:00
|
|
|
makeData () {
|
|
|
|
let data = deepCopy(this.data);
|
2017-07-14 14:52:54 +08:00
|
|
|
data.forEach((row, index) => {
|
|
|
|
row._index = index;
|
|
|
|
row._rowKey = rowKey++;
|
|
|
|
});
|
2016-11-28 14:23:49 +08:00
|
|
|
return data;
|
2016-11-28 15:43:19 +08:00
|
|
|
},
|
2016-11-29 15:35:06 +08:00
|
|
|
makeDataWithSort () {
|
|
|
|
let data = this.makeData();
|
|
|
|
let sortType = 'normal';
|
|
|
|
let sortIndex = -1;
|
2016-12-16 14:15:11 +08:00
|
|
|
let isCustom = false;
|
|
|
|
|
2016-11-29 15:35:06 +08:00
|
|
|
for (let i = 0; i < this.cloneColumns.length; i++) {
|
|
|
|
if (this.cloneColumns[i]._sortType !== 'normal') {
|
|
|
|
sortType = this.cloneColumns[i]._sortType;
|
|
|
|
sortIndex = i;
|
2016-12-16 14:15:11 +08:00
|
|
|
isCustom = this.cloneColumns[i].sortable === 'custom';
|
2016-11-29 15:35:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-16 14:15:11 +08:00
|
|
|
if (sortType !== 'normal' && !isCustom) data = this.sortData(data, sortType, sortIndex);
|
2016-11-29 15:35:06 +08:00
|
|
|
return data;
|
|
|
|
},
|
2016-11-29 16:05:14 +08:00
|
|
|
makeDataWithFilter () {
|
|
|
|
let data = this.makeData();
|
|
|
|
this.cloneColumns.forEach(col => data = this.filterData(data, col));
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
makeDataWithSortAndFilter () {
|
|
|
|
let data = this.makeDataWithSort();
|
|
|
|
this.cloneColumns.forEach(col => data = this.filterData(data, col));
|
|
|
|
return data;
|
|
|
|
},
|
2016-11-28 15:43:19 +08:00
|
|
|
makeObjData () {
|
|
|
|
let data = {};
|
|
|
|
this.data.forEach((row, index) => {
|
|
|
|
const newRow = deepCopy(row);// todo 直接替换
|
|
|
|
newRow._isHover = false;
|
2017-05-27 15:13:10 +08:00
|
|
|
if (newRow._disabled) {
|
2017-02-23 14:29:49 +08:00
|
|
|
newRow._isDisabled = newRow._disabled;
|
2017-05-27 15:13:10 +08:00
|
|
|
} else {
|
2017-02-23 14:29:49 +08:00
|
|
|
newRow._isDisabled = false;
|
|
|
|
}
|
2017-02-20 09:53:10 +08:00
|
|
|
if (newRow._checked) {
|
2017-02-28 15:10:07 +08:00
|
|
|
newRow._isChecked = newRow._checked;
|
2017-02-20 09:53:10 +08:00
|
|
|
} else {
|
2017-02-15 16:04:35 +08:00
|
|
|
newRow._isChecked = false;
|
|
|
|
}
|
2017-05-27 15:13:10 +08:00
|
|
|
if (newRow._expanded) {
|
|
|
|
newRow._isExpanded = newRow._expanded;
|
|
|
|
} else {
|
|
|
|
newRow._isExpanded = false;
|
|
|
|
}
|
2017-02-20 09:53:10 +08:00
|
|
|
if (newRow._highlight) {
|
|
|
|
newRow._isHighlight = newRow._highlight;
|
|
|
|
} else {
|
|
|
|
newRow._isHighlight = false;
|
|
|
|
}
|
2016-11-28 15:43:19 +08:00
|
|
|
data[index] = newRow;
|
|
|
|
});
|
|
|
|
return data;
|
2016-11-28 16:53:19 +08:00
|
|
|
},
|
|
|
|
makeColumns () {
|
|
|
|
let columns = deepCopy(this.columns);
|
|
|
|
let left = [];
|
|
|
|
let right = [];
|
|
|
|
let center = [];
|
|
|
|
|
|
|
|
columns.forEach((column, index) => {
|
|
|
|
column._index = index;
|
2017-07-14 14:52:54 +08:00
|
|
|
column._columnKey = columnKey++;
|
2016-11-30 16:12:10 +08:00
|
|
|
column._width = column.width ? column.width : ''; // update in handleResize()
|
2016-11-29 08:43:47 +08:00
|
|
|
column._sortType = 'normal';
|
|
|
|
column._filterVisible = false;
|
|
|
|
column._isFiltered = false;
|
|
|
|
column._filterChecked = [];
|
2016-11-28 16:53:19 +08:00
|
|
|
|
2016-11-29 11:04:48 +08:00
|
|
|
if ('filterMultiple' in column) {
|
|
|
|
column._filterMultiple = column.filterMultiple;
|
|
|
|
} else {
|
|
|
|
column._filterMultiple = true;
|
|
|
|
}
|
2016-11-30 13:17:55 +08:00
|
|
|
if ('filteredValue' in column) {
|
|
|
|
column._filterChecked = column.filteredValue;
|
|
|
|
column._isFiltered = true;
|
|
|
|
}
|
2016-11-29 11:04:48 +08:00
|
|
|
|
2016-11-28 16:53:19 +08:00
|
|
|
if (column.fixed && column.fixed === 'left') {
|
|
|
|
left.push(column);
|
|
|
|
} else if (column.fixed && column.fixed === 'right') {
|
|
|
|
right.push(column);
|
|
|
|
} else {
|
|
|
|
center.push(column);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return left.concat(center).concat(right);
|
2016-12-09 13:24:39 +08:00
|
|
|
},
|
|
|
|
exportCsv (params) {
|
|
|
|
if (params.filename) {
|
|
|
|
if (params.filename.indexOf('.csv') === -1) {
|
|
|
|
params.filename += '.csv';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
params.filename = 'table.csv';
|
|
|
|
}
|
|
|
|
|
|
|
|
let columns = [];
|
|
|
|
let datas = [];
|
|
|
|
if (params.columns && params.data) {
|
|
|
|
columns = params.columns;
|
|
|
|
datas = params.data;
|
|
|
|
} else {
|
|
|
|
columns = this.columns;
|
|
|
|
if (!('original' in params)) params.original = true;
|
|
|
|
datas = params.original ? this.data : this.rebuildData;
|
|
|
|
}
|
|
|
|
|
|
|
|
let noHeader = false;
|
|
|
|
if ('noHeader' in params) noHeader = params.noHeader;
|
|
|
|
|
|
|
|
const data = Csv(columns, datas, ',', noHeader);
|
|
|
|
ExportCsv.download(params.filename, data);
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
|
|
|
},
|
2017-03-09 14:11:22 +08:00
|
|
|
created () {
|
2017-03-17 09:50:11 +08:00
|
|
|
if (!this.context) this.currentContext = this.$parent;
|
2017-04-05 12:49:40 +08:00
|
|
|
this.showSlotHeader = this.$slots.header !== undefined;
|
|
|
|
this.showSlotFooter = this.$slots.footer !== undefined;
|
2016-11-30 13:17:55 +08:00
|
|
|
this.rebuildData = this.makeDataWithSortAndFilter();
|
2016-11-24 17:32:43 +08:00
|
|
|
},
|
2017-03-09 14:11:22 +08:00
|
|
|
mounted () {
|
2016-11-25 15:47:28 +08:00
|
|
|
this.handleResize();
|
2016-11-24 17:32:43 +08:00
|
|
|
this.fixedHeader();
|
2016-11-29 11:04:48 +08:00
|
|
|
this.$nextTick(() => this.ready = true);
|
2017-07-10 13:49:26 +08:00
|
|
|
// window.addEventListener('resize', this.handleResize, false);
|
|
|
|
on(window, 'resize', this.handleResize);
|
2017-04-10 09:58:51 +08:00
|
|
|
this.$on('on-visible-change', (val) => {
|
2017-04-10 14:22:08 +08:00
|
|
|
if (val) {
|
|
|
|
this.handleResize();
|
|
|
|
this.fixedHeader();
|
|
|
|
}
|
2017-04-10 09:58:51 +08:00
|
|
|
});
|
2016-11-23 18:38:39 +08:00
|
|
|
},
|
|
|
|
beforeDestroy () {
|
2017-07-10 13:49:26 +08:00
|
|
|
// window.removeEventListener('resize', this.handleResize, false);
|
|
|
|
off(window, 'resize', this.handleResize);
|
2016-11-23 16:27:17 +08:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
data: {
|
|
|
|
handler () {
|
2016-11-28 15:43:19 +08:00
|
|
|
this.objData = this.makeObjData();
|
2016-11-29 16:05:14 +08:00
|
|
|
this.rebuildData = this.makeDataWithSortAndFilter();
|
2016-11-25 15:47:28 +08:00
|
|
|
this.handleResize();
|
2017-03-15 15:50:28 +08:00
|
|
|
// here will trigger before clickCurrentRow, so use async
|
|
|
|
setTimeout(() => {
|
|
|
|
this.cloneData = deepCopy(this.data);
|
|
|
|
}, 0);
|
2016-11-23 16:27:17 +08:00
|
|
|
},
|
|
|
|
deep: true
|
|
|
|
},
|
|
|
|
columns: {
|
|
|
|
handler () {
|
2016-12-02 11:23:46 +08:00
|
|
|
// todo 这里有性能问题,可能是左右固定计算属性影响的
|
2016-11-28 16:53:19 +08:00
|
|
|
this.cloneColumns = this.makeColumns();
|
2016-11-29 16:05:14 +08:00
|
|
|
this.rebuildData = this.makeDataWithSortAndFilter();
|
2016-11-25 15:47:28 +08:00
|
|
|
this.handleResize();
|
2016-11-23 16:27:17 +08:00
|
|
|
},
|
|
|
|
deep: true
|
2016-11-24 17:32:43 +08:00
|
|
|
},
|
|
|
|
height () {
|
|
|
|
this.fixedHeader();
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
2016-12-25 22:49:42 +08:00
|
|
|
};
|
|
|
|
</script>
|