2017-06-29 06:43:28 +00:00
|
|
|
import { hasClass, addClass, removeClass } from 'element-ui/src/utils/dom';
|
2016-10-25 13:35:41 +00:00
|
|
|
import ElCheckbox from 'element-ui/packages/checkbox';
|
|
|
|
import ElTag from 'element-ui/packages/tag';
|
2016-10-27 13:45:21 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import FilterPanel from './filter-panel.vue';
|
2016-08-16 08:07:18 +00:00
|
|
|
|
2016-11-23 12:32:23 +00:00
|
|
|
const getAllColumns = (columns) => {
|
|
|
|
const result = [];
|
|
|
|
columns.forEach((column) => {
|
|
|
|
if (column.children) {
|
|
|
|
result.push(column);
|
|
|
|
result.push.apply(result, getAllColumns(column.children));
|
|
|
|
} else {
|
|
|
|
result.push(column);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertToRows = (originColumns) => {
|
|
|
|
let maxLevel = 1;
|
|
|
|
const traverse = (column, parent) => {
|
|
|
|
if (parent) {
|
|
|
|
column.level = parent.level + 1;
|
|
|
|
if (maxLevel < column.level) {
|
|
|
|
maxLevel = column.level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (column.children) {
|
|
|
|
let colSpan = 0;
|
|
|
|
column.children.forEach((subColumn) => {
|
2017-02-16 06:48:52 +00:00
|
|
|
traverse(subColumn, column);
|
2016-11-23 12:32:23 +00:00
|
|
|
colSpan += subColumn.colSpan;
|
|
|
|
});
|
|
|
|
column.colSpan = colSpan;
|
|
|
|
} else {
|
|
|
|
column.colSpan = 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
originColumns.forEach((column) => {
|
|
|
|
column.level = 1;
|
|
|
|
traverse(column);
|
|
|
|
});
|
|
|
|
|
|
|
|
const rows = [];
|
|
|
|
for (let i = 0; i < maxLevel; i++) {
|
|
|
|
rows.push([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const allColumns = getAllColumns(originColumns);
|
|
|
|
|
|
|
|
allColumns.forEach((column) => {
|
|
|
|
if (!column.children) {
|
|
|
|
column.rowSpan = maxLevel - column.level + 1;
|
|
|
|
} else {
|
|
|
|
column.rowSpan = 1;
|
|
|
|
}
|
|
|
|
rows[column.level - 1].push(column);
|
|
|
|
});
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
};
|
|
|
|
|
2016-08-16 08:07:18 +00:00
|
|
|
export default {
|
2016-12-31 15:33:51 +00:00
|
|
|
name: 'ElTableHeader',
|
2016-08-16 08:07:18 +00:00
|
|
|
|
|
|
|
render(h) {
|
2016-11-23 12:32:23 +00:00
|
|
|
const originColumns = this.store.states.originColumns;
|
|
|
|
const columnRows = convertToRows(originColumns, this.columns);
|
2017-09-22 06:30:44 +00:00
|
|
|
// 是否拥有多级表头
|
|
|
|
const isGroup = columnRows.length > 1;
|
|
|
|
if (isGroup) this.$parent.isGroup = true;
|
2016-11-23 12:32:23 +00:00
|
|
|
|
2016-08-16 08:07:18 +00:00
|
|
|
return (
|
|
|
|
<table
|
|
|
|
class="el-table__header"
|
|
|
|
cellspacing="0"
|
|
|
|
cellpadding="0"
|
|
|
|
border="0">
|
2017-01-05 02:42:31 +00:00
|
|
|
<colgroup>
|
|
|
|
{
|
|
|
|
this._l(this.columns, column =>
|
|
|
|
<col
|
|
|
|
name={ column.id }
|
|
|
|
width={ column.realWidth || column.width }
|
|
|
|
/>)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
!this.fixed && this.layout.gutterWidth
|
|
|
|
? <col name="gutter" width={ this.layout.scrollY ? this.layout.gutterWidth : '' }></col>
|
|
|
|
: ''
|
|
|
|
}
|
|
|
|
</colgroup>
|
2017-09-22 06:30:44 +00:00
|
|
|
<thead class={ [{ 'is-group': isGroup, 'has-gutter': this.hasGutter }] }>
|
2016-11-23 12:32:23 +00:00
|
|
|
{
|
2016-12-02 09:33:03 +00:00
|
|
|
this._l(columnRows, (columns, rowIndex) =>
|
2017-10-25 07:35:12 +00:00
|
|
|
<tr
|
|
|
|
style={ this.getHeaderRowStyle(rowIndex) }
|
|
|
|
class={ this.getHeaderRowClass(rowIndex) }
|
|
|
|
>
|
2018-01-05 08:53:02 +00:00
|
|
|
{
|
|
|
|
this._l(columns, (column, cellIndex) =>
|
|
|
|
<th
|
|
|
|
colspan={ column.colSpan }
|
|
|
|
rowspan={ column.rowSpan }
|
|
|
|
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) }
|
|
|
|
style={ this.getHeaderCellStyle(rowIndex, cellIndex, columns, column) }
|
|
|
|
class={ this.getHeaderCellClass(rowIndex, cellIndex, columns, column) }>
|
|
|
|
<div class={ ['cell', column.filteredValue && column.filteredValue.length > 0 ? 'highlight' : '', column.labelClassName] }>
|
|
|
|
{
|
|
|
|
column.renderHeader
|
|
|
|
? column.renderHeader.call(this._renderProxy, h, { column, $index: cellIndex, store: this.store, _self: this.$parent.$vnode.context })
|
|
|
|
: column.label
|
|
|
|
}
|
|
|
|
{
|
|
|
|
column.sortable
|
|
|
|
? <span class="caret-wrapper" on-click={ ($event) => this.handleSortClick($event, column) }>
|
|
|
|
<i class="sort-caret ascending" on-click={ ($event) => this.handleSortClick($event, column, 'ascending') }>
|
|
|
|
</i>
|
|
|
|
<i class="sort-caret descending" on-click={ ($event) => this.handleSortClick($event, column, '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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
this.hasGutter
|
2018-01-18 09:17:40 +00:00
|
|
|
? <th class="gutter" style={{
|
|
|
|
width: this.layout.scrollY ? this.layout.gutterWidth + 'px' : '0',
|
|
|
|
display: this.layout.scrollY ? '' : 'none'
|
|
|
|
}}></th>
|
2018-01-05 08:53:02 +00:00
|
|
|
: ''
|
|
|
|
}
|
2017-01-03 08:27:42 +00:00
|
|
|
</tr>
|
2016-11-23 12:32:23 +00:00
|
|
|
)
|
|
|
|
}
|
2016-10-12 11:18:34 +00:00
|
|
|
</thead>
|
2016-08-16 08:07:18 +00:00
|
|
|
</table>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
2016-10-12 11:18:34 +00:00
|
|
|
fixed: String,
|
|
|
|
store: {
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
layout: {
|
|
|
|
required: true
|
2016-08-16 08:07:18 +00:00
|
|
|
},
|
2017-01-03 12:08:43 +00:00
|
|
|
border: Boolean,
|
2017-01-14 06:51:44 +00:00
|
|
|
defaultSort: {
|
|
|
|
type: Object,
|
|
|
|
default() {
|
|
|
|
return {
|
|
|
|
prop: '',
|
|
|
|
order: ''
|
|
|
|
};
|
|
|
|
}
|
2017-01-05 04:38:39 +00:00
|
|
|
}
|
2016-08-16 08:07:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
ElCheckbox,
|
|
|
|
ElTag
|
|
|
|
},
|
|
|
|
|
2016-10-12 11:18:34 +00:00
|
|
|
computed: {
|
2017-10-25 07:35:12 +00:00
|
|
|
table() {
|
|
|
|
return this.$parent;
|
|
|
|
},
|
|
|
|
|
2016-10-12 11:18:34 +00:00
|
|
|
isAllSelected() {
|
|
|
|
return this.store.states.isAllSelected;
|
|
|
|
},
|
|
|
|
|
2016-10-21 15:13:34 +00:00
|
|
|
columnsCount() {
|
|
|
|
return this.store.states.columns.length;
|
|
|
|
},
|
|
|
|
|
|
|
|
leftFixedCount() {
|
|
|
|
return this.store.states.fixedColumns.length;
|
|
|
|
},
|
|
|
|
|
|
|
|
rightFixedCount() {
|
|
|
|
return this.store.states.rightFixedColumns.length;
|
|
|
|
},
|
|
|
|
|
2017-10-18 03:01:32 +00:00
|
|
|
leftFixedLeafCount() {
|
|
|
|
return this.store.states.fixedLeafColumnsLength;
|
|
|
|
},
|
|
|
|
|
|
|
|
rightFixedLeafCount() {
|
|
|
|
return this.store.states.rightFixedLeafColumnsLength;
|
|
|
|
},
|
|
|
|
|
2016-10-12 11:18:34 +00:00
|
|
|
columns() {
|
|
|
|
return this.store.states.columns;
|
2017-09-22 06:30:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hasGutter() {
|
|
|
|
return !this.fixed && this.layout.gutterWidth;
|
2016-10-12 11:18:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-10-27 13:45:21 +00:00
|
|
|
created() {
|
|
|
|
this.filterPanels = {};
|
|
|
|
},
|
|
|
|
|
2017-01-03 12:08:43 +00:00
|
|
|
mounted() {
|
2017-01-14 06:51:44 +00:00
|
|
|
if (this.defaultSort.prop) {
|
2017-01-09 15:04:06 +00:00
|
|
|
const states = this.store.states;
|
2017-01-14 06:51:44 +00:00
|
|
|
states.sortProp = this.defaultSort.prop;
|
|
|
|
states.sortOrder = this.defaultSort.order || 'ascending';
|
2017-01-09 15:04:06 +00:00
|
|
|
this.$nextTick(_ => {
|
|
|
|
for (let i = 0, length = this.columns.length; i < length; i++) {
|
2017-01-11 01:48:09 +00:00
|
|
|
let column = this.columns[i];
|
2017-01-14 06:51:44 +00:00
|
|
|
if (column.property === states.sortProp) {
|
|
|
|
column.order = states.sortOrder;
|
2017-01-11 01:48:09 +00:00
|
|
|
states.sortingColumn = column;
|
2017-01-09 15:04:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-03 12:08:43 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 01:48:09 +00:00
|
|
|
if (states.sortingColumn) {
|
|
|
|
this.store.commit('changeSortCondition');
|
|
|
|
}
|
2017-01-09 15:04:06 +00:00
|
|
|
});
|
|
|
|
}
|
2017-01-03 12:08:43 +00:00
|
|
|
},
|
|
|
|
|
2016-10-27 13:45:21 +00:00
|
|
|
beforeDestroy() {
|
|
|
|
const panels = this.filterPanels;
|
|
|
|
for (let prop in panels) {
|
|
|
|
if (panels.hasOwnProperty(prop) && panels[prop]) {
|
|
|
|
panels[prop].$destroy(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-08-16 08:07:18 +00:00
|
|
|
methods: {
|
2017-02-16 06:48:52 +00:00
|
|
|
isCellHidden(index, columns) {
|
2017-10-18 03:01:32 +00:00
|
|
|
let start = 0;
|
|
|
|
for (let i = 0; i < index; i++) {
|
|
|
|
start += columns[i].colSpan;
|
|
|
|
}
|
|
|
|
const after = start + columns[index].colSpan - 1;
|
2016-10-21 15:13:34 +00:00
|
|
|
if (this.fixed === true || this.fixed === 'left') {
|
2017-10-18 03:01:32 +00:00
|
|
|
return after >= this.leftFixedLeafCount;
|
2016-10-21 15:13:34 +00:00
|
|
|
} else if (this.fixed === 'right') {
|
2017-10-18 03:01:32 +00:00
|
|
|
return start < this.columnsCount - this.rightFixedLeafCount;
|
2016-10-21 15:13:34 +00:00
|
|
|
} else {
|
2017-10-18 03:01:32 +00:00
|
|
|
return (after < this.leftFixedLeafCount) || (start >= this.columnsCount - this.rightFixedLeafCount);
|
2016-10-21 15:13:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-25 07:35:12 +00:00
|
|
|
getHeaderRowStyle(rowIndex) {
|
|
|
|
const headerRowStyle = this.table.headerRowStyle;
|
|
|
|
if (typeof headerRowStyle === 'function') {
|
|
|
|
return headerRowStyle.call(null, { rowIndex });
|
|
|
|
}
|
|
|
|
return headerRowStyle;
|
|
|
|
},
|
|
|
|
|
|
|
|
getHeaderRowClass(rowIndex) {
|
|
|
|
const classes = [];
|
|
|
|
|
|
|
|
const headerRowClassName = this.table.headerRowClassName;
|
|
|
|
if (typeof headerRowClassName === 'string') {
|
|
|
|
classes.push(headerRowClassName);
|
|
|
|
} else if (typeof headerRowClassName === 'function') {
|
|
|
|
classes.push(headerRowClassName.call(null, { rowIndex }));
|
|
|
|
}
|
|
|
|
|
|
|
|
return classes.join(' ');
|
|
|
|
},
|
|
|
|
|
|
|
|
getHeaderCellStyle(rowIndex, columnIndex, row, column) {
|
|
|
|
const headerCellStyle = this.table.headerCellStyle;
|
|
|
|
if (typeof headerCellStyle === 'function') {
|
|
|
|
return headerCellStyle.call(null, {
|
|
|
|
rowIndex,
|
|
|
|
columnIndex,
|
|
|
|
row,
|
|
|
|
column
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return headerCellStyle;
|
|
|
|
},
|
|
|
|
|
|
|
|
getHeaderCellClass(rowIndex, columnIndex, row, column) {
|
|
|
|
const classes = [column.id, column.order, column.headerAlign, column.className, column.labelClassName];
|
|
|
|
|
|
|
|
if (rowIndex === 0 && this.isCellHidden(columnIndex, row)) {
|
|
|
|
classes.push('is-hidden');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!column.children) {
|
|
|
|
classes.push('is-leaf');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (column.sortable) {
|
|
|
|
classes.push('is-sortable');
|
|
|
|
}
|
|
|
|
|
|
|
|
const headerCellClassName = this.table.headerCellClassName;
|
|
|
|
if (typeof headerCellClassName === 'string') {
|
|
|
|
classes.push(headerCellClassName);
|
|
|
|
} else if (typeof headerCellClassName === 'function') {
|
|
|
|
classes.push(headerCellClassName.call(null, {
|
|
|
|
rowIndex,
|
|
|
|
columnIndex,
|
|
|
|
row,
|
|
|
|
column
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return classes.join(' ');
|
|
|
|
},
|
|
|
|
|
2016-10-12 11:18:34 +00:00
|
|
|
toggleAllSelection() {
|
|
|
|
this.store.commit('toggleAllSelection');
|
2016-08-16 08:07:18 +00:00
|
|
|
},
|
|
|
|
|
2016-10-27 13:45:21 +00:00
|
|
|
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;
|
2017-04-27 06:08:59 +00:00
|
|
|
if (column.filterPlacement) {
|
2017-04-28 03:42:09 +00:00
|
|
|
filterPanel.placement = column.filterPlacement;
|
2017-04-27 06:08:59 +00:00
|
|
|
}
|
2016-10-27 13:45:21 +00:00
|
|
|
filterPanel.table = table;
|
|
|
|
filterPanel.cell = cell;
|
|
|
|
filterPanel.column = column;
|
2016-12-26 02:45:20 +00:00
|
|
|
!this.$isServer && filterPanel.$mount(document.createElement('div'));
|
2016-10-27 13:45:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
filterPanel.showPopper = true;
|
|
|
|
}, 16);
|
|
|
|
},
|
|
|
|
|
2017-01-14 09:18:12 +00:00
|
|
|
handleHeaderClick(event, column) {
|
|
|
|
if (!column.filters && column.sortable) {
|
|
|
|
this.handleSortClick(event, column);
|
|
|
|
} else if (column.filters && !column.sortable) {
|
|
|
|
this.handleFilterClick(event, column);
|
|
|
|
}
|
|
|
|
|
2016-11-18 07:59:00 +00:00
|
|
|
this.$parent.$emit('header-click', column, event);
|
|
|
|
},
|
|
|
|
|
2016-08-16 08:07:18 +00:00
|
|
|
handleMouseDown(event, column) {
|
2016-12-26 02:45:20 +00:00
|
|
|
if (this.$isServer) return;
|
2016-11-23 12:32:23 +00:00
|
|
|
if (column.children && column.children.length > 0) return;
|
2016-10-27 15:25:03 +00:00
|
|
|
/* istanbul ignore if */
|
2016-08-16 08:07:18 +00:00
|
|
|
if (this.draggingColumn && this.border) {
|
|
|
|
this.dragging = true;
|
|
|
|
|
|
|
|
this.$parent.resizeProxyVisible = true;
|
|
|
|
|
2017-02-23 05:09:25 +00:00
|
|
|
const table = this.$parent;
|
|
|
|
const tableEl = table.$el;
|
2016-10-12 11:18:34 +00:00
|
|
|
const tableLeft = tableEl.getBoundingClientRect().left;
|
2016-08-16 08:07:18 +00:00
|
|
|
const columnEl = this.$el.querySelector(`th.${column.id}`);
|
|
|
|
const columnRect = columnEl.getBoundingClientRect();
|
2016-10-12 11:18:34 +00:00
|
|
|
const minLeft = columnRect.left - tableLeft + 30;
|
2016-08-16 08:07:18 +00:00
|
|
|
|
2017-06-29 06:43:28 +00:00
|
|
|
addClass(columnEl, 'noclick');
|
2016-08-16 08:07:18 +00:00
|
|
|
|
|
|
|
this.dragState = {
|
|
|
|
startMouseLeft: event.clientX,
|
2016-10-12 11:18:34 +00:00
|
|
|
startLeft: columnRect.right - tableLeft,
|
|
|
|
startColumnLeft: columnRect.left - tableLeft,
|
|
|
|
tableLeft
|
2016-08-16 08:07:18 +00:00
|
|
|
};
|
|
|
|
|
2017-02-23 05:09:25 +00:00
|
|
|
const resizeProxy = table.$refs.resizeProxy;
|
2016-08-16 08:07:18 +00:00
|
|
|
resizeProxy.style.left = this.dragState.startLeft + 'px';
|
|
|
|
|
|
|
|
document.onselectstart = function() { return false; };
|
|
|
|
document.ondragstart = function() { return false; };
|
|
|
|
|
2016-10-12 11:18:34 +00:00
|
|
|
const handleMouseMove = (event) => {
|
2016-08-16 08:07:18 +00:00
|
|
|
const deltaLeft = event.clientX - this.dragState.startMouseLeft;
|
|
|
|
const proxyLeft = this.dragState.startLeft + deltaLeft;
|
|
|
|
|
|
|
|
resizeProxy.style.left = Math.max(minLeft, proxyLeft) + 'px';
|
|
|
|
};
|
|
|
|
|
2016-10-12 11:18:34 +00:00
|
|
|
const handleMouseUp = () => {
|
2016-08-16 08:07:18 +00:00
|
|
|
if (this.dragging) {
|
2017-02-23 05:09:25 +00:00
|
|
|
const {
|
|
|
|
startColumnLeft,
|
|
|
|
startLeft
|
|
|
|
} = this.dragState;
|
2016-08-16 08:07:18 +00:00
|
|
|
const finalLeft = parseInt(resizeProxy.style.left, 10);
|
2017-02-23 05:09:25 +00:00
|
|
|
const columnWidth = finalLeft - startColumnLeft;
|
2016-08-16 08:07:18 +00:00
|
|
|
column.width = column.realWidth = columnWidth;
|
2017-02-23 05:09:25 +00:00
|
|
|
table.$emit('header-dragend', column.width, startLeft - startColumnLeft, column, event);
|
2016-08-16 08:07:18 +00:00
|
|
|
|
2016-10-12 11:18:34 +00:00
|
|
|
this.store.scheduleLayout();
|
2016-08-16 08:07:18 +00:00
|
|
|
|
|
|
|
document.body.style.cursor = '';
|
|
|
|
this.dragging = false;
|
|
|
|
this.draggingColumn = null;
|
|
|
|
this.dragState = {};
|
|
|
|
|
2017-02-23 05:09:25 +00:00
|
|
|
table.resizeProxyVisible = false;
|
2016-08-16 08:07:18 +00:00
|
|
|
}
|
|
|
|
|
2016-10-12 11:18:34 +00:00
|
|
|
document.removeEventListener('mousemove', handleMouseMove);
|
|
|
|
document.removeEventListener('mouseup', handleMouseUp);
|
2016-08-16 08:07:18 +00:00
|
|
|
document.onselectstart = null;
|
|
|
|
document.ondragstart = null;
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2017-06-29 06:43:28 +00:00
|
|
|
removeClass(columnEl, 'noclick');
|
2016-08-16 08:07:18 +00:00
|
|
|
}, 0);
|
|
|
|
};
|
|
|
|
|
2016-10-12 11:18:34 +00:00
|
|
|
document.addEventListener('mousemove', handleMouseMove);
|
|
|
|
document.addEventListener('mouseup', handleMouseUp);
|
2016-08-16 08:07:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleMouseMove(event, column) {
|
2016-11-23 12:32:23 +00:00
|
|
|
if (column.children && column.children.length > 0) return;
|
2016-10-27 13:45:21 +00:00
|
|
|
let target = event.target;
|
|
|
|
while (target && target.tagName !== 'TH') {
|
|
|
|
target = target.parentNode;
|
|
|
|
}
|
2016-08-16 08:07:18 +00:00
|
|
|
|
|
|
|
if (!column || !column.resizable) return;
|
|
|
|
|
|
|
|
if (!this.dragging && this.border) {
|
|
|
|
let rect = target.getBoundingClientRect();
|
|
|
|
|
2016-11-18 07:59:00 +00:00
|
|
|
const bodyStyle = document.body.style;
|
2016-08-16 08:07:18 +00:00
|
|
|
if (rect.width > 12 && rect.right - event.pageX < 8) {
|
2016-10-12 11:18:34 +00:00
|
|
|
bodyStyle.cursor = 'col-resize';
|
2017-10-09 12:07:10 +00:00
|
|
|
if (hasClass(target, 'is-sortable')) {
|
|
|
|
target.style.cursor = 'col-resize';
|
|
|
|
}
|
2016-08-16 08:07:18 +00:00
|
|
|
this.draggingColumn = column;
|
|
|
|
} else if (!this.dragging) {
|
2016-10-12 11:18:34 +00:00
|
|
|
bodyStyle.cursor = '';
|
2017-10-09 12:07:10 +00:00
|
|
|
if (hasClass(target, 'is-sortable')) {
|
|
|
|
target.style.cursor = 'pointer';
|
|
|
|
}
|
2016-08-16 08:07:18 +00:00
|
|
|
this.draggingColumn = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleMouseOut() {
|
2016-12-26 02:45:20 +00:00
|
|
|
if (this.$isServer) return;
|
2016-08-16 08:07:18 +00:00
|
|
|
document.body.style.cursor = '';
|
|
|
|
},
|
|
|
|
|
2017-01-18 06:14:34 +00:00
|
|
|
toggleOrder(order) {
|
|
|
|
return !order ? 'ascending' : order === 'ascending' ? 'descending' : null;
|
2017-01-03 12:08:43 +00:00
|
|
|
},
|
|
|
|
|
2017-03-09 04:19:24 +00:00
|
|
|
handleSortClick(event, column, givenOrder) {
|
2017-01-14 09:18:12 +00:00
|
|
|
event.stopPropagation();
|
2017-03-09 04:19:24 +00:00
|
|
|
let order = givenOrder || this.toggleOrder(column.order);
|
2017-01-03 12:08:43 +00:00
|
|
|
|
2016-08-16 08:07:18 +00:00
|
|
|
let target = event.target;
|
|
|
|
while (target && target.tagName !== 'TH') {
|
|
|
|
target = target.parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target && target.tagName === 'TH') {
|
2017-06-29 06:43:28 +00:00
|
|
|
if (hasClass(target, 'noclick')) {
|
|
|
|
removeClass(target, 'noclick');
|
2016-08-16 08:07:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!column.sortable) return;
|
|
|
|
|
2016-10-27 17:24:13 +00:00
|
|
|
const states = this.store.states;
|
|
|
|
let sortProp = states.sortProp;
|
|
|
|
let sortOrder;
|
|
|
|
const sortingColumn = states.sortingColumn;
|
2016-08-16 08:07:18 +00:00
|
|
|
|
2018-01-07 04:15:52 +00:00
|
|
|
if (sortingColumn !== column || (sortingColumn === column && sortingColumn.order === null)) {
|
2016-10-27 17:24:13 +00:00
|
|
|
if (sortingColumn) {
|
|
|
|
sortingColumn.order = null;
|
2016-08-16 08:07:18 +00:00
|
|
|
}
|
2016-10-27 17:24:13 +00:00
|
|
|
states.sortingColumn = column;
|
|
|
|
sortProp = column.property;
|
2016-08-16 08:07:18 +00:00
|
|
|
}
|
|
|
|
|
2017-01-18 06:14:34 +00:00
|
|
|
if (!order) {
|
2016-10-27 17:24:13 +00:00
|
|
|
sortOrder = column.order = null;
|
|
|
|
states.sortingColumn = null;
|
|
|
|
sortProp = null;
|
2016-12-23 04:11:17 +00:00
|
|
|
} else {
|
|
|
|
sortOrder = column.order = order;
|
2016-08-16 08:07:18 +00:00
|
|
|
}
|
2016-12-23 04:11:17 +00:00
|
|
|
|
2016-10-27 17:24:13 +00:00
|
|
|
states.sortProp = sortProp;
|
|
|
|
states.sortOrder = sortOrder;
|
2016-08-16 08:07:18 +00:00
|
|
|
|
2016-10-12 11:18:34 +00:00
|
|
|
this.store.commit('changeSortCondition');
|
2016-08-16 08:07:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
draggingColumn: null,
|
|
|
|
dragging: false,
|
2016-10-12 11:18:34 +00:00
|
|
|
dragState: {}
|
2016-08-16 08:07:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|