|
@@ -1,5 +1,7 @@
|
|
|
import ElCheckbox from 'element-ui/packages/checkbox';
|
|
|
import ElTag from 'element-ui/packages/tag';
|
|
|
+import Vue from 'vue';
|
|
|
+import FilterPanel from './filter-panel.vue';
|
|
|
|
|
|
export default {
|
|
|
name: 'el-table-header',
|
|
@@ -31,21 +33,27 @@ export default {
|
|
|
on-mousemove={ ($event) => this.handleMouseMove($event, column) }
|
|
|
on-mouseout={ this.handleMouseOut }
|
|
|
on-mousedown={ ($event) => this.handleMouseDown($event, column) }
|
|
|
- on-click={ ($event) => this.handleHeaderClick($event, column) }
|
|
|
class={ [column.id, column.direction, column.align, this.isCellHidden(cellIndex) ? 'hidden' : ''] }>
|
|
|
+ <div class={ ['cell', column.filteredValue && column.filteredValue.length > 0 ? 'highlight' : ''] }>
|
|
|
{
|
|
|
- [
|
|
|
- column.headerTemplate
|
|
|
- ? column.headerTemplate.call(this._renderProxy, h, column.label)
|
|
|
- : <div>{ column.label }</div>,
|
|
|
- column.sortable
|
|
|
- ? <div class="caret-wrapper">
|
|
|
- <i class="sort-caret ascending"></i>
|
|
|
- <i class="sort-caret descending"></i>
|
|
|
- </div>
|
|
|
- : ''
|
|
|
- ]
|
|
|
+ column.headerTemplate
|
|
|
+ ? column.headerTemplate.call(this._renderProxy, h, column.label)
|
|
|
+ : column.label
|
|
|
}
|
|
|
+ {
|
|
|
+ column.sortable
|
|
|
+ ? <span class="caret-wrapper" on-click={ ($event) => this.handleHeaderClick($event, column) }>
|
|
|
+ <i class="sort-caret ascending"></i>
|
|
|
+ <i class="sort-caret descending"></i>
|
|
|
+ </span>
|
|
|
+ : ''
|
|
|
+ }
|
|
|
+ {
|
|
|
+ column.filterable
|
|
|
+ ? <span class="el-table__column-filter-trigger" on-click={ ($event) => this.handleFilterClick($event, column) }><i class={ ['el-icon-arrow-down', column.filterOpened ? 'el-icon-arrow-up' : ''] }></i></span>
|
|
|
+ : ''
|
|
|
+ }
|
|
|
+ </div>
|
|
|
</th>
|
|
|
)
|
|
|
}
|
|
@@ -61,7 +69,6 @@ export default {
|
|
|
},
|
|
|
|
|
|
props: {
|
|
|
- columns: {},
|
|
|
fixed: String,
|
|
|
store: {
|
|
|
required: true
|
|
@@ -99,6 +106,19 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ created() {
|
|
|
+ this.filterPanels = {};
|
|
|
+ },
|
|
|
+
|
|
|
+ beforeDestroy() {
|
|
|
+ const panels = this.filterPanels;
|
|
|
+ for (let prop in panels) {
|
|
|
+ if (panels.hasOwnProperty(prop) && panels[prop]) {
|
|
|
+ panels[prop].$destroy(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
methods: {
|
|
|
isCellHidden(index) {
|
|
|
if (this.fixed === true || this.fixed === 'left') {
|
|
@@ -114,6 +134,34 @@ export default {
|
|
|
this.store.commit('toggleAllSelection');
|
|
|
},
|
|
|
|
|
|
+ handleFilterClick(event, column) {
|
|
|
+ event.stopPropagation();
|
|
|
+ const target = event.target;
|
|
|
+ const cell = target.parentNode;
|
|
|
+ const table = this.$parent;
|
|
|
+
|
|
|
+ let filterPanel = this.filterPanels[column.id];
|
|
|
+
|
|
|
+ if (filterPanel && column.filterOpened) {
|
|
|
+ filterPanel.showPopper = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!filterPanel) {
|
|
|
+ filterPanel = new Vue(FilterPanel);
|
|
|
+ this.filterPanels[column.id] = filterPanel;
|
|
|
+
|
|
|
+ filterPanel.table = table;
|
|
|
+ filterPanel.cell = cell;
|
|
|
+ filterPanel.column = column;
|
|
|
+ filterPanel.$mount(document.createElement('div'));
|
|
|
+ }
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ filterPanel.showPopper = true;
|
|
|
+ }, 16);
|
|
|
+ },
|
|
|
+
|
|
|
handleMouseDown(event, column) {
|
|
|
if (this.draggingColumn && this.border) {
|
|
|
this.dragging = true;
|
|
@@ -180,7 +228,10 @@ export default {
|
|
|
},
|
|
|
|
|
|
handleMouseMove(event, column) {
|
|
|
- const target = event.target;
|
|
|
+ let target = event.target;
|
|
|
+ while (target && target.tagName !== 'TH') {
|
|
|
+ target = target.parentNode;
|
|
|
+ }
|
|
|
|
|
|
if (!column || !column.resizable) return;
|
|
|
|
|
@@ -194,7 +245,6 @@ export default {
|
|
|
} else if (!this.dragging) {
|
|
|
bodyStyle.cursor = '';
|
|
|
this.draggingColumn = null;
|
|
|
- if (column.sortable) bodyStyle.cursor = 'pointer';
|
|
|
}
|
|
|
}
|
|
|
},
|