mirror of https://github.com/ElemeFE/element
Merge pull request #1016 from furybean/table-row-key
Table: render rows with row-key.pull/1008/head
commit
bcbee7b472
|
@ -1,4 +1,4 @@
|
||||||
import { getValueByPath, getCell, getColumnByCell } from './util';
|
import { getValueByPath, getCell, getColumnByCell, getRowIdentity } from './util';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
@ -31,6 +31,7 @@ export default {
|
||||||
{
|
{
|
||||||
this._l(this.data, (row, $index) =>
|
this._l(this.data, (row, $index) =>
|
||||||
<tr
|
<tr
|
||||||
|
key={ this.$parent.rowKey ? this.getKeyOfRow(row, $index) : $index }
|
||||||
on-click={ ($event) => this.handleClick($event, row) }
|
on-click={ ($event) => this.handleClick($event, row) }
|
||||||
on-mouseenter={ _ => this.handleMouseEnter($index) }
|
on-mouseenter={ _ => this.handleMouseEnter($index) }
|
||||||
on-mouseleave={ _ => this.handleMouseLeave() }
|
on-mouseleave={ _ => this.handleMouseLeave() }
|
||||||
|
@ -118,6 +119,14 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
getKeyOfRow(row, index) {
|
||||||
|
const rowKey = this.$parent.rowKey;
|
||||||
|
if (rowKey) {
|
||||||
|
return getRowIdentity(row, rowKey);
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
},
|
||||||
|
|
||||||
isCellHidden(index) {
|
isCellHidden(index) {
|
||||||
if (this.fixed === true || this.fixed === 'left') {
|
if (this.fixed === true || this.fixed === 'left') {
|
||||||
return index >= this.leftFixedCount;
|
return index >= this.leftFixedCount;
|
||||||
|
|
|
@ -1,15 +1,6 @@
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import debounce from 'throttle-debounce/debounce';
|
import debounce from 'throttle-debounce/debounce';
|
||||||
import { orderBy, getColumnById } from './util';
|
import { orderBy, getColumnById, getRowIdentity } from './util';
|
||||||
|
|
||||||
const getRowIdentity = (row, rowKey) => {
|
|
||||||
if (!row) throw new Error('row is required when get row identity');
|
|
||||||
if (typeof rowKey === 'string') {
|
|
||||||
return row[rowKey];
|
|
||||||
} else if (typeof rowKey === 'function') {
|
|
||||||
return rowKey.call(null, row);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const sortData = (data, states) => {
|
const sortData = (data, states) => {
|
||||||
const sortingColumn = states.sortingColumn;
|
const sortingColumn = states.sortingColumn;
|
||||||
|
|
|
@ -106,3 +106,12 @@ export const mousewheel = function(element, callback) {
|
||||||
element.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', callback);
|
element.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', callback);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getRowIdentity = (row, rowKey) => {
|
||||||
|
if (!row) throw new Error('row is required when get row identity');
|
||||||
|
if (typeof rowKey === 'string') {
|
||||||
|
return row[rowKey];
|
||||||
|
} else if (typeof rowKey === 'function') {
|
||||||
|
return rowKey.call(null, row);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue