|
@@ -1,38 +1,99 @@
|
|
<template>
|
|
<template>
|
|
- <div class="el-table" :class="{ 'el-table--fit': fit, 'el-table--striped': stripe, 'el-table--border': border }" @mouseleave="handleMouseLeave($event)">
|
|
|
|
|
|
+ <div class="el-table"
|
|
|
|
+ :class="{ 'el-table--fit': fit, 'el-table--striped': stripe, 'el-table--border': border }"
|
|
|
|
+ @mouseleave="handleMouseLeave($event)">
|
|
<div class="hidden-columns" ref="hiddenColumns"><slot></slot></div>
|
|
<div class="hidden-columns" ref="hiddenColumns"><slot></slot></div>
|
|
- <div class="el-table__header-wrapper">
|
|
|
|
- <table-header :columns="columns" :all-selected="allSelected" @allselectedchange="handleAllSelectedChange" :selection="selection" :style="{ width: bodyWidth ? bodyWidth + 'px' : '' }" :border="border"></table-header>
|
|
|
|
|
|
+ <div class="el-table__header-wrapper" ref="headerWrapper">
|
|
|
|
+ <table-header
|
|
|
|
+ :store="store"
|
|
|
|
+ :layout="layout"
|
|
|
|
+ :border="border"
|
|
|
|
+ :style="{ width: layout.bodyWidth ? layout.bodyWidth + 'px' : '' }">
|
|
|
|
+ </table-header>
|
|
</div>
|
|
</div>
|
|
- <div class="el-table__body-wrapper">
|
|
|
|
- <table-body :columns="columns" :selection="selection" :data="filterData" :style="{ width: bodyWidth ? bodyWidth - (showVScrollBar ? currentGutterWidth : 0 ) + 'px' : '' }"></table-body>
|
|
|
|
|
|
+ <div class="el-table__body-wrapper" ref="bodyWrapper"
|
|
|
|
+ :style="{ height: layout.bodyHeight ? layout.bodyHeight + 'px' : '' }">
|
|
|
|
+ <table-body
|
|
|
|
+ :store="store"
|
|
|
|
+ :layout="layout"
|
|
|
|
+ :row-class-name="rowClassName"
|
|
|
|
+ :style="{ width: layout.bodyWidth ? layout.bodyWidth - (layout.scrollY ? layout.gutterWidth : 0 ) + 'px' : '' }">
|
|
|
|
+ </table-body>
|
|
</div>
|
|
</div>
|
|
- <div class="el-table__fixed" :style="{ width: fixedBodyWidth ? fixedBodyWidth + 'px' : '' }" ref="fixed">
|
|
|
|
- <div class="el-table__fixed-header-wrapper" v-if="fixedColumnCount > 0">
|
|
|
|
- <table-header :columns="fixedColumns" :all-selected="allSelected" @allselectedchange="handleAllSelectedChange" :selection="selection" :style="{ width: fixedBodyWidth ? fixedBodyWidth + 'px' : '' }" :border="border"></table-header>
|
|
|
|
|
|
+ <div class="el-table__fixed" ref="fixedWrapper"
|
|
|
|
+ :style="{
|
|
|
|
+ width: layout.fixedWidth ? layout.fixedWidth + 'px' : '',
|
|
|
|
+ height: layout.viewportHeight ? layout.viewportHeight + 'px' : ''
|
|
|
|
+ }">
|
|
|
|
+ <div class="el-table__fixed-header-wrapper" ref="fixedHeaderWrapper"
|
|
|
|
+ v-if="fixedColumns.length > 0">
|
|
|
|
+ <table-header
|
|
|
|
+ fixed="left"
|
|
|
|
+ :border="border"
|
|
|
|
+ :store="store"
|
|
|
|
+ :layout="layout"
|
|
|
|
+ :style="{ width: layout.fixedWidth ? layout.fixedWidth + 'px' : '' }"></table-header>
|
|
</div>
|
|
</div>
|
|
- <div class="el-table__fixed-body-wrapper" v-if="fixedColumnCount > 0" :style="{ top: headerHeight + 'px' }">
|
|
|
|
- <table-body :columns="fixedColumns" fixed :selection="selection" :data="filterData" :style="{ width: fixedBodyWidth ? fixedBodyWidth + 'px' : '' }"></table-body>
|
|
|
|
|
|
+ <div class="el-table__fixed-body-wrapper" ref="fixedBodyWrapper"
|
|
|
|
+ v-if="fixedColumns.length > 0"
|
|
|
|
+ :style="{
|
|
|
|
+ top: layout.headerHeight + 'px',
|
|
|
|
+ height: layout.fixedBodyHeight ? layout.fixedBodyHeight + 'px' : ''
|
|
|
|
+ }">
|
|
|
|
+ <table-body
|
|
|
|
+ fixed="left"
|
|
|
|
+ :store="store"
|
|
|
|
+ :layout="layout"
|
|
|
|
+ :row-class-name="rowClassName"
|
|
|
|
+ :style="{ width: layout.fixedWidth ? layout.fixedWidth + 'px' : '' }">
|
|
|
|
+ </table-body>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ <div class="el-table__fixed-right" ref="rightFixedWrapper"
|
|
|
|
+ :style="{
|
|
|
|
+ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '',
|
|
|
|
+ height: layout.viewportHeight ? layout.viewportHeight + 'px' : '',
|
|
|
|
+ right: layout.scrollY ? layout.gutterWidth + 'px' : ''
|
|
|
|
+ }">
|
|
|
|
+ <div class="el-table__fixed-header-wrapper" ref="rightFixedHeaderWrapper"
|
|
|
|
+ v-if="rightFixedColumns.length > 0">
|
|
|
|
+ <table-header
|
|
|
|
+ fixed="right"
|
|
|
|
+ :border="border"
|
|
|
|
+ :store="store"
|
|
|
|
+ :layout="layout"
|
|
|
|
+ :style="{ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '' }"></table-header>
|
|
|
|
+ </div>
|
|
|
|
+ <div class="el-table__fixed-body-wrapper" ref="rightFixedBodyWrapper"
|
|
|
|
+ v-if="rightFixedColumns.length > 0"
|
|
|
|
+ :style="{
|
|
|
|
+ top: layout.headerHeight + 'px',
|
|
|
|
+ height: layout.fixedBodyHeight ? layout.fixedBodyHeight + 'px' : ''
|
|
|
|
+ }">
|
|
|
|
+ <table-body
|
|
|
|
+ fixed="right"
|
|
|
|
+ :store="store"
|
|
|
|
+ :layout="layout"
|
|
|
|
+ :row-class-name="rowClassName"
|
|
|
|
+ :style="{ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '' }">
|
|
|
|
+ </table-body>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="el-table__column-resize-proxy" ref="resizeProxy" v-show="resizeProxyVisible"></div>
|
|
<div class="el-table__column-resize-proxy" ref="resizeProxy" v-show="resizeProxyVisible"></div>
|
|
- <slot name="bottom"></slot>
|
|
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script type="text/babel">
|
|
<script type="text/babel">
|
|
import throttle from 'throttle-debounce/throttle';
|
|
import throttle from 'throttle-debounce/throttle';
|
|
import debounce from 'throttle-debounce/debounce';
|
|
import debounce from 'throttle-debounce/debounce';
|
|
- import { getScrollBarWidth, orderBy } from './util';
|
|
|
|
- import objectAssign from 'object-assign';
|
|
|
|
import { addResizeListener, removeResizeListener } from './resize-event';
|
|
import { addResizeListener, removeResizeListener } from './resize-event';
|
|
-
|
|
|
|
- let gridIdSeed = 1;
|
|
|
|
- let GUTTER_WIDTH;
|
|
|
|
-
|
|
|
|
|
|
+ import TableStore from './table-store';
|
|
|
|
+ import TableLayout from './table-layout';
|
|
import TableBody from './table-body';
|
|
import TableBody from './table-body';
|
|
import TableHeader from './table-header';
|
|
import TableHeader from './table-header';
|
|
|
|
|
|
|
|
+ let tableIdSeed = 1;
|
|
|
|
+
|
|
export default {
|
|
export default {
|
|
name: 'el-table',
|
|
name: 'el-table',
|
|
|
|
|
|
@@ -53,39 +114,18 @@
|
|
default: true
|
|
default: true
|
|
},
|
|
},
|
|
|
|
|
|
- stripe: {
|
|
|
|
- type: Boolean,
|
|
|
|
- default: false
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- border: {
|
|
|
|
- type: Boolean,
|
|
|
|
- default: false
|
|
|
|
- },
|
|
|
|
|
|
+ stripe: Boolean,
|
|
|
|
|
|
- fixedColumnCount: {
|
|
|
|
- type: Number,
|
|
|
|
- default: 0
|
|
|
|
- },
|
|
|
|
|
|
+ border: Boolean,
|
|
|
|
|
|
selectionMode: {
|
|
selectionMode: {
|
|
type: String,
|
|
type: String,
|
|
default: 'none'
|
|
default: 'none'
|
|
},
|
|
},
|
|
|
|
|
|
- selection: {},
|
|
|
|
-
|
|
|
|
- allowNoSelection: {
|
|
|
|
- type: Boolean,
|
|
|
|
- default: false
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- gutterWidth: {
|
|
|
|
- default: 0
|
|
|
|
- },
|
|
|
|
|
|
+ allowNoSelection: Boolean,
|
|
|
|
|
|
- customCriteria: Array,
|
|
|
|
- customBackgroundColors: Array
|
|
|
|
|
|
+ rowClassName: [String, Function]
|
|
},
|
|
},
|
|
|
|
|
|
components: {
|
|
components: {
|
|
@@ -94,371 +134,131 @@
|
|
},
|
|
},
|
|
|
|
|
|
methods: {
|
|
methods: {
|
|
- handleAllSelectedChange(val) {
|
|
|
|
- this.allSelected = val;
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- doOnDataChange(data) {
|
|
|
|
- data = data || [];
|
|
|
|
-
|
|
|
|
- if (this.selectionMode === 'single') {
|
|
|
|
- const oldSelection = this.selected;
|
|
|
|
- if (oldSelection === null) {
|
|
|
|
- if (!this.allowNoSelection) {
|
|
|
|
- this.selected = data[0];
|
|
|
|
- if (this.selected !== oldSelection) {
|
|
|
|
- this.$emit('selectionchange', this.selected);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else if (data.indexOf(oldSelection) === -1) {
|
|
|
|
- if (!this.allowNoSelection) {
|
|
|
|
- this.selected = data[0];
|
|
|
|
- } else {
|
|
|
|
- this.selected = null;
|
|
|
|
- }
|
|
|
|
- if (this.selected !== oldSelection) {
|
|
|
|
- this.$emit('selectionchange', this.selected);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- toggleAllSelection() {
|
|
|
|
- setTimeout(() => {
|
|
|
|
- this.tableData.forEach(item => {
|
|
|
|
- item.$selected = this.allSelected;
|
|
|
|
- });
|
|
|
|
- }, 0);
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- $calcColumns() {
|
|
|
|
- let fit = this.fit;
|
|
|
|
- let columns = this.columns;
|
|
|
|
-
|
|
|
|
- let bodyWidth = this.$el.clientWidth;
|
|
|
|
- let bodyMinWidth = 0;
|
|
|
|
-
|
|
|
|
- let flattenColumns = [];
|
|
|
|
-
|
|
|
|
- columns.forEach((column) => {
|
|
|
|
- if (column.isColumnGroup) {
|
|
|
|
- flattenColumns.push.apply(flattenColumns, column.columns);
|
|
|
|
- } else {
|
|
|
|
- flattenColumns.push(column);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- if (fit) {
|
|
|
|
- let flexColumns = [];
|
|
|
|
- // let definedWidthColumnsWidth = 0;
|
|
|
|
- // let definedMinWidthSum = 0;
|
|
|
|
-
|
|
|
|
- flattenColumns.forEach((column) => {
|
|
|
|
- // definedMinWidthSum += column.minWidth || 80;
|
|
|
|
- bodyMinWidth += column.width || column.minWidth || 80;
|
|
|
|
-
|
|
|
|
- if (typeof column.width === 'number') {
|
|
|
|
- // definedWidthColumnsWidth += column.width;
|
|
|
|
- } else {
|
|
|
|
- flexColumns.push(column);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- if (bodyMinWidth < bodyWidth - this.currentGutterWidth) { // do not have scroll bar.
|
|
|
|
- let flexWidthTotal = bodyWidth - this.currentGutterWidth - columns.length - bodyMinWidth;
|
|
|
|
- let flexWidthPerColumn = Math.floor(flexWidthTotal / flexColumns.length);
|
|
|
|
- let flexWidthFirstColumn = flexWidthTotal - flexWidthPerColumn * flexColumns.length + flexWidthPerColumn;
|
|
|
|
-
|
|
|
|
- flexColumns.forEach((column, index) => {
|
|
|
|
- if (index === 0) {
|
|
|
|
- column.realWidth = (column.minWidth || 80) + flexWidthFirstColumn;
|
|
|
|
- } else {
|
|
|
|
- column.realWidth = (column.minWidth || 80) + flexWidthPerColumn;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- } else { // need horizontal scroll bar.
|
|
|
|
- this.showHScrollBar = true;
|
|
|
|
- flexColumns.forEach(function(column) {
|
|
|
|
- column.realWidth = column.minWidth;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.bodyWidth = Math.max(bodyMinWidth, bodyWidth);
|
|
|
|
- } else {
|
|
|
|
- flattenColumns.forEach((column) => {
|
|
|
|
- if (!column.width && !column.minWidth) {
|
|
|
|
- column.realWidth = 80;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- bodyMinWidth += column.realWidth;
|
|
|
|
- });
|
|
|
|
- this.showHScrollBar = bodyMinWidth > bodyWidth;
|
|
|
|
-
|
|
|
|
- this.bodyWidth = bodyMinWidth;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this.styleNode) {
|
|
|
|
- let styleSheet = this.styleNode.sheet;
|
|
|
|
-
|
|
|
|
- if (!styleSheet) return;
|
|
|
|
- for (let i = 0, j = styleSheet.cssRules.length; i < j; i++) {
|
|
|
|
- styleSheet.deleteRule(0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- columns.forEach(function(column) {
|
|
|
|
- const addRule = function(rule) {
|
|
|
|
- styleSheet.insertRule(rule, styleSheet.cssRules.length);
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- if (column.isColumnGroup) {
|
|
|
|
- let childColumns = column.columns;
|
|
|
|
- let groupWidth = 0;
|
|
|
|
- childColumns.forEach(function(childColumn) {
|
|
|
|
- groupWidth += childColumn.realWidth;
|
|
|
|
- addRule(`.${childColumn.id}, .${childColumn.id} > div { width: ${childColumn.realWidth}px; }`);
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- addRule(`.${column.id}, .${column.id} > div { width: ${groupWidth}px; }`);
|
|
|
|
- } else {
|
|
|
|
- addRule(`.${column.id}, .${column.id} > div { width: ${column.realWidth}px; }`);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this.fixedColumnCount > 0) {
|
|
|
|
- let fixedBodyWidth = 0;
|
|
|
|
- let fixedColumnCount = this.fixedColumnCount;
|
|
|
|
- columns.forEach(function(column, index) {
|
|
|
|
- if (index < fixedColumnCount) {
|
|
|
|
- fixedBodyWidth += column.realWidth;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- this.fixedBodyWidth = fixedBodyWidth;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.$nextTick(() => {
|
|
|
|
- this.headerHeight = this.$el.querySelector('.el-table__header-wrapper').offsetHeight;
|
|
|
|
- });
|
|
|
|
|
|
+ handleMouseLeave() {
|
|
|
|
+ this.store.commit('setHoverRow', null);
|
|
|
|
+ if (this.hoverState) this.hoverState = null;
|
|
},
|
|
},
|
|
|
|
|
|
- $calcHeight(height) {
|
|
|
|
- if (typeof height === 'string' && /^\d+$/.test(height)) {
|
|
|
|
- height = Number(height);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!isNaN(height) && this.$el) {
|
|
|
|
- const headerHeight = this.headerHeight = this.$el.querySelector('.el-table__header-wrapper').offsetHeight;
|
|
|
|
- const bodyHeight = (height - headerHeight);
|
|
|
|
- const gridWrapper = this.$el.querySelector('.el-table__body-wrapper');
|
|
|
|
- gridWrapper.style.height = bodyHeight + 'px';
|
|
|
|
- this.$el.style.height = height + 'px';
|
|
|
|
- if (this.$refs.fixed) {
|
|
|
|
- this.$refs.fixed.style.height = height + 'px';
|
|
|
|
- }
|
|
|
|
- const fixedBodyWrapper = this.$el.querySelector('.el-table__fixed-body-wrapper');
|
|
|
|
- if (fixedBodyWrapper) {
|
|
|
|
- fixedBodyWrapper.style.height = (this.showHScrollBar ? gridWrapper.offsetHeight - this.currentGutterWidth : gridWrapper.offsetHeight) + 'px';
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ updateScrollY() {
|
|
|
|
+ this.layout.updateScrollY();
|
|
},
|
|
},
|
|
|
|
|
|
- handleMouseLeave() {
|
|
|
|
- this.hoverRowIndex = null;
|
|
|
|
- const hoverState = this.hoverState;
|
|
|
|
- if (hoverState) {
|
|
|
|
- this.hoverState = null;
|
|
|
|
- }
|
|
|
|
|
|
+ syncHeight() {
|
|
|
|
+ this.layout.syncHeight();
|
|
},
|
|
},
|
|
|
|
|
|
- updateScrollInfo() {
|
|
|
|
- this.$nextTick(() => {
|
|
|
|
- if (this.$el) {
|
|
|
|
- let gridBodyWrapper = this.$el.querySelector('.el-table__body-wrapper');
|
|
|
|
- let gridBody = this.$el.querySelector('.el-table__body-wrapper .el-table__body');
|
|
|
|
-
|
|
|
|
- this.showVScrollBar = gridBody.offsetHeight > gridBodyWrapper.offsetHeight;
|
|
|
|
- }
|
|
|
|
|
|
+ bindEvents() {
|
|
|
|
+ const { bodyWrapper, headerWrapper } = this.$refs;
|
|
|
|
+ const refs = this.$refs;
|
|
|
|
+ bodyWrapper.addEventListener('scroll', function() {
|
|
|
|
+ headerWrapper.scrollLeft = this.scrollLeft;
|
|
|
|
+ if (refs.fixedBodyWrapper) refs.fixedBodyWrapper.scrollTop = this.scrollTop;
|
|
|
|
+ if (refs.rightFixedBodyWrapper) refs.rightFixedBodyWrapper.scrollTop = this.scrollTop;
|
|
});
|
|
});
|
|
- },
|
|
|
|
|
|
|
|
- doRender() {
|
|
|
|
- let bodyWrapper = this.$el.querySelector('.el-table__body-wrapper');
|
|
|
|
- let headerWrapper = this.$el.querySelector('.el-table__header-wrapper');
|
|
|
|
- const el = this.$el;
|
|
|
|
-
|
|
|
|
- if (!this.$ready) {
|
|
|
|
- bodyWrapper.addEventListener('scroll', function() {
|
|
|
|
- headerWrapper.scrollLeft = this.scrollLeft;
|
|
|
|
- let fixedBodyWrapper = el.querySelector('.el-table__fixed-body-wrapper');
|
|
|
|
- if (fixedBodyWrapper) {
|
|
|
|
- fixedBodyWrapper.scrollTop = this.scrollTop;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.$calcColumns();
|
|
|
|
-
|
|
|
|
- if (!this.$ready && this.fit) {
|
|
|
|
|
|
+ if (this.fit) {
|
|
this.windowResizeListener = throttle(50, () => {
|
|
this.windowResizeListener = throttle(50, () => {
|
|
- this.$calcColumns();
|
|
|
|
|
|
+ if (this.$ready) this.doLayout();
|
|
});
|
|
});
|
|
addResizeListener(this.$el, this.windowResizeListener);
|
|
addResizeListener(this.$el, this.windowResizeListener);
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
|
|
|
|
+ doLayout() {
|
|
|
|
+ this.store.updateColumns();
|
|
|
|
+ this.layout.update();
|
|
|
|
+ this.updateScrollY();
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
if (this.height) {
|
|
if (this.height) {
|
|
- this.$calcHeight(this.height);
|
|
|
|
|
|
+ this.layout.setHeight(this.height);
|
|
|
|
+ } else if (this.shouldUpdateHeight) {
|
|
|
|
+ this.layout.updateHeight();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
created() {
|
|
created() {
|
|
- this.gridId = 'grid_' + gridIdSeed + '_';
|
|
|
|
-
|
|
|
|
- if (GUTTER_WIDTH === undefined) {
|
|
|
|
- GUTTER_WIDTH = getScrollBarWidth();
|
|
|
|
- }
|
|
|
|
- this.currentGutterWidth = GUTTER_WIDTH;
|
|
|
|
-
|
|
|
|
- this.debouncedReRender = debounce(50, () => {
|
|
|
|
- this.doRender();
|
|
|
|
- });
|
|
|
|
|
|
+ this.tableId = 'el-table_' + tableIdSeed + '_';
|
|
|
|
+ this.debouncedLayout = debounce(50, () => this.doLayout());
|
|
},
|
|
},
|
|
|
|
|
|
computed: {
|
|
computed: {
|
|
|
|
+ shouldUpdateHeight() {
|
|
|
|
+ return typeof this.height === 'number' ||
|
|
|
|
+ this.fixedColumns.length > 0 ||
|
|
|
|
+ this.rightFixedColumns.length > 0;
|
|
|
|
+ },
|
|
|
|
+
|
|
selection() {
|
|
selection() {
|
|
if (this.selectionMode === 'multiple') {
|
|
if (this.selectionMode === 'multiple') {
|
|
const data = this.tableData || [];
|
|
const data = this.tableData || [];
|
|
return data.filter(item => item.$selected === true);
|
|
return data.filter(item => item.$selected === true);
|
|
} else if (this.selectionMode === 'single') {
|
|
} else if (this.selectionMode === 'single') {
|
|
- return this.selected;
|
|
|
|
- } else {
|
|
|
|
- return null;
|
|
|
|
|
|
+ return this.store.currentRow;
|
|
}
|
|
}
|
|
|
|
+ return null;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ columns() {
|
|
|
|
+ return this.store.states.columns;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ tableData() {
|
|
|
|
+ return this.store.states.data;
|
|
},
|
|
},
|
|
|
|
|
|
fixedColumns() {
|
|
fixedColumns() {
|
|
- const columns = this.columns || [];
|
|
|
|
- const fixedColumnCount = this.fixedColumnCount;
|
|
|
|
- return columns.filter(function(item, index) {
|
|
|
|
- return index < fixedColumnCount;
|
|
|
|
- });
|
|
|
|
|
|
+ return this.store.states.fixedColumns;
|
|
},
|
|
},
|
|
|
|
|
|
- filterData() {
|
|
|
|
- return orderBy(this.tableData, this.sortingProperty, this.sortingDirection);
|
|
|
|
|
|
+ rightFixedColumns() {
|
|
|
|
+ return this.store.states.rightFixedColumns;
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
watch: {
|
|
watch: {
|
|
- fixedColumnCount() {
|
|
|
|
- this.debouncedReRender();
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
selection(val) {
|
|
selection(val) {
|
|
this.$emit('selectionchange', val);
|
|
this.$emit('selectionchange', val);
|
|
- if (this.selectionMode === 'multiple') {
|
|
|
|
- this.allSelected = this.tableData.length > 0 && val.length === this.tableData.length;
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- visibleFilter(val) {
|
|
|
|
- this.$broadcast('toggleFilterPopup', val);
|
|
|
|
},
|
|
},
|
|
|
|
|
|
height(value) {
|
|
height(value) {
|
|
- this.$calcHeight(value);
|
|
|
|
|
|
+ this.layout.setHeight(value);
|
|
},
|
|
},
|
|
|
|
|
|
data: {
|
|
data: {
|
|
immediate: true,
|
|
immediate: true,
|
|
handler(val) {
|
|
handler(val) {
|
|
- if (val && this.selectionMode === 'multiple') {
|
|
|
|
- this.tableData = val.map(item => objectAssign({ '$selected': false }, item));
|
|
|
|
- } else {
|
|
|
|
- this.tableData = val;
|
|
|
|
- }
|
|
|
|
|
|
+ this.store.commit('setData', val);
|
|
}
|
|
}
|
|
- },
|
|
|
|
-
|
|
|
|
- tableData(newVal) {
|
|
|
|
- this.$nextTick(_ => this.doRender());
|
|
|
|
- this.doOnDataChange(newVal);
|
|
|
|
- this.updateScrollInfo();
|
|
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
destroyed() {
|
|
destroyed() {
|
|
- if (this.styleNode) {
|
|
|
|
- this.styleNode.parentNode.removeChild(this.styleNode);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this.windowResizeListener) {
|
|
|
|
- removeResizeListener(this.$el, this.windowResizeListener);
|
|
|
|
- }
|
|
|
|
|
|
+ if (this.windowResizeListener) removeResizeListener(this.$el, this.windowResizeListener);
|
|
},
|
|
},
|
|
|
|
|
|
mounted() {
|
|
mounted() {
|
|
- const styleNode = document.createElement('style');
|
|
|
|
- styleNode.type = 'text/css';
|
|
|
|
- styleNode.rel = 'stylesheet';
|
|
|
|
- styleNode.title = 'Grid Column Style';
|
|
|
|
- document.getElementsByTagName('head')[0].appendChild(styleNode);
|
|
|
|
-
|
|
|
|
- this.styleNode = styleNode;
|
|
|
|
-
|
|
|
|
- this.doRender();
|
|
|
|
|
|
+ this.bindEvents();
|
|
|
|
+ this.doLayout();
|
|
|
|
|
|
this.$ready = true;
|
|
this.$ready = true;
|
|
- if (this.tableData) {
|
|
|
|
- this.doOnDataChange(this.tableData);
|
|
|
|
- }
|
|
|
|
- this.updateScrollInfo();
|
|
|
|
- if (this.fixedColumnCount > 0) {
|
|
|
|
- this.$nextTick(() => {
|
|
|
|
- const style = this.$refs.fixed.style;
|
|
|
|
- if (!style) return;
|
|
|
|
- // style.height = this.$el.clientHeight + 'px';
|
|
|
|
- // 存在横向滚动条的时候应该要减去滚动条的高度
|
|
|
|
- style.height = (this.showHScrollBar ? this.$el.clientHeight - this.currentGutterWidth : this.$el.clientHeight) + 'px';
|
|
|
|
- // 若非固定列中的某行内容被撑高, 需要固定列中对应行高度与其保持一致
|
|
|
|
- let bodyHeight = this.$el.querySelector('.el-table__body-wrapper').offsetHeight;
|
|
|
|
- let fixedBodyHeight = this.$el.querySelector('.el-table__fixed-body-wrapper').offsetHeight;
|
|
|
|
- if (bodyHeight !== fixedBodyHeight) {
|
|
|
|
- let bodyTrs = this.$el.querySelector('.el-table__body-wrapper').querySelectorAll('tr');
|
|
|
|
- let fixedBodyTrs = this.$el.querySelector('.el-table__fixed-body-wrapper').querySelectorAll('tr');
|
|
|
|
- bodyTrs.forEach((tr, index) => {
|
|
|
|
- let trHeight = tr.offsetHeight;
|
|
|
|
- let fixedTrHeight = fixedBodyTrs[index].offsetHeight;
|
|
|
|
- if (trHeight !== fixedTrHeight) {
|
|
|
|
- fixedBodyTrs[index].style.height = trHeight + 'px';
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
},
|
|
},
|
|
|
|
|
|
data() {
|
|
data() {
|
|
|
|
+ const store = new TableStore(this, {
|
|
|
|
+ allowNoSelection: this.allowNoSelection,
|
|
|
|
+ selectionMode: this.selectionMode
|
|
|
|
+ });
|
|
|
|
+ const layout = new TableLayout({
|
|
|
|
+ store,
|
|
|
|
+ table: this,
|
|
|
|
+ fit: this.fit
|
|
|
|
+ });
|
|
return {
|
|
return {
|
|
- tableData: this.data,
|
|
|
|
- showHScrollBar: false,
|
|
|
|
- showVScrollBar: false,
|
|
|
|
- hoverRowIndex: null,
|
|
|
|
- headerHeight: 35,
|
|
|
|
- selected: null,
|
|
|
|
- allSelected: false,
|
|
|
|
- columns: [],
|
|
|
|
- resizeProxyVisible: false,
|
|
|
|
- bodyWidth: '',
|
|
|
|
- fixedBodyWidth: '',
|
|
|
|
- sortingColumn: null,
|
|
|
|
- sortingProperty: null,
|
|
|
|
- sortingDirection: 1,
|
|
|
|
- visibleFilter: null,
|
|
|
|
- currentGutterWidth: this.gutterWidth
|
|
|
|
|
|
+ store,
|
|
|
|
+ layout,
|
|
|
|
+ resizeProxyVisible: false
|
|
};
|
|
};
|
|
}
|
|
}
|
|
};
|
|
};
|