fix: 默认前端排序点击分页后数据不更新
This commit is contained in:
parent
287758057f
commit
b2362185f5
|
@ -465,9 +465,10 @@ var Table = function (_Component) {
|
|||
this.bodyTable.scrollTop = this.scrollTop;
|
||||
this.scrollTop = -1;
|
||||
}
|
||||
if (prevProps.data.length === 0 || this.props.data.length === 0) {
|
||||
this.resetScrollX();
|
||||
}
|
||||
// 当表格没有数据时,重置滚动条位置,造成grid里面的表头列无法操作
|
||||
// if (prevProps.data.length === 0 || this.props.data.length === 0 ) {
|
||||
// this.resetScrollX();
|
||||
// }
|
||||
|
||||
// 是否传入 scroll中的y属性,如果传入判断是否是整数,如果是则进行比较 。bodyTable 的clientHeight进行判断
|
||||
this.isShowScrollY();
|
||||
|
@ -790,7 +791,8 @@ var Table = function (_Component) {
|
|||
var _props3 = this.props,
|
||||
clsPrefix = _props3.clsPrefix,
|
||||
expandIconAsCell = _props3.expandIconAsCell,
|
||||
onPaste = _props3.onPaste;
|
||||
onPaste = _props3.onPaste,
|
||||
getCellClassName = _props3.getCellClassName;
|
||||
|
||||
var colCount = void 0;
|
||||
if (fixed === 'left') {
|
||||
|
@ -844,7 +846,8 @@ var Table = function (_Component) {
|
|||
useDragHandle: this.props.useDragHandle,
|
||||
onDragRow: this.onDragRow,
|
||||
onDragRowStart: this.onDragRowStart,
|
||||
height: expandedRowHeight
|
||||
height: expandedRowHeight,
|
||||
getCellClassName: getCellClassName
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1020,7 +1023,8 @@ var Table = function (_Component) {
|
|||
lazyEndIndex: lazyEndIndex,
|
||||
centerColumnsLength: this.centerColumnsLength,
|
||||
leftColumnsLength: this.leftColumnsLength,
|
||||
expandIconCellWidth: expandIconCellWidth
|
||||
expandIconCellWidth: expandIconCellWidth,
|
||||
getCellClassName: props.getCellClassName
|
||||
})));
|
||||
this.treeRowIndex++;
|
||||
var subVisible = visible && isRowExpanded;
|
||||
|
|
|
@ -336,7 +336,8 @@ var TableCell = function (_Component) {
|
|||
showSum = _props2.showSum,
|
||||
bodyDisplayInRow = _props2.bodyDisplayInRow,
|
||||
lazyStartIndex = _props2.lazyStartIndex,
|
||||
lazyEndIndex = _props2.lazyEndIndex;
|
||||
lazyEndIndex = _props2.lazyEndIndex,
|
||||
getCellClassName = _props2.getCellClassName;
|
||||
|
||||
var dataIndex = column.dataIndex,
|
||||
render = column.render,
|
||||
|
@ -456,6 +457,12 @@ var TableCell = function (_Component) {
|
|||
if (colMenu) {
|
||||
className += ' u-table-inline-icon';
|
||||
}
|
||||
|
||||
if (typeof getCellClassName == 'function') {
|
||||
var selfClassName = getCellClassName(record, index, column) || '';
|
||||
className += ' ' + selfClassName;
|
||||
}
|
||||
|
||||
if (colSpan == 0) return null;
|
||||
return _react2["default"].createElement(
|
||||
'td',
|
||||
|
|
|
@ -588,7 +588,8 @@ var TableRow = function (_Component) {
|
|||
hoverKey = _props10.hoverKey,
|
||||
lazyStartIndex = _props10.lazyStartIndex,
|
||||
lazyEndIndex = _props10.lazyEndIndex,
|
||||
expandIconCellWidth = _props10.expandIconCellWidth;
|
||||
expandIconCellWidth = _props10.expandIconCellWidth,
|
||||
getCellClassName = _props10.getCellClassName;
|
||||
var notRowDrag = this.state.notRowDrag;
|
||||
|
||||
var showSum = false;
|
||||
|
@ -651,7 +652,8 @@ var TableRow = function (_Component) {
|
|||
lazyEndIndex: lazyEndIndex,
|
||||
onPaste: onPaste,
|
||||
stopRowDrag: this.stopRowDrag,
|
||||
col: i
|
||||
col: i,
|
||||
getCellClassName: getCellClassName
|
||||
}));
|
||||
}
|
||||
var style = _extends({ height: height }, record ? record.style : undefined);
|
||||
|
|
|
@ -57,31 +57,34 @@ function sort(Table, Icon) {
|
|||
var flatColumns = [];
|
||||
_this2._toFlatColumn(props.columns, -1, flatColumns);
|
||||
_this2.state = { data: _this2.props.data, columns: props.columns, flatColumns: flatColumns };
|
||||
|
||||
_this2._initSort();
|
||||
return _this2;
|
||||
}
|
||||
|
||||
//默认是前端排序,值为true为后端排序
|
||||
|
||||
SortTable.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
||||
|
||||
if (nextProps.data !== this.props.data) {
|
||||
this.setState({
|
||||
data: nextProps.data,
|
||||
oldData: nextProps.data.concat()
|
||||
});
|
||||
}
|
||||
if (nextProps.columns !== this.props.columns) {
|
||||
var flatColumns = [];
|
||||
this._toFlatColumn(nextProps.columns, -1, flatColumns);
|
||||
this.setState({ columns: nextProps.columns, flatColumns: flatColumns });
|
||||
}
|
||||
|
||||
if (nextProps.data !== this.props.data) {
|
||||
this.setState({
|
||||
data: nextProps.data,
|
||||
oldData: nextProps.data.concat()
|
||||
}, function () {
|
||||
this._initSort(); // 数据更新后需要重新排序
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*column扁平化处理,适应多表头避免递归操作
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
SortTable.prototype._toFlatColumn = function _toFlatColumn(columns) {
|
||||
var parentIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
|
||||
var flatColumns = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
||||
|
@ -164,6 +167,24 @@ function sort(Table, Icon) {
|
|||
}(_react.Component), _class.defaultProps = { sort: { mode: "single", backSource: false } }, _initialiseProps = function _initialiseProps() {
|
||||
var _this3 = this;
|
||||
|
||||
this._initSort = function () {
|
||||
var flatColumns = _this3.state.flatColumns;
|
||||
|
||||
var needSort = false;
|
||||
flatColumns.forEach(function (item) {
|
||||
if (item.order == 'descend' || item.order == 'ascend') {
|
||||
needSort = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (needSort) {
|
||||
var data = _this3.multiSort(flatColumns);
|
||||
_this3.setState({
|
||||
data: data
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.getOrderNum = function () {
|
||||
var orderNum = 0;
|
||||
//todo 1
|
||||
|
|
|
@ -43,8 +43,10 @@ export default function sort(Table, Icon) {
|
|||
this.setState({
|
||||
data: nextProps.data,
|
||||
oldData: nextProps.data.concat()
|
||||
}, function(){
|
||||
this._initSort(); // 数据更新后需要重新排序
|
||||
});
|
||||
this._initSort();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue