forked from ElemeFE/element
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ElemeFE#68 from eleme/feat/next-table
Feat/next table
- Loading branch information
Showing
11 changed files
with
736 additions
and
673 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
} | ||
}, | ||
ready() { | ||
mounted() { | ||
console.log('popup ready'); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
const getColumnById = function(grid, columnId) { | ||
let column = null; | ||
grid.columns.forEach(function(item) { | ||
if (item.id === columnId) { | ||
column = item; | ||
} | ||
}); | ||
return column; | ||
}; | ||
|
||
const getColumnByCell = function(grid, cell) { | ||
const matches = (cell.className || '').match(/grid_[^\s]+/gm); | ||
if (matches) { | ||
return getColumnById(grid, matches[0]); | ||
} | ||
return null; | ||
}; | ||
|
||
import { getValueByPath, getCell, orderBy, getChild } from './util'; | ||
|
||
export default { | ||
props: { | ||
columns: {}, | ||
data: {}, | ||
fixed: {}, | ||
selection: { | ||
default() { | ||
return []; | ||
} | ||
} | ||
}, | ||
|
||
render(h) { | ||
return ( | ||
<table | ||
class="el-table__body" | ||
cellspacing="0" | ||
cellpadding="0" | ||
border="0"> | ||
<tbody> | ||
{ | ||
this._l(this.data, (row, $index) => | ||
<tr | ||
on-click={ ($event) => this.handleClick($event, row) } | ||
on-mouseenter={ _ => this.handleMouseEnter($index) } | ||
class={{ | ||
'current-row': row === this.$parent.$parent.selected, | ||
'hover': this.$parent.$parent.hoverRowIndex === $index, | ||
'positive-row': row.$positive, | ||
'info-row': row.$info, | ||
'warning-row': row.$warning, | ||
'negative-row': row.$negative | ||
}}> | ||
{ | ||
this._l(this.columns, (column) => | ||
<td | ||
class={ column.id } | ||
on-mouseenter={ ($event) => this.handleCellMouseEnter($event, row) } | ||
on-mouseleave={ this.handleCellMouseLeave }> | ||
{ | ||
column.template | ||
? column.template.call(this._renderProxy, h, { row, column, $index }) | ||
: <div class="cell">{ this.$getPropertyText(row, column.property, column.id) }</div> | ||
} | ||
</td> | ||
).concat(this.fixed ? <td class="gutter" /> : '') | ||
} | ||
</tr> | ||
) | ||
} | ||
</tbody> | ||
</table> | ||
); | ||
}, | ||
|
||
data() { | ||
return { | ||
tooltipDisabled: true | ||
}; | ||
}, | ||
|
||
filters: { | ||
orderBy | ||
}, | ||
|
||
methods: { | ||
handleCellMouseEnter(event, row) { | ||
let grid = this.$parent; | ||
const cell = getCell(event); | ||
|
||
if (cell) { | ||
const column = getColumnByCell(grid, cell); | ||
const hoverState = grid.hoverState = { cell: cell, column: column, row: row }; | ||
grid.$emit('cellmouseenter', hoverState.row, hoverState.column, hoverState.cell, event); | ||
} | ||
|
||
// 判断是否text-overflow, 如果是就显示tooltip | ||
const cellChild = getChild(event); | ||
|
||
if (cellChild.scrollWidth > cellChild.offsetWidth) { | ||
this.tooltipDisabled = false; | ||
} else { | ||
this.tooltipDisabled = true; | ||
} | ||
}, | ||
|
||
handleCellMouseLeave(event) { | ||
let grid = this.$parent; | ||
const cell = getCell(event); | ||
|
||
if (cell) { | ||
const oldHoverState = grid.hoverState; | ||
grid.$emit('cellmouseleave', oldHoverState.row, oldHoverState.column, oldHoverState.cell, event); | ||
} | ||
}, | ||
|
||
handleMouseEnter(index) { | ||
this.$parent.hoverRowIndex = index; | ||
}, | ||
|
||
handleClick(event, row) { | ||
let grid = this.$parent; | ||
const cell = getCell(event); | ||
|
||
if (cell) { | ||
const column = getColumnByCell(grid, cell); | ||
if (column) { | ||
grid.$emit('cellclick', row, column, cell, event); | ||
} | ||
} | ||
|
||
if (grid.selectionMode === 'single') { | ||
grid.selected = row; | ||
grid.$emit('selectionchange', row); | ||
} | ||
|
||
grid.$emit('rowclick', row, event); | ||
}, | ||
|
||
handleCreate(vm) { | ||
document.body.appendChild(vm.$refs.popper); | ||
vm.updatePopper(); | ||
}, | ||
|
||
$getPropertyText(row, property, columnId) { | ||
let grid = this.$parent; | ||
const column = getColumnById(grid, columnId); | ||
if (column && column.formatter) { | ||
return column.formatter(row, column); | ||
} | ||
|
||
return getValueByPath(row, property); | ||
} | ||
} | ||
}; |
Oops, something went wrong.