fix: 默认前端排序点击分页后数据不更新

This commit is contained in:
izbz wh 2020-11-02 14:17:11 +08:00
parent 287758057f
commit b2362185f5
8 changed files with 201 additions and 165 deletions

View File

@ -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;

View File

@ -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',

View File

@ -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);

View File

@ -1,7 +1,7 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
@ -35,115 +35,115 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
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.onDragEnd = 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;
});
// 向前移动
if (targetIndex < sourceIndex) {
targetIndex = targetIndex + 1;
}
columns.splice(targetIndex, 0, columns.splice(sourceIndex, 1)[0]);
var _newColumns = [];
columns.forEach(function (da, i) {
var newDate = _extends(da, {});
newDate.title = da.title;
_newColumns.push(newDate);
});
_this.setState({
columns: _newColumns //cloneDeep(columns)
});
if (_this.props.onDragEnd) {
_this.props.onDragEnd(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.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,
others = _objectWithoutProperties(_props, ['data', 'dragborder', 'draggable', 'className']);
_this.onDragEnd = function (event, data) {
var dragSource = data.dragSource,
dragTarg = data.dragTarg;
var columns = _this.state.columns;
return _react2["default"].createElement(Table, _extends({}, others, {
columns: this.state.columns,
data: data,
className: className + ' u-table-drag-border',
onDragEnd: this.onDragEnd,
draggable: draggable,
dragborder: dragborder
}));
};
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;
});
// 向前移动
if (targetIndex < sourceIndex) {
targetIndex = targetIndex + 1;
}
columns.splice(targetIndex, 0, columns.splice(sourceIndex, 1)[0]);
var _newColumns = [];
columns.forEach(function (da, i) {
var newDate = _extends(da, {});
newDate.title = da.title;
_newColumns.push(newDate);
});
_this.setState({
columns: _newColumns //cloneDeep(columns)
});
if (_this.props.onDragEnd) {
_this.props.onDragEnd(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.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,
others = _objectWithoutProperties(_props, ['data', 'dragborder', 'draggable', 'className']);
return _react2["default"].createElement(Table, _extends({}, others, {
columns: this.state.columns,
data: data,
className: className + ' u-table-drag-border',
onDragEnd: this.onDragEnd,
draggable: draggable,
dragborder: dragborder
}));
};
return DragColumn;
}(_react.Component);
}
module.exports = exports['default'];

View File

@ -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

View File

@ -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;
}

View File

@ -43,8 +43,10 @@ export default function sort(Table, Icon) {
this.setState({
data: nextProps.data,
oldData: nextProps.data.concat()
}, function(){
this._initSort(); // 数据更新后需要重新排序
});
this._initSort();
}
}