fast-table
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -55,3 +55,3 @@ 'use strict'; | ||
}); | ||
}, _this.renderRows = function (datas) { | ||
}, _this.renderRows = function () { | ||
var rows = []; | ||
@@ -61,4 +61,4 @@ var _this$props = _this.props, | ||
fixed = _this$props.fixed, | ||
renderStart = _this$props.renderStart, | ||
renderEnd = _this$props.renderEnd; | ||
showData = _this$props.showData, | ||
tops = _this$props.tops; | ||
@@ -74,30 +74,29 @@ var table = _this.context.table; | ||
var columnManager = table.columnManager; | ||
datas.forEach(function (record, i) { | ||
if (i >= renderStart && i <= renderEnd) { | ||
var leafColumns = void 0; | ||
if (fixed === 'left') { | ||
leafColumns = columnManager.leftLeafColumns(); | ||
} else if (fixed === 'right') { | ||
leafColumns = columnManager.rightLeafColumns(); | ||
} else { | ||
leafColumns = columnManager.leafColumns(); | ||
} | ||
var className = typeof rowClassName === 'function' ? rowClassName(record, i) : rowClassName; | ||
var key = getRowKey(record, i); | ||
var props = { | ||
key: key, | ||
record: record, | ||
fixed: fixed, | ||
prefixCls: prefixCls, | ||
className: className, | ||
rowKey: key, | ||
index: i, | ||
columns: leafColumns, | ||
ref: rowRef(record, i), | ||
components: table.components, | ||
height: getRowHeight(record, i) * rowHeight, | ||
onHover: _this.handleRowHover | ||
}; | ||
rows.push(_react2.default.createElement(_TableRow2.default, props)); | ||
(showData || []).forEach(function (record, i) { | ||
var leafColumns = void 0; | ||
if (fixed === 'left') { | ||
leafColumns = columnManager.leftLeafColumns(); | ||
} else if (fixed === 'right') { | ||
leafColumns = columnManager.rightLeafColumns(); | ||
} else { | ||
leafColumns = columnManager.leafColumns(); | ||
} | ||
var className = typeof rowClassName === 'function' ? rowClassName(record, record.index) : rowClassName; | ||
var key = getRowKey(record, record.index); | ||
var props = { | ||
key: key, | ||
record: record, | ||
fixed: fixed, | ||
prefixCls: prefixCls, | ||
className: className, | ||
rowKey: key, | ||
index: record.index, | ||
top: tops[record.index], | ||
columns: leafColumns, | ||
ref: rowRef(record, record.index), | ||
components: table.components, | ||
height: getRowHeight(record, record.index) * rowHeight, | ||
onHover: _this.handleRowHover | ||
}; | ||
rows.push(_react2.default.createElement(_TableRow2.default, props)); | ||
}); | ||
@@ -161,6 +160,7 @@ return rows; | ||
if (hasBody) { | ||
var rows = this.renderRows(); | ||
body = _react2.default.createElement( | ||
BodyWrapper, | ||
{ className: 'tbody', style: { height: bodyHeight + (footer ? footerHeight : 0) } }, | ||
this.renderRows(table.props.dataSource), | ||
rows, | ||
this.renderEmptyText(), | ||
@@ -187,3 +187,5 @@ this.renderFooter() | ||
renderEnd = state.renderEnd, | ||
bodyHeight = state.bodyHeight; | ||
bodyHeight = state.bodyHeight, | ||
showData = state.showData, | ||
tops = state.tops; | ||
@@ -195,3 +197,5 @@ return { | ||
renderStart: renderStart, | ||
renderEnd: renderEnd | ||
renderEnd: renderEnd, | ||
showData: showData || [], | ||
tops: tops | ||
}; | ||
@@ -198,0 +202,0 @@ })(BaseTable); |
@@ -120,3 +120,4 @@ 'use strict'; | ||
value: function componentDidMount() { | ||
this.resetData(); | ||
this.showCount = this.getShowCount(); | ||
this.resetData(this.props.dataSource); | ||
this.resizeEvent = (0, _Utils.addEventListener)(window, 'resize', this.debouncedWindowResize); | ||
@@ -141,4 +142,4 @@ } | ||
value: function componentDidUpdate() { | ||
this.bodyHeight = this['bodyTable'].getBoundingClientRect().height; | ||
this.showCount = 5 + this.bodyHeight / this.props.rowHeight; | ||
var showCount = this.getShowCount(); | ||
if (this.showCount !== showCount) this.resetData(this.props.dataSource); | ||
} | ||
@@ -170,2 +171,11 @@ }, { | ||
this.getShowCount = function () { | ||
var dataSource = _this2.props.dataSource || []; | ||
_this2.bodyHeight = _this2['bodyTable'].getBoundingClientRect().height; | ||
var showCount = 5 + _this2.bodyHeight / _this2.props.rowHeight; | ||
showCount = showCount > dataSource.length ? dataSource.length : showCount; | ||
showCount = Math.max(showCount, _this2.props.defaultShowCount); | ||
return showCount; | ||
}; | ||
this.resetData = function () { | ||
@@ -182,3 +192,5 @@ var dataSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this2.props.dataSource; | ||
if (hasScroll) { | ||
result = _this2.resetRenderInterval(_this2.lastScrollTop || _this2['bodyTable'].scrollTop, _this2['bodyTable'].clientHeight, bodyHeight, fixedColumnsBodyRowsHeight); | ||
var scrollTop = _this2.lastScrollTop || _this2['bodyTable'].scrollTop; | ||
var clientHeight = _this2['bodyTable'].clientHeight; | ||
result = _this2.resetRenderInterval(scrollTop, clientHeight, bodyHeight, fixedColumnsBodyRowsHeight, dataSource); | ||
} | ||
@@ -196,3 +208,4 @@ _this2.store.setState(_extends({ | ||
if (_this2.lastScrollTop !== target.scrollTop && target !== _this2['headTable']) { | ||
var result = _this2.resetRenderInterval(target.scrollTop, target.clientHeight, target.scrollHeight); | ||
var state = _this2.store.getState(); | ||
var result = _this2.resetRenderInterval(target.scrollTop, target.clientHeight, target.scrollHeight, state.fixedColumnsBodyRowsHeight, _this2.props.dataSource); | ||
_this2.store.setState(result); | ||
@@ -220,5 +233,6 @@ } | ||
this.resetRenderInterval = function (scrollTop, clientHeight, scrollHeight, fixedColumnsBodyRowsHeight) { | ||
this.resetRenderInterval = function (scrollTop, clientHeight, scrollHeight, fixedColumnsBodyRowsHeight, dataSource) { | ||
var rowHeight = _this2.props.rowHeight; | ||
dataSource = dataSource || []; | ||
if (!fixedColumnsBodyRowsHeight) { | ||
@@ -254,5 +268,13 @@ var state = _this2.store.getState(); | ||
} | ||
var showData = []; | ||
dataSource.forEach(function (data, index) { | ||
if (index >= start && index <= end) { | ||
data = _extends({}, data, { index: index }); | ||
showData.push(data); | ||
} | ||
}); | ||
return { | ||
renderStart: start, | ||
renderEnd: end | ||
renderEnd: end, | ||
showData: showData | ||
}; | ||
@@ -259,0 +281,0 @@ }; |
@@ -138,10 +138,7 @@ 'use strict'; | ||
exports.default = (0, _miniStore.connect)(function (state, props) { | ||
var currentHoverKey = state.currentHoverKey, | ||
tops = state.tops; | ||
var rowKey = props.rowKey, | ||
index = props.index; | ||
var currentHoverKey = state.currentHoverKey; | ||
var rowKey = props.rowKey; | ||
return { | ||
hovered: currentHoverKey === rowKey, | ||
top: tops[index] | ||
hovered: currentHoverKey === rowKey | ||
}; | ||
@@ -148,0 +145,0 @@ })(TableRow); |
{ | ||
"name": "fast-table", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "react table fast", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
65898
1594