fix:syncHove属性bug;feature:滚动加载场景下保存expandKeys
This commit is contained in:
parent
e1e99843f2
commit
e5c300075e
|
@ -144,7 +144,8 @@ var defaultProps = {
|
|||
syncHover: true,
|
||||
setRowHeight: function setRowHeight() {},
|
||||
setRowParentIndex: function setRowParentIndex() {},
|
||||
tabIndex: '0'
|
||||
tabIndex: '0',
|
||||
noExpandedRowKeys: []
|
||||
};
|
||||
|
||||
var Table = function (_Component) {
|
||||
|
@ -395,7 +396,7 @@ var Table = function (_Component) {
|
|||
expandedRows.push(this.getRowKey(record, index));
|
||||
this.onExpandedRowsChange(expandedRows);
|
||||
}
|
||||
this.props.onExpand(expanded, record);
|
||||
this.props.onExpand(expanded, record, index);
|
||||
};
|
||||
|
||||
Table.prototype.onRowDestroy = function onRowDestroy(record, rowIndex) {
|
||||
|
@ -653,7 +654,7 @@ var Table = function (_Component) {
|
|||
var fixedColumnsBodyRowsHeight = this.state.fixedColumnsBodyRowsHeight;
|
||||
|
||||
var rst = [];
|
||||
var isHiddenExpandIcon = void 0;
|
||||
|
||||
var height = void 0;
|
||||
var rowClassName = props.rowClassName;
|
||||
var rowRef = props.rowRef;
|
||||
|
@ -672,32 +673,31 @@ var Table = function (_Component) {
|
|||
var lazyCurrentIndex = props.lazyLoad && props.lazyLoad.startIndex ? props.lazyLoad.startIndex : 0;
|
||||
var lazyParentIndex = props.lazyLoad && props.lazyLoad.startParentIndex ? props.lazyLoad.startParentIndex : 0;
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var isHiddenExpandIcon = void 0;
|
||||
var record = data[i];
|
||||
var key = this.getRowKey(record, i);
|
||||
var childrenColumn = record[childrenColumnName];
|
||||
var isRowExpanded = this.isRowExpanded(record, i);
|
||||
var expandedRowContent = void 0;
|
||||
var expandedContentHeight = 0;
|
||||
if (expandedRowRender && isRowExpanded) {
|
||||
expandedRowContent = expandedRowRender(record, i, indent);
|
||||
expandedContentHeight = parseInt(expandedRowContent.props && expandedRowContent.props.style && expandedRowContent.props.style.height ? expandedRowContent.props.style.height : 0);
|
||||
}
|
||||
//只有当使用expandedRowRender参数的时候才去识别isHiddenExpandIcon(隐藏行展开的icon)
|
||||
if (expandedRowRender && typeof props.haveExpandIcon == 'function') {
|
||||
isHiddenExpandIcon = props.haveExpandIcon(record, i);
|
||||
}
|
||||
var className = rowClassName(record, i, indent);
|
||||
|
||||
var onHoverProps = {};
|
||||
|
||||
onHoverProps.onHover = this.handleRowHover;
|
||||
|
||||
//fixedIndex一般是跟index是一个值的,只有是树结构时,会讲子节点的值也累计上
|
||||
var fixedIndex = i;
|
||||
//判断是否是tree结构
|
||||
if (this.treeType) {
|
||||
fixedIndex = this.treeRowIndex;
|
||||
}
|
||||
if (expandedRowRender && isRowExpanded) {
|
||||
expandedRowContent = expandedRowRender(record, fixedIndex + lazyCurrentIndex, indent);
|
||||
expandedContentHeight = parseInt(expandedRowContent.props && expandedRowContent.props.style && expandedRowContent.props.style.height ? expandedRowContent.props.style.height : 0);
|
||||
}
|
||||
//只有当使用expandedRowRender参数的时候才去识别isHiddenExpandIcon(隐藏行展开的icon)
|
||||
if (expandedRowRender && typeof props.haveExpandIcon == 'function') {
|
||||
isHiddenExpandIcon = props.haveExpandIcon(record, i);
|
||||
}
|
||||
|
||||
var onHoverProps = {};
|
||||
|
||||
onHoverProps.onHover = this.handleRowHover;
|
||||
|
||||
if (props.height) {
|
||||
height = props.height;
|
||||
|
@ -713,6 +713,7 @@ var Table = function (_Component) {
|
|||
} else {
|
||||
leafColumns = this.columnManager.leafColumns();
|
||||
}
|
||||
var className = rowClassName(record, fixedIndex + lazyCurrentIndex, indent);
|
||||
|
||||
//合计代码如果是最后一行并且有合计功能时,最后一行为合计列
|
||||
if (i == data.length - 1 && props.showSum) {
|
||||
|
@ -728,6 +729,11 @@ var Table = function (_Component) {
|
|||
if (rootIndex == -1) {
|
||||
index = i + lazyParentIndex;
|
||||
}
|
||||
var noexpandable = void 0;
|
||||
if (props.noExpandedRowKeys.indexOf(key) >= 0) {
|
||||
noexpandable = true;
|
||||
isHiddenExpandIcon = true;
|
||||
}
|
||||
rst.push(_react2["default"].createElement(_TableRow2["default"], _extends({
|
||||
indent: indent,
|
||||
indentSize: props.indentSize,
|
||||
|
@ -740,7 +746,7 @@ var Table = function (_Component) {
|
|||
visible: visible,
|
||||
expandRowByClick: expandRowByClick,
|
||||
onExpand: this.onExpanded,
|
||||
expandable: childrenColumn || expandedRowRender,
|
||||
expandable: !noexpandable && (childrenColumn || expandedRowRender),
|
||||
expanded: isRowExpanded,
|
||||
clsPrefix: props.clsPrefix + '-row',
|
||||
childrenColumnName: childrenColumnName,
|
||||
|
@ -761,7 +767,8 @@ var Table = function (_Component) {
|
|||
setRowParentIndex: props.setRowParentIndex,
|
||||
treeType: childrenColumn || this.treeType ? true : false,
|
||||
fixedIndex: fixedIndex + lazyCurrentIndex,
|
||||
rootIndex: rootIndex
|
||||
rootIndex: rootIndex,
|
||||
syncHover: props.syncHover
|
||||
})));
|
||||
this.treeRowIndex++;
|
||||
var subVisible = visible && isRowExpanded;
|
||||
|
|
|
@ -175,13 +175,14 @@ var TableRow = function (_Component) {
|
|||
expandable = _props5.expandable,
|
||||
expandRowByClick = _props5.expandRowByClick,
|
||||
expanded = _props5.expanded,
|
||||
onExpand = _props5.onExpand;
|
||||
onExpand = _props5.onExpand,
|
||||
fixedIndex = _props5.fixedIndex;
|
||||
|
||||
if (expandable && expandRowByClick) {
|
||||
onExpand(!expanded, record, index, event);
|
||||
onExpand(!expanded, record, fixedIndex, event);
|
||||
}
|
||||
this.set(function (e) {
|
||||
onRowClick(record, index, event);
|
||||
onRowClick(record, fixedIndex, event);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -189,19 +190,23 @@ var TableRow = function (_Component) {
|
|||
var _props6 = this.props,
|
||||
record = _props6.record,
|
||||
index = _props6.index,
|
||||
onRowDoubleClick = _props6.onRowDoubleClick;
|
||||
onRowDoubleClick = _props6.onRowDoubleClick,
|
||||
fixedIndex = _props6.fixedIndex;
|
||||
|
||||
this.clear();
|
||||
onRowDoubleClick(record, index, event);
|
||||
onRowDoubleClick(record, fixedIndex, event);
|
||||
};
|
||||
|
||||
TableRow.prototype.onMouseEnter = function onMouseEnter(e) {
|
||||
var _props7 = this.props,
|
||||
onHover = _props7.onHover,
|
||||
hoverKey = _props7.hoverKey,
|
||||
fixedIndex = _props7.fixedIndex;
|
||||
fixedIndex = _props7.fixedIndex,
|
||||
syncHover = _props7.syncHover;
|
||||
|
||||
this.setState({ hovered: true });
|
||||
if (!syncHover) {
|
||||
this.setState({ hovered: true });
|
||||
}
|
||||
onHover(true, hoverKey, e, fixedIndex);
|
||||
};
|
||||
|
||||
|
@ -209,9 +214,12 @@ var TableRow = function (_Component) {
|
|||
var _props8 = this.props,
|
||||
onHover = _props8.onHover,
|
||||
hoverKey = _props8.hoverKey,
|
||||
fixedIndex = _props8.fixedIndex;
|
||||
fixedIndex = _props8.fixedIndex,
|
||||
syncHover = _props8.syncHover;
|
||||
|
||||
this.setState({ hovered: false });
|
||||
if (!syncHover) {
|
||||
this.setState({ hovered: false });
|
||||
}
|
||||
onHover(false, hoverKey, e, fixedIndex);
|
||||
};
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ function bigData(Table) {
|
|||
_this2.endIndex = _this2.currentIndex + _this2.loadCount; //数据结束位置
|
||||
_this2.setRowHeight = _this2.setRowHeight.bind(_this2);
|
||||
_this2.setRowParentIndex = _this2.setRowParentIndex.bind(_this2);
|
||||
_this2.expandedRowKeys = [];
|
||||
return _this2;
|
||||
}
|
||||
|
||||
|
@ -269,6 +270,7 @@ function bigData(Table) {
|
|||
var endIndex = this.endIndex,
|
||||
startIndex = this.startIndex;
|
||||
|
||||
var expandedRowKeys = this.props.expandedRowKeys ? this.props.expandedRowKeys : this.expandedRowKeys;
|
||||
if (startIndex < 0) {
|
||||
startIndex = 0;
|
||||
}
|
||||
|
@ -299,7 +301,7 @@ function bigData(Table) {
|
|||
lazyLoad.preHeight = this.getSumHeight(0, startIndex);
|
||||
lazyLoad.sufHeight = this.getSumHeight(endIndex, data.length);
|
||||
}
|
||||
// console.log('*******ScrollTop*****'+scrollTop);
|
||||
// console.log('*******expandedRowKeys*****'+expandedRowKeys);
|
||||
return _react2["default"].createElement(Table, _extends({}, this.props, {
|
||||
data: data.slice(startIndex, endIndex),
|
||||
lazyLoad: lazyLoad,
|
||||
|
@ -308,7 +310,8 @@ function bigData(Table) {
|
|||
setRowHeight: this.setRowHeight,
|
||||
setRowParentIndex: this.setRowParentIndex,
|
||||
onExpand: this.onExpand,
|
||||
onExpandedRowsChange: this.onExpandedRowsChange
|
||||
onExpandedRowsChange: this.onExpandedRowsChange,
|
||||
expandedRowKeys: expandedRowKeys
|
||||
// className={'lazy-table'}
|
||||
}));
|
||||
};
|
||||
|
@ -372,30 +375,6 @@ function bigData(Table) {
|
|||
_this.scrollTop = nextScrollTop;
|
||||
var viewHeight = parseInt(scroll.y);
|
||||
_this.treeType = treeType;
|
||||
// let index = currentIndex;//记录下次当前位置
|
||||
// let temp = currentIndex ?nextScrollTop - currentScrollTop:nextScrollTop;
|
||||
|
||||
// const isOrder = temp > 0 ?true:false;//true为向下滚动、false为向上滚动
|
||||
|
||||
// //根据scrollTop计算下次当前索引的位置
|
||||
// if(isOrder){
|
||||
// while (temp > 0) {
|
||||
// temp -= this.cachedRowHeight[index] || rowHeight
|
||||
// if(temp > 0){
|
||||
// index += 1
|
||||
// //保存当前index对应的scrollTop
|
||||
// this.currentScrollTop += this.cachedRowHeight[index]|| rowHeight;
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// while(temp < 0){
|
||||
// temp += this.cachedRowHeight[index] || rowHeight
|
||||
// if(temp < 0){
|
||||
// index -= 1
|
||||
// this.currentScrollTop -= this.cachedRowHeight[index]|| rowHeight;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
var index = 0;
|
||||
var temp = nextScrollTop;
|
||||
var currentKey = void 0;
|
||||
|
@ -454,17 +433,6 @@ function bigData(Table) {
|
|||
if (rowsInView + index > endIndex - rowDiff && isOrder) {
|
||||
startIndex = index - loadBuffer > 0 ? index - loadBuffer : 0;
|
||||
endIndex = startIndex + loadCount;
|
||||
//树状结构则根据当前的节点重新计算startIndex和endIndex
|
||||
// if(treeType){
|
||||
// const currentParentIndex = _this.cachedRowParentIndex[index];
|
||||
// startIndex = currentParentIndex - loadBuffer>0?currentParentIndex - loadBuffer:0;
|
||||
// endIndex = startIndex + loadCount;
|
||||
// // console.log(endIndex,"endIndex的parentIndex",parentEndIndex);
|
||||
// // endIndex = parentEndIndex +1
|
||||
// }else{
|
||||
// startIndex = index - loadBuffer>0?index - loadBuffer:0;
|
||||
// endIndex = startIndex + loadCount;
|
||||
// }
|
||||
if (endIndex > data.length) {
|
||||
endIndex = data.length;
|
||||
}
|
||||
|
@ -473,12 +441,6 @@ function bigData(Table) {
|
|||
_this4.endIndex = endIndex;
|
||||
_this4.setState({ needRender: !needRender });
|
||||
}
|
||||
// console.log(
|
||||
// "===================",
|
||||
// "**index**" + index,
|
||||
// " **startIndex**" + this.startIndex,
|
||||
// "**endIndex**" + this.endIndex
|
||||
// );
|
||||
}
|
||||
// 向上滚动,当前的index是否已经加载(currentIndex),若干上临界值小于startIndex则重新渲染
|
||||
if (!isOrder && index < startIndex + rowDiff) {
|
||||
|
@ -501,22 +463,48 @@ function bigData(Table) {
|
|||
}
|
||||
};
|
||||
|
||||
this.onExpand = function (expandState, record) {
|
||||
this.onExpand = function (expandState, record, index) {
|
||||
var _this = _this4;
|
||||
var _this$expandedRowKeys = _this.expandedRowKeys,
|
||||
expandedRowKeys = _this$expandedRowKeys === undefined ? [] : _this$expandedRowKeys;
|
||||
var needRender = _this.state.needRender;
|
||||
|
||||
var rowKey = _this.getRowKey(record, index);
|
||||
// 记录展开子表行的key
|
||||
// 展开
|
||||
if (expandState) {
|
||||
record.children && record.children.forEach(function (item, index) {
|
||||
_this.expandChildRowKeys.push(_this.getRowKey(item, index));
|
||||
});
|
||||
} else {
|
||||
// 收起
|
||||
record.children && record.children.forEach(function (item, index) {
|
||||
_this.expandChildRowKeys.splice(_this.expandChildRowKeys.findIndex(function (fitem) {
|
||||
return fitem.key === item.key;
|
||||
}), 1);
|
||||
});
|
||||
if (record.children) {
|
||||
if (expandState) {
|
||||
record.children.forEach(function (item, index) {
|
||||
_this.expandChildRowKeys.push(rowKey);
|
||||
});
|
||||
} else {
|
||||
// 收起
|
||||
record.children.forEach(function (item, index) {
|
||||
_this.expandChildRowKeys.splice(_this.expandChildRowKeys.findIndex(function (fitem) {
|
||||
return fitem.key === item.key;
|
||||
}), 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
//滚动加载expandedRowKeys自己维护,否则有展开不全的问题
|
||||
if (!_this.props.expandedRowKeys) {
|
||||
if (expandState) {
|
||||
expandedRowKeys.push(rowKey);
|
||||
} else {
|
||||
var _index = -1;
|
||||
expandedRowKeys.forEach(function (r, i) {
|
||||
if (r === rowKey) {
|
||||
_index = i;
|
||||
}
|
||||
});
|
||||
if (_index !== -1) {
|
||||
expandedRowKeys.splice(_index, 1);
|
||||
_this4.setState({ needRender: !needRender });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// expandState为true时,记录下
|
||||
_this.props.onExpand(expandState, record);
|
||||
};
|
||||
}, _temp;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
value: true
|
||||
});
|
||||
|
||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||
|
@ -36,137 +36,137 @@ var cloneDeep = require('lodash.clonedeep');
|
|||
|
||||
function dragColumn(Table) {
|
||||
|
||||
return function (_Component) {
|
||||
_inherits(DragColumn, _Component);
|
||||
return function (_Component) {
|
||||
_inherits(DragColumn, _Component);
|
||||
|
||||
function DragColumn(props) {
|
||||
_classCallCheck(this, DragColumn);
|
||||
function DragColumn(props) {
|
||||
_classCallCheck(this, DragColumn);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
||||
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
||||
|
||||
_this.setColumOrderByIndex = function (_column) {
|
||||
_column.forEach(function (da, i) {
|
||||
da.dragIndex = i;
|
||||
da.drgHover = false;
|
||||
});
|
||||
return _column;
|
||||
};
|
||||
|
||||
_this.onDrop = function (event, data) {
|
||||
var dragSource = data.dragSource,
|
||||
dragTarg = data.dragTarg;
|
||||
var columns = _this.state.columns;
|
||||
|
||||
var sourceIndex = -1,
|
||||
targetIndex = -1;
|
||||
|
||||
sourceIndex = columns.findIndex(function (da, i) {
|
||||
return da.key == dragSource.key;
|
||||
});
|
||||
targetIndex = columns.findIndex(function (da, i) {
|
||||
return da.key == dragTarg.key;
|
||||
});
|
||||
// for (let index = 0; index < columns.length; index++) {
|
||||
// const da = columns[index];
|
||||
// if(da.key === dragSource.key){
|
||||
// columns[index] = dragTargColum;
|
||||
// }
|
||||
// if(da.key === dragTarg.key){
|
||||
// columns[index] = dragSourceColum;
|
||||
// }
|
||||
// }
|
||||
// 向前移动
|
||||
if (targetIndex < sourceIndex) {
|
||||
targetIndex = targetIndex + 1;
|
||||
}
|
||||
columns.splice(targetIndex, 0, columns.splice(sourceIndex, 1)[0]);
|
||||
_this.setState({
|
||||
columns: cloneDeep(columns)
|
||||
});
|
||||
if (_this.props.onDrop) {
|
||||
_this.props.onDrop(event, data, columns);
|
||||
}
|
||||
};
|
||||
|
||||
_this.getTarget = function (evt) {
|
||||
return evt.target || evt.srcElement;
|
||||
};
|
||||
|
||||
_this.state = {
|
||||
columns: _this.setColumOrderByIndex(props.columns)
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
|
||||
DragColumn.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.columns != this.props.columns) {
|
||||
this.setState({
|
||||
columns: this.setColumOrderByIndex(nextProps.columns)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
DragColumn.prototype.cloneDeep = function cloneDeep(obj) {
|
||||
if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' || Object.keys(obj).length === 0) {
|
||||
return obj;
|
||||
}
|
||||
var resultData = {};
|
||||
return this.recursion(obj, resultData);
|
||||
};
|
||||
|
||||
DragColumn.prototype.recursion = function (_recursion) {
|
||||
function recursion(_x) {
|
||||
return _recursion.apply(this, arguments);
|
||||
}
|
||||
|
||||
recursion.toString = function () {
|
||||
return _recursion.toString();
|
||||
};
|
||||
|
||||
return recursion;
|
||||
}(function (obj) {
|
||||
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
for (key in obj) {
|
||||
if (_typeof(obj[key]) == 'object' && Object.keys(obj[key].length > 0)) {
|
||||
data[key] = recursion(obj[key]);
|
||||
} else {
|
||||
data[key] = obj[key];
|
||||
}
|
||||
}
|
||||
return data;
|
||||
_this.setColumOrderByIndex = function (_column) {
|
||||
_column.forEach(function (da, i) {
|
||||
da.dragIndex = i;
|
||||
da.drgHover = false;
|
||||
});
|
||||
return _column;
|
||||
};
|
||||
|
||||
DragColumn.prototype.render = function render() {
|
||||
var _props = this.props,
|
||||
data = _props.data,
|
||||
dragborder = _props.dragborder,
|
||||
draggable = _props.draggable,
|
||||
className = _props.className,
|
||||
columns = _props.columns,
|
||||
onDragStart = _props.onDragStart,
|
||||
onDragEnter = _props.onDragEnter,
|
||||
onDragOver = _props.onDragOver,
|
||||
onDrop = _props.onDrop,
|
||||
others = _objectWithoutProperties(_props, ['data', 'dragborder', 'draggable', 'className', 'columns', 'onDragStart', 'onDragEnter', 'onDragOver', 'onDrop']);
|
||||
_this.onDrop = function (event, data) {
|
||||
var dragSource = data.dragSource,
|
||||
dragTarg = data.dragTarg;
|
||||
var columns = _this.state.columns;
|
||||
|
||||
var key = new Date().getTime();
|
||||
return _react2["default"].createElement(Table, _extends({}, others, {
|
||||
columns: this.state.columns,
|
||||
data: data,
|
||||
className: className + ' u-table-drag-border',
|
||||
onDragStart: this.onDragStart,
|
||||
onDragOver: this.onDragOver,
|
||||
onDrop: this.onDrop,
|
||||
onDragEnter: this.onDragEnter,
|
||||
draggable: draggable,
|
||||
dragborder: dragborder
|
||||
// dragborder={false}
|
||||
, dragborderKey: key
|
||||
}));
|
||||
};
|
||||
var sourceIndex = -1,
|
||||
targetIndex = -1;
|
||||
|
||||
return DragColumn;
|
||||
}(_react.Component);
|
||||
sourceIndex = columns.findIndex(function (da, i) {
|
||||
return da.key == dragSource.key;
|
||||
});
|
||||
targetIndex = columns.findIndex(function (da, i) {
|
||||
return da.key == dragTarg.key;
|
||||
});
|
||||
// for (let index = 0; index < columns.length; index++) {
|
||||
// const da = columns[index];
|
||||
// if(da.key === dragSource.key){
|
||||
// columns[index] = dragTargColum;
|
||||
// }
|
||||
// if(da.key === dragTarg.key){
|
||||
// columns[index] = dragSourceColum;
|
||||
// }
|
||||
// }
|
||||
// 向前移动
|
||||
if (targetIndex < sourceIndex) {
|
||||
targetIndex = targetIndex + 1;
|
||||
}
|
||||
columns.splice(targetIndex, 0, columns.splice(sourceIndex, 1)[0]);
|
||||
_this.setState({
|
||||
columns: cloneDeep(columns)
|
||||
});
|
||||
if (_this.props.onDrop) {
|
||||
_this.props.onDrop(event, data, columns);
|
||||
}
|
||||
};
|
||||
|
||||
_this.getTarget = function (evt) {
|
||||
return evt.target || evt.srcElement;
|
||||
};
|
||||
|
||||
_this.state = {
|
||||
columns: _this.setColumOrderByIndex(props.columns)
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
|
||||
DragColumn.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.columns != this.props.columns) {
|
||||
this.setState({
|
||||
columns: this.setColumOrderByIndex(nextProps.columns)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
DragColumn.prototype.cloneDeep = function cloneDeep(obj) {
|
||||
if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' || Object.keys(obj).length === 0) {
|
||||
return obj;
|
||||
}
|
||||
var resultData = {};
|
||||
return this.recursion(obj, resultData);
|
||||
};
|
||||
|
||||
DragColumn.prototype.recursion = function (_recursion) {
|
||||
function recursion(_x) {
|
||||
return _recursion.apply(this, arguments);
|
||||
}
|
||||
|
||||
recursion.toString = function () {
|
||||
return _recursion.toString();
|
||||
};
|
||||
|
||||
return recursion;
|
||||
}(function (obj) {
|
||||
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
for (key in obj) {
|
||||
if (_typeof(obj[key]) == 'object' && Object.keys(obj[key].length > 0)) {
|
||||
data[key] = recursion(obj[key]);
|
||||
} else {
|
||||
data[key] = obj[key];
|
||||
}
|
||||
}
|
||||
return data;
|
||||
});
|
||||
|
||||
DragColumn.prototype.render = function render() {
|
||||
var _props = this.props,
|
||||
data = _props.data,
|
||||
dragborder = _props.dragborder,
|
||||
draggable = _props.draggable,
|
||||
className = _props.className,
|
||||
columns = _props.columns,
|
||||
onDragStart = _props.onDragStart,
|
||||
onDragEnter = _props.onDragEnter,
|
||||
onDragOver = _props.onDragOver,
|
||||
onDrop = _props.onDrop,
|
||||
others = _objectWithoutProperties(_props, ['data', 'dragborder', 'draggable', 'className', 'columns', 'onDragStart', 'onDragEnter', 'onDragOver', 'onDrop']);
|
||||
|
||||
var key = new Date().getTime();
|
||||
return _react2["default"].createElement(Table, _extends({}, others, {
|
||||
columns: this.state.columns,
|
||||
data: data,
|
||||
className: className + ' u-table-drag-border',
|
||||
onDragStart: this.onDragStart,
|
||||
onDragOver: this.onDragOver,
|
||||
onDrop: this.onDrop,
|
||||
onDragEnter: this.onDragEnter,
|
||||
draggable: draggable,
|
||||
dragborder: dragborder
|
||||
// dragborder={false}
|
||||
, dragborderKey: key
|
||||
}));
|
||||
};
|
||||
|
||||
return DragColumn;
|
||||
}(_react.Component);
|
||||
}
|
||||
module.exports = exports['default'];
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
value: true
|
||||
});
|
||||
|
||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||
|
@ -20,29 +20,29 @@ exports.ObjectAssign = ObjectAssign;
|
|||
*/
|
||||
|
||||
function sortBy(arr, prop, desc) {
|
||||
var props = [],
|
||||
ret = [],
|
||||
i = 0,
|
||||
len = arr.length;
|
||||
if (typeof prop == 'string') {
|
||||
for (; i < len; i++) {
|
||||
var oI = arr[i];
|
||||
(props[i] = new String(oI && oI[prop] || ''))._obj = oI;
|
||||
var props = [],
|
||||
ret = [],
|
||||
i = 0,
|
||||
len = arr.length;
|
||||
if (typeof prop == 'string') {
|
||||
for (; i < len; i++) {
|
||||
var oI = arr[i];
|
||||
(props[i] = new String(oI && oI[prop] || ''))._obj = oI;
|
||||
}
|
||||
} else if (typeof prop == 'function') {
|
||||
for (; i < len; i++) {
|
||||
var _oI = arr[i];
|
||||
(props[i] = new String(_oI && prop(_oI) || ''))._obj = _oI;
|
||||
}
|
||||
} else {
|
||||
throw '参数类型错误';
|
||||
}
|
||||
} else if (typeof prop == 'function') {
|
||||
for (; i < len; i++) {
|
||||
var _oI = arr[i];
|
||||
(props[i] = new String(_oI && prop(_oI) || ''))._obj = _oI;
|
||||
props.sort();
|
||||
for (i = 0; i < len; i++) {
|
||||
ret[i] = props[i]._obj;
|
||||
}
|
||||
} else {
|
||||
throw '参数类型错误';
|
||||
}
|
||||
props.sort();
|
||||
for (i = 0; i < len; i++) {
|
||||
ret[i] = props[i]._obj;
|
||||
}
|
||||
if (desc) ret.reverse();
|
||||
return ret;
|
||||
if (desc) ret.reverse();
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -51,11 +51,11 @@ function sortBy(arr, prop, desc) {
|
|||
* @param {} property
|
||||
*/
|
||||
function compare(property) {
|
||||
return function (a, b) {
|
||||
var value1 = a[property];
|
||||
var value2 = b[property];
|
||||
return value1 - value2;
|
||||
};
|
||||
return function (a, b) {
|
||||
var value1 = a[property];
|
||||
var value2 = b[property];
|
||||
return value1 - value2;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,17 +63,17 @@ function compare(property) {
|
|||
* @param {*} obj 要拷贝的对象
|
||||
*/
|
||||
function ObjectAssign(obj) {
|
||||
var b = obj instanceof Array;
|
||||
var tagObj = b ? [] : {};
|
||||
if (b) {
|
||||
//数组
|
||||
obj.forEach(function (da) {
|
||||
var _da = {};
|
||||
_extends(_da, da);
|
||||
tagObj.push(_da);
|
||||
});
|
||||
} else {
|
||||
_extends(tagObj, obj);
|
||||
}
|
||||
return tagObj;
|
||||
var b = obj instanceof Array;
|
||||
var tagObj = b ? [] : {};
|
||||
if (b) {
|
||||
//数组
|
||||
obj.forEach(function (da) {
|
||||
var _da = {};
|
||||
_extends(_da, da);
|
||||
tagObj.push(_da);
|
||||
});
|
||||
} else {
|
||||
_extends(tagObj, obj);
|
||||
}
|
||||
return tagObj;
|
||||
}
|
|
@ -8626,10 +8626,8 @@ ul {
|
|||
color: rgb(66,165,245); }
|
||||
.u-table td a:active {
|
||||
color: rgb(21,101,192); }
|
||||
.u-table tr:hover {
|
||||
background: rgb(227,242,253); }
|
||||
.u-table tr:hover td .uf-eye {
|
||||
visibility: visible !important; }
|
||||
.u-table tr:hover td .uf-eye {
|
||||
visibility: visible !important; }
|
||||
.u-table tr tr a {
|
||||
color: rgb(30,136,229); }
|
||||
.u-table tr tr a:hover {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "bee-table",
|
||||
"version": "1.6.41.beta.0",
|
||||
"version": "1.6.42.beta.0",
|
||||
"description": "Table ui component for react",
|
||||
"keywords": [
|
||||
"react",
|
||||
|
|
33
src/Table.js
33
src/Table.js
|
@ -85,6 +85,7 @@ const defaultProps = {
|
|||
setRowHeight:()=>{},
|
||||
setRowParentIndex:()=>{},
|
||||
tabIndex:'0',
|
||||
noExpandedRowKeys:[]
|
||||
};
|
||||
|
||||
class Table extends Component {
|
||||
|
@ -289,7 +290,7 @@ class Table extends Component {
|
|||
expandedRows.push(this.getRowKey(record, index));
|
||||
this.onExpandedRowsChange(expandedRows);
|
||||
}
|
||||
this.props.onExpand(expanded, record);
|
||||
this.props.onExpand(expanded, record,index);
|
||||
}
|
||||
|
||||
onRowDestroy(record, rowIndex) {
|
||||
|
@ -515,7 +516,7 @@ class Table extends Component {
|
|||
const expandRowByClick = props.expandRowByClick;
|
||||
const { fixedColumnsBodyRowsHeight } = this.state;
|
||||
let rst = [];
|
||||
let isHiddenExpandIcon;
|
||||
|
||||
let height;
|
||||
const rowClassName = props.rowClassName;
|
||||
const rowRef = props.rowRef;
|
||||
|
@ -534,32 +535,34 @@ class Table extends Component {
|
|||
const lazyCurrentIndex = props.lazyLoad && props.lazyLoad.startIndex ?props.lazyLoad.startIndex :0;
|
||||
const lazyParentIndex = props.lazyLoad && props.lazyLoad.startParentIndex ?props.lazyLoad.startParentIndex :0;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let isHiddenExpandIcon;
|
||||
const record = data[i];
|
||||
const key = this.getRowKey(record, i);
|
||||
const childrenColumn = record[childrenColumnName];
|
||||
const isRowExpanded = this.isRowExpanded(record, i);
|
||||
let expandedRowContent;
|
||||
let expandedContentHeight = 0;
|
||||
//fixedIndex一般是跟index是一个值的,只有是树结构时,会讲子节点的值也累计上
|
||||
let fixedIndex = i;
|
||||
//判断是否是tree结构
|
||||
if (this.treeType) {
|
||||
fixedIndex = this.treeRowIndex;
|
||||
}
|
||||
if (expandedRowRender && isRowExpanded) {
|
||||
expandedRowContent = expandedRowRender(record, i, indent);
|
||||
expandedRowContent = expandedRowRender(record, fixedIndex+lazyCurrentIndex, indent);
|
||||
expandedContentHeight = parseInt(expandedRowContent.props && expandedRowContent.props.style && expandedRowContent.props.style.height?expandedRowContent.props.style.height:0);
|
||||
}
|
||||
//只有当使用expandedRowRender参数的时候才去识别isHiddenExpandIcon(隐藏行展开的icon)
|
||||
if (expandedRowRender && typeof props.haveExpandIcon == 'function') {
|
||||
isHiddenExpandIcon = props.haveExpandIcon(record, i);
|
||||
}
|
||||
let className = rowClassName(record, i, indent);
|
||||
|
||||
|
||||
const onHoverProps = {};
|
||||
|
||||
onHoverProps.onHover = this.handleRowHover;
|
||||
|
||||
//fixedIndex一般是跟index是一个值的,只有是树结构时,会讲子节点的值也累计上
|
||||
let fixedIndex = i;
|
||||
//判断是否是tree结构
|
||||
if (this.treeType) {
|
||||
fixedIndex = this.treeRowIndex;
|
||||
}
|
||||
|
||||
|
||||
if (props.height) {
|
||||
height = props.height
|
||||
|
@ -575,7 +578,7 @@ class Table extends Component {
|
|||
} else {
|
||||
leafColumns = this.columnManager.leafColumns();
|
||||
}
|
||||
|
||||
let className = rowClassName(record, fixedIndex+lazyCurrentIndex, indent);
|
||||
|
||||
//合计代码如果是最后一行并且有合计功能时,最后一行为合计列
|
||||
if(i == data.length -1 && props.showSum){
|
||||
|
@ -591,6 +594,11 @@ class Table extends Component {
|
|||
if(rootIndex ==-1){
|
||||
index = i+lazyParentIndex
|
||||
}
|
||||
let noexpandable;
|
||||
if(props.noExpandedRowKeys.indexOf(key) >= 0){
|
||||
noexpandable = true;
|
||||
isHiddenExpandIcon = true;
|
||||
}
|
||||
rst.push(
|
||||
<TableRow
|
||||
indent={indent}
|
||||
|
@ -604,7 +612,7 @@ class Table extends Component {
|
|||
visible={visible}
|
||||
expandRowByClick={expandRowByClick}
|
||||
onExpand={this.onExpanded}
|
||||
expandable={childrenColumn || expandedRowRender}
|
||||
expandable={!noexpandable && (childrenColumn || expandedRowRender)}
|
||||
expanded={isRowExpanded}
|
||||
clsPrefix={`${props.clsPrefix}-row`}
|
||||
childrenColumnName={childrenColumnName}
|
||||
|
@ -626,6 +634,7 @@ class Table extends Component {
|
|||
treeType={childrenColumn||this.treeType?true:false}
|
||||
fixedIndex={fixedIndex+lazyCurrentIndex}
|
||||
rootIndex = {rootIndex}
|
||||
syncHover = {props.syncHover}
|
||||
/>
|
||||
);
|
||||
this.treeRowIndex++;
|
||||
|
|
|
@ -70,7 +70,7 @@ $checkbox-height:16px;
|
|||
tr {
|
||||
// transition: all 0.3s ease;
|
||||
&:hover {
|
||||
background: $hover-bg-color-base;
|
||||
// background: $hover-bg-color-base;
|
||||
td {
|
||||
.uf-eye{
|
||||
visibility: visible !important;
|
||||
|
|
|
@ -112,31 +112,36 @@ class TableRow extends Component{
|
|||
expandRowByClick,
|
||||
expanded,
|
||||
onExpand,
|
||||
fixedIndex
|
||||
} = this.props;
|
||||
if (expandable && expandRowByClick) {
|
||||
onExpand(!expanded, record, index,event);
|
||||
onExpand(!expanded, record, fixedIndex,event);
|
||||
}
|
||||
this.set((e)=> {
|
||||
onRowClick(record, index, event);
|
||||
onRowClick(record, fixedIndex, event);
|
||||
});
|
||||
}
|
||||
|
||||
onRowDoubleClick(event) {
|
||||
const { record, index, onRowDoubleClick } = this.props;
|
||||
const { record, index, onRowDoubleClick,fixedIndex } = this.props;
|
||||
this.clear();
|
||||
onRowDoubleClick(record, index, event);
|
||||
onRowDoubleClick(record, fixedIndex, event);
|
||||
}
|
||||
|
||||
onMouseEnter(e) {
|
||||
const { onHover, hoverKey,fixedIndex } = this.props;
|
||||
this.setState({ hovered: true });
|
||||
const { onHover, hoverKey,fixedIndex,syncHover } = this.props;
|
||||
if(syncHover){
|
||||
this.setState({ hovered: true });
|
||||
}
|
||||
onHover(true, hoverKey,e,fixedIndex);
|
||||
}
|
||||
|
||||
onMouseLeave(e) {
|
||||
|
||||
const { onHover, hoverKey ,fixedIndex} = this.props;
|
||||
this.setState({ hovered: false });
|
||||
const { onHover, hoverKey ,fixedIndex,syncHover} = this.props;
|
||||
if(syncHover){
|
||||
this.setState({ hovered: false });
|
||||
}
|
||||
onHover(false, hoverKey,e,fixedIndex);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ export default function bigData(Table) {
|
|||
this.endIndex = this.currentIndex + this.loadCount; //数据结束位置
|
||||
this.setRowHeight = this.setRowHeight.bind(this);
|
||||
this.setRowParentIndex = this.setRowParentIndex.bind(this);
|
||||
this.expandedRowKeys = [];
|
||||
}
|
||||
componentWillReceiveProps(nextProps) {
|
||||
const props = this.props;
|
||||
|
@ -227,30 +228,6 @@ export default function bigData(Table) {
|
|||
_this.scrollTop = nextScrollTop;
|
||||
const viewHeight = parseInt(scroll.y);
|
||||
_this.treeType = treeType;
|
||||
// let index = currentIndex;//记录下次当前位置
|
||||
// let temp = currentIndex ?nextScrollTop - currentScrollTop:nextScrollTop;
|
||||
|
||||
// const isOrder = temp > 0 ?true:false;//true为向下滚动、false为向上滚动
|
||||
|
||||
// //根据scrollTop计算下次当前索引的位置
|
||||
// if(isOrder){
|
||||
// while (temp > 0) {
|
||||
// temp -= this.cachedRowHeight[index] || rowHeight
|
||||
// if(temp > 0){
|
||||
// index += 1
|
||||
// //保存当前index对应的scrollTop
|
||||
// this.currentScrollTop += this.cachedRowHeight[index]|| rowHeight;
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// while(temp < 0){
|
||||
// temp += this.cachedRowHeight[index] || rowHeight
|
||||
// if(temp < 0){
|
||||
// index -= 1
|
||||
// this.currentScrollTop -= this.cachedRowHeight[index]|| rowHeight;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
let index = 0;
|
||||
let temp = nextScrollTop;
|
||||
let currentKey;
|
||||
|
@ -319,17 +296,6 @@ export default function bigData(Table) {
|
|||
if (rowsInView + index > endIndex - rowDiff && isOrder) {
|
||||
startIndex = index - loadBuffer > 0 ? index - loadBuffer : 0;
|
||||
endIndex = startIndex + loadCount;
|
||||
//树状结构则根据当前的节点重新计算startIndex和endIndex
|
||||
// if(treeType){
|
||||
// const currentParentIndex = _this.cachedRowParentIndex[index];
|
||||
// startIndex = currentParentIndex - loadBuffer>0?currentParentIndex - loadBuffer:0;
|
||||
// endIndex = startIndex + loadCount;
|
||||
// // console.log(endIndex,"endIndex的parentIndex",parentEndIndex);
|
||||
// // endIndex = parentEndIndex +1
|
||||
// }else{
|
||||
// startIndex = index - loadBuffer>0?index - loadBuffer:0;
|
||||
// endIndex = startIndex + loadCount;
|
||||
// }
|
||||
if (endIndex > data.length) {
|
||||
endIndex = data.length;
|
||||
}
|
||||
|
@ -338,12 +304,6 @@ export default function bigData(Table) {
|
|||
this.endIndex = endIndex;
|
||||
this.setState({ needRender: !needRender });
|
||||
}
|
||||
// console.log(
|
||||
// "===================",
|
||||
// "**index**" + index,
|
||||
// " **startIndex**" + this.startIndex,
|
||||
// "**endIndex**" + this.endIndex
|
||||
// );
|
||||
}
|
||||
// 向上滚动,当前的index是否已经加载(currentIndex),若干上临界值小于startIndex则重新渲染
|
||||
if (!isOrder && index < startIndex + rowDiff) {
|
||||
|
@ -401,33 +361,61 @@ export default function bigData(Table) {
|
|||
return parentIndex;
|
||||
}
|
||||
|
||||
onExpand = (expandState, record) => {
|
||||
onExpand = (expandState, record,index) => {
|
||||
const _this = this;
|
||||
let {expandedRowKeys = []} = _this;
|
||||
const {needRender} = _this.state;
|
||||
const rowKey = _this.getRowKey(record, index);
|
||||
// 记录展开子表行的key
|
||||
// 展开
|
||||
if (expandState) {
|
||||
record.children &&
|
||||
record.children.forEach((item, index) => {
|
||||
_this.expandChildRowKeys.push(_this.getRowKey(item, index));
|
||||
});
|
||||
} else {
|
||||
// 收起
|
||||
record.children &&
|
||||
record.children.forEach((item, index) => {
|
||||
_this.expandChildRowKeys.splice(
|
||||
_this.expandChildRowKeys.findIndex(
|
||||
fitem => fitem.key === item.key
|
||||
),
|
||||
1
|
||||
);
|
||||
});
|
||||
if( record.children){
|
||||
if (expandState) {
|
||||
record.children.forEach((item, index) => {
|
||||
_this.expandChildRowKeys.push(rowKey);
|
||||
});
|
||||
|
||||
} else {
|
||||
// 收起
|
||||
record.children.forEach((item, index) => {
|
||||
_this.expandChildRowKeys.splice(
|
||||
_this.expandChildRowKeys.findIndex(
|
||||
fitem => fitem.key === item.key
|
||||
),
|
||||
1
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//滚动加载expandedRowKeys自己维护,否则有展开不全的问题
|
||||
if(!_this.props.expandedRowKeys){
|
||||
if(expandState){
|
||||
expandedRowKeys.push(rowKey);
|
||||
|
||||
}else{
|
||||
let index = -1;
|
||||
expandedRowKeys.forEach((r, i) => {
|
||||
if (r === rowKey) {
|
||||
index = i;
|
||||
}
|
||||
});
|
||||
if (index !== -1) {
|
||||
expandedRowKeys.splice(index, 1);
|
||||
this.setState({ needRender: !needRender });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// expandState为true时,记录下
|
||||
_this.props.onExpand(expandState, record);
|
||||
};
|
||||
|
||||
|
||||
render() {
|
||||
const { data } = this.props;
|
||||
const { scrollTop } = this;
|
||||
let { endIndex, startIndex } = this;
|
||||
let expandedRowKeys = this.props.expandedRowKeys?this.props.expandedRowKeys: this.expandedRowKeys;
|
||||
if(startIndex < 0){
|
||||
startIndex = 0;
|
||||
}
|
||||
|
@ -466,7 +454,7 @@ export default function bigData(Table) {
|
|||
lazyLoad.preHeight = this.getSumHeight(0, startIndex);
|
||||
lazyLoad.sufHeight = this.getSumHeight(endIndex, data.length);
|
||||
}
|
||||
// console.log('*******ScrollTop*****'+scrollTop);
|
||||
// console.log('*******expandedRowKeys*****'+expandedRowKeys);
|
||||
return (
|
||||
<Table
|
||||
{...this.props}
|
||||
|
@ -478,6 +466,7 @@ export default function bigData(Table) {
|
|||
setRowParentIndex={this.setRowParentIndex}
|
||||
onExpand={this.onExpand}
|
||||
onExpandedRowsChange={this.onExpandedRowsChange}
|
||||
expandedRowKeys={expandedRowKeys}
|
||||
// className={'lazy-table'}
|
||||
/>
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue