fast-table
Advanced tools
Comparing version 1.3.2 to 1.3.3
@@ -93,30 +93,58 @@ 'use strict'; | ||
rowClassName = _table$props.rowClassName, | ||
expandedRowByClick = _table$props.expandedRowByClick; | ||
expandedRowByClick = _table$props.expandedRowByClick, | ||
hoverEnable = _table$props.hoverEnable; | ||
var dataManager = table.dataManager; | ||
var sizeManager = table.sizeManager; | ||
var columns = table.columnManager.bodyColumns(fixed); | ||
var hasExpanded = dataManager._hasExpanded; | ||
var showData = dataManager.showData(); | ||
for (var index = _this._startIndex; index <= _this._stopIndex; index++) { | ||
var _classNames; | ||
var dataSource = showData.filter(function (d, index) { | ||
return index >= _this._startIndex && index <= _this._stopIndex || d._isFixed; | ||
}); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var record = showData[index]; | ||
var className = typeof rowClassName === 'function' ? rowClassName(record, record._index) : rowClassName; | ||
var _props = { | ||
key: 'Row' + record._showIndex, | ||
className: (0, _classnames2.default)(className, (_classNames = {}, _defineProperty(_classNames, prefixCls + '-hover', currentHoverKey === record.key), _defineProperty(_classNames, prefixCls + '-expanded-row-' + record._expandedLevel, hasExpanded), _classNames)), | ||
record: record, | ||
prefixCls: prefixCls, | ||
columns: columns, | ||
fixed: fixed, | ||
expandedRowByClick: expandedRowByClick, | ||
expanded: dataManager.rowIsExpanded(record), | ||
onHover: _this.handleRowHover, | ||
components: table.components, | ||
handleExpanded: handleExpandChange, | ||
indentSize: indentSize | ||
}; | ||
hasExpanded && (_props.renderExpandedIcon = _ExpandedIcon2.default); | ||
rows.push((0, _TableRow2.default)(_props)); | ||
try { | ||
for (var _iterator = dataSource[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _classNames; | ||
var record = _step.value; | ||
var className = typeof rowClassName === 'function' ? rowClassName(record, record._index) : rowClassName; | ||
var _props = { | ||
key: 'Row' + record._showIndex, | ||
className: (0, _classnames2.default)(className, (_classNames = {}, _defineProperty(_classNames, prefixCls + '-hover', currentHoverKey === record.key), _defineProperty(_classNames, prefixCls + '-expanded-row-' + record._expandedLevel, hasExpanded), _defineProperty(_classNames, prefixCls + '-row-fixed', record._isFixed), _classNames)), | ||
record: record, | ||
prefixCls: prefixCls, | ||
columns: columns, | ||
fixed: fixed, | ||
expandedRowByClick: expandedRowByClick, | ||
expanded: dataManager.rowIsExpanded(record), | ||
onHover: _this.handleRowHover, | ||
components: table.components, | ||
handleExpanded: handleExpandChange, | ||
hoverEnable: hoverEnable, | ||
indentSize: indentSize, | ||
scrollTop: sizeManager._scrollTop | ||
}; | ||
hasExpanded && (_props.renderExpandedIcon = _ExpandedIcon2.default); | ||
rows.push((0, _TableRow2.default)(_props)); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
_this._children = rows; | ||
@@ -123,0 +151,0 @@ return _this._children; |
@@ -15,2 +15,4 @@ 'use strict'; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -27,9 +29,16 @@ | ||
this._hasExpanded = false; | ||
this._data = []; | ||
this.getData = function () { | ||
return _this._cache('getData', function () { | ||
return _this._getData(_this.data); | ||
return _this._getData(_this._data); | ||
}); | ||
}; | ||
this.getFixedData = function () { | ||
return _this._cache('getFixedData', function () { | ||
return _this._getFixedData(_this.showData()); | ||
}); | ||
}; | ||
this.showData = function () { | ||
@@ -41,2 +50,14 @@ return _this._cache('showData', function () { | ||
this.fixedData = function () { | ||
return _this._cache('fixedData', function () { | ||
return _this._getFixedData(_this.showData()); | ||
}); | ||
}; | ||
this.fixedDataLength = function () { | ||
return _this._cache('fixedDataLength', function () { | ||
return _this.fixedData().length; | ||
}); | ||
}; | ||
this.isExpanded = function () { | ||
@@ -55,3 +76,16 @@ return _this._cache('isExpanded', function () { | ||
this.reset = function (data) { | ||
_this.data = data || []; | ||
var _data = data || []; | ||
if (!_this.fixedHeader) { | ||
_this._data = _data; | ||
} else { | ||
var dataBase = _data.filter(function (d) { | ||
var children = d.children || []; | ||
return children.length > 0 || !d.isFixed; | ||
}); | ||
var dataFixed = _data.filter(function (d) { | ||
var children = d.children || []; | ||
return d.isFixed && children.length === 0; | ||
}); | ||
_this._data = [].concat(_toConsumableArray(dataFixed), _toConsumableArray(dataBase)); | ||
} | ||
_this._bodyHeight = 0; | ||
@@ -108,2 +142,3 @@ _this._cached = {}; | ||
_this._hasExpanded = _this._hasExpanded || children.length > 0; | ||
dataSource[index]['_isFixed'] = !!dataSource[index].isFixed && children.length === 0; | ||
if (children.length > 0) { | ||
@@ -116,2 +151,8 @@ dataSource[index]['children'] = _this._getData(children, level + 1); | ||
this._getFixedData = function (data) { | ||
return data.filter(function (d) { | ||
return d.isFixed && (d.children || []).length === 0; | ||
}); | ||
}; | ||
this._showData = function (dataSource, data) { | ||
@@ -150,8 +191,8 @@ dataSource = dataSource || []; | ||
this.data = props.dataSource || []; | ||
this.getRowHeight = props.getRowHeight; | ||
this.fixedHeader = props.fixedHeader; | ||
this.rowHeight = props.rowHeight; | ||
this.expandedRowKeys = props.expandedRowKeys || []; | ||
this.rowKey = props.rowKey; | ||
this.showData(); | ||
this.reset(props.dataSource); | ||
} | ||
@@ -158,0 +199,0 @@ |
@@ -153,2 +153,3 @@ 'use strict'; | ||
_this.lastScrollLeft = target.scrollLeft; | ||
_this.sizeManager.update({ _scrollLeft: _this.lastScrollLeft }); | ||
}; | ||
@@ -176,2 +177,3 @@ | ||
} | ||
_this.sizeManager.update({ _scrollTop: target.scrollTop }); | ||
_this.resetShowData(target); | ||
@@ -178,0 +180,0 @@ if (_this.props.refreshEnable) { |
@@ -35,3 +35,5 @@ 'use strict'; | ||
expandedRowByClick = props.expandedRowByClick, | ||
handleExpanded = props.handleExpanded; | ||
hoverEnable = props.hoverEnable, | ||
handleExpanded = props.handleExpanded, | ||
scrollTop = props.scrollTop; | ||
@@ -45,11 +47,5 @@ var Tr = components.body.row; | ||
position: 'absolute', | ||
top: record._top, | ||
top: record._top + (record._isFixed ? scrollTop : 0), | ||
height: record._height | ||
}, | ||
onMouseEnter: function onMouseEnter(event) { | ||
onHover && onHover(true, record.key); | ||
}, | ||
onMouseLeave: function onMouseLeave(event) { | ||
onHover && onHover(false, record.key); | ||
}, | ||
onClick: function (_onClick) { | ||
@@ -70,2 +66,13 @@ function onClick(_x) { | ||
}; | ||
if (record._isFixed) { | ||
newProps.style.zIndex = 1; | ||
} | ||
if (hoverEnable) { | ||
newProps.onMouseEnter = function () { | ||
onHover && onHover(true, record.key); | ||
}; | ||
newProps.onMouseLeave = function () { | ||
onHover && onHover(false, record.key); | ||
}; | ||
} | ||
var cells = []; | ||
@@ -72,0 +79,0 @@ for (var i = 0; i < columns.length; i++) { |
@@ -28,2 +28,3 @@ 'use strict'; | ||
useScrollY: true, | ||
hoverEnable: true, | ||
@@ -30,0 +31,0 @@ getRowHeight: function getRowHeight() { |
{ | ||
"name": "fast-table", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "react table fast", | ||
@@ -11,3 +11,4 @@ "main": "./lib/index.js", | ||
"scripts": { | ||
"build": "babel src -d lib" | ||
"build": "babel src -d lib", | ||
"init": "npm install --registry=https://registry.npm.taobao.org -d" | ||
}, | ||
@@ -14,0 +15,0 @@ "repository": { |
106336
2688