From 69d5646833f87d98e38a628ae8b506bd61464e32 Mon Sep 17 00:00:00 2001 From: furybean Date: Sun, 13 Nov 2016 02:57:08 +0800 Subject: [PATCH] Table: render rows with row-key. --- packages/table/src/table-body.js | 11 ++++++++++- packages/table/src/table-store.js | 11 +---------- packages/table/src/util.js | 9 +++++++++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/table/src/table-body.js b/packages/table/src/table-body.js index ccf342160..6110cad1a 100644 --- a/packages/table/src/table-body.js +++ b/packages/table/src/table-body.js @@ -1,4 +1,4 @@ -import { getValueByPath, getCell, getColumnByCell } from './util'; +import { getValueByPath, getCell, getColumnByCell, getRowIdentity } from './util'; export default { props: { @@ -31,6 +31,7 @@ export default { { this._l(this.data, (row, $index) => this.handleClick($event, row) } on-mouseenter={ _ => this.handleMouseEnter($index) } on-mouseleave={ _ => this.handleMouseLeave() } @@ -118,6 +119,14 @@ export default { }, methods: { + getKeyOfRow(row, index) { + const rowKey = this.$parent.rowKey; + if (rowKey) { + return getRowIdentity(row, rowKey); + } + return index; + }, + isCellHidden(index) { if (this.fixed === true || this.fixed === 'left') { return index >= this.leftFixedCount; diff --git a/packages/table/src/table-store.js b/packages/table/src/table-store.js index 3bfbdd970..b7004de0b 100644 --- a/packages/table/src/table-store.js +++ b/packages/table/src/table-store.js @@ -1,15 +1,6 @@ import Vue from 'vue'; import debounce from 'throttle-debounce/debounce'; -import { orderBy, getColumnById } 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); - } -}; +import { orderBy, getColumnById, getRowIdentity } from './util'; const sortData = (data, states) => { const sortingColumn = states.sortingColumn; diff --git a/packages/table/src/util.js b/packages/table/src/util.js index 25c10f2de..eb6ae6dfa 100644 --- a/packages/table/src/util.js +++ b/packages/table/src/util.js @@ -106,3 +106,12 @@ export const mousewheel = function(element, 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); + } +};