fix: 默认前端排序点击分页后数据不更新
This commit is contained in:
parent
287758057f
commit
b2362185f5
|
@ -460,8 +460,8 @@
|
||||||
-moz-user-select: -moz-none;
|
-moz-user-select: -moz-none;
|
||||||
-khtml-user-select: none;
|
-khtml-user-select: none;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
/*
|
/*
|
||||||
Introduced in IE 10.
|
Introduced in IE 10.
|
||||||
*/
|
*/
|
||||||
-ms-user-select: none;
|
-ms-user-select: none;
|
||||||
user-select: none; }
|
user-select: none; }
|
||||||
|
|
|
@ -465,9 +465,10 @@ var Table = function (_Component) {
|
||||||
this.bodyTable.scrollTop = this.scrollTop;
|
this.bodyTable.scrollTop = this.scrollTop;
|
||||||
this.scrollTop = -1;
|
this.scrollTop = -1;
|
||||||
}
|
}
|
||||||
if (prevProps.data.length === 0 || this.props.data.length === 0) {
|
// 当表格没有数据时,重置滚动条位置,造成grid里面的表头列无法操作
|
||||||
this.resetScrollX();
|
// if (prevProps.data.length === 0 || this.props.data.length === 0 ) {
|
||||||
}
|
// this.resetScrollX();
|
||||||
|
// }
|
||||||
|
|
||||||
// 是否传入 scroll中的y属性,如果传入判断是否是整数,如果是则进行比较 。bodyTable 的clientHeight进行判断
|
// 是否传入 scroll中的y属性,如果传入判断是否是整数,如果是则进行比较 。bodyTable 的clientHeight进行判断
|
||||||
this.isShowScrollY();
|
this.isShowScrollY();
|
||||||
|
@ -790,7 +791,8 @@ var Table = function (_Component) {
|
||||||
var _props3 = this.props,
|
var _props3 = this.props,
|
||||||
clsPrefix = _props3.clsPrefix,
|
clsPrefix = _props3.clsPrefix,
|
||||||
expandIconAsCell = _props3.expandIconAsCell,
|
expandIconAsCell = _props3.expandIconAsCell,
|
||||||
onPaste = _props3.onPaste;
|
onPaste = _props3.onPaste,
|
||||||
|
getCellClassName = _props3.getCellClassName;
|
||||||
|
|
||||||
var colCount = void 0;
|
var colCount = void 0;
|
||||||
if (fixed === 'left') {
|
if (fixed === 'left') {
|
||||||
|
@ -844,7 +846,8 @@ var Table = function (_Component) {
|
||||||
useDragHandle: this.props.useDragHandle,
|
useDragHandle: this.props.useDragHandle,
|
||||||
onDragRow: this.onDragRow,
|
onDragRow: this.onDragRow,
|
||||||
onDragRowStart: this.onDragRowStart,
|
onDragRowStart: this.onDragRowStart,
|
||||||
height: expandedRowHeight
|
height: expandedRowHeight,
|
||||||
|
getCellClassName: getCellClassName
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1020,7 +1023,8 @@ var Table = function (_Component) {
|
||||||
lazyEndIndex: lazyEndIndex,
|
lazyEndIndex: lazyEndIndex,
|
||||||
centerColumnsLength: this.centerColumnsLength,
|
centerColumnsLength: this.centerColumnsLength,
|
||||||
leftColumnsLength: this.leftColumnsLength,
|
leftColumnsLength: this.leftColumnsLength,
|
||||||
expandIconCellWidth: expandIconCellWidth
|
expandIconCellWidth: expandIconCellWidth,
|
||||||
|
getCellClassName: props.getCellClassName
|
||||||
})));
|
})));
|
||||||
this.treeRowIndex++;
|
this.treeRowIndex++;
|
||||||
var subVisible = visible && isRowExpanded;
|
var subVisible = visible && isRowExpanded;
|
||||||
|
|
|
@ -336,7 +336,8 @@ var TableCell = function (_Component) {
|
||||||
showSum = _props2.showSum,
|
showSum = _props2.showSum,
|
||||||
bodyDisplayInRow = _props2.bodyDisplayInRow,
|
bodyDisplayInRow = _props2.bodyDisplayInRow,
|
||||||
lazyStartIndex = _props2.lazyStartIndex,
|
lazyStartIndex = _props2.lazyStartIndex,
|
||||||
lazyEndIndex = _props2.lazyEndIndex;
|
lazyEndIndex = _props2.lazyEndIndex,
|
||||||
|
getCellClassName = _props2.getCellClassName;
|
||||||
|
|
||||||
var dataIndex = column.dataIndex,
|
var dataIndex = column.dataIndex,
|
||||||
render = column.render,
|
render = column.render,
|
||||||
|
@ -456,6 +457,12 @@ var TableCell = function (_Component) {
|
||||||
if (colMenu) {
|
if (colMenu) {
|
||||||
className += ' u-table-inline-icon';
|
className += ' u-table-inline-icon';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof getCellClassName == 'function') {
|
||||||
|
var selfClassName = getCellClassName(record, index, column) || '';
|
||||||
|
className += ' ' + selfClassName;
|
||||||
|
}
|
||||||
|
|
||||||
if (colSpan == 0) return null;
|
if (colSpan == 0) return null;
|
||||||
return _react2["default"].createElement(
|
return _react2["default"].createElement(
|
||||||
'td',
|
'td',
|
||||||
|
|
|
@ -588,7 +588,8 @@ var TableRow = function (_Component) {
|
||||||
hoverKey = _props10.hoverKey,
|
hoverKey = _props10.hoverKey,
|
||||||
lazyStartIndex = _props10.lazyStartIndex,
|
lazyStartIndex = _props10.lazyStartIndex,
|
||||||
lazyEndIndex = _props10.lazyEndIndex,
|
lazyEndIndex = _props10.lazyEndIndex,
|
||||||
expandIconCellWidth = _props10.expandIconCellWidth;
|
expandIconCellWidth = _props10.expandIconCellWidth,
|
||||||
|
getCellClassName = _props10.getCellClassName;
|
||||||
var notRowDrag = this.state.notRowDrag;
|
var notRowDrag = this.state.notRowDrag;
|
||||||
|
|
||||||
var showSum = false;
|
var showSum = false;
|
||||||
|
@ -651,7 +652,8 @@ var TableRow = function (_Component) {
|
||||||
lazyEndIndex: lazyEndIndex,
|
lazyEndIndex: lazyEndIndex,
|
||||||
onPaste: onPaste,
|
onPaste: onPaste,
|
||||||
stopRowDrag: this.stopRowDrag,
|
stopRowDrag: this.stopRowDrag,
|
||||||
col: i
|
col: i,
|
||||||
|
getCellClassName: getCellClassName
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
var style = _extends({ height: height }, record ? record.style : undefined);
|
var style = _extends({ height: height }, record ? record.style : undefined);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", {
|
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; };
|
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) {
|
function dragColumn(Table) {
|
||||||
|
|
||||||
return function (_Component) {
|
return function (_Component) {
|
||||||
_inherits(DragColumn, _Component);
|
_inherits(DragColumn, _Component);
|
||||||
|
|
||||||
function DragColumn(props) {
|
function DragColumn(props) {
|
||||||
_classCallCheck(this, DragColumn);
|
_classCallCheck(this, DragColumn);
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
||||||
|
|
||||||
_this.setColumOrderByIndex = function (_column) {
|
_this.setColumOrderByIndex = function (_column) {
|
||||||
_column.forEach(function (da, i) {
|
_column.forEach(function (da, i) {
|
||||||
da.dragIndex = i;
|
da.dragIndex = i;
|
||||||
da.drgHover = false;
|
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;
|
|
||||||
});
|
});
|
||||||
|
return _column;
|
||||||
|
};
|
||||||
|
|
||||||
DragColumn.prototype.render = function render() {
|
_this.onDragEnd = function (event, data) {
|
||||||
var _props = this.props,
|
var dragSource = data.dragSource,
|
||||||
data = _props.data,
|
dragTarg = data.dragTarg;
|
||||||
dragborder = _props.dragborder,
|
var columns = _this.state.columns;
|
||||||
draggable = _props.draggable,
|
|
||||||
className = _props.className,
|
|
||||||
others = _objectWithoutProperties(_props, ['data', 'dragborder', 'draggable', 'className']);
|
|
||||||
|
|
||||||
return _react2["default"].createElement(Table, _extends({}, others, {
|
var sourceIndex = -1,
|
||||||
columns: this.state.columns,
|
targetIndex = -1;
|
||||||
data: data,
|
|
||||||
className: className + ' u-table-drag-border',
|
|
||||||
onDragEnd: this.onDragEnd,
|
|
||||||
draggable: draggable,
|
|
||||||
dragborder: dragborder
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
return DragColumn;
|
sourceIndex = columns.findIndex(function (da, i) {
|
||||||
}(_react.Component);
|
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'];
|
module.exports = exports['default'];
|
|
@ -57,31 +57,34 @@ function sort(Table, Icon) {
|
||||||
var flatColumns = [];
|
var flatColumns = [];
|
||||||
_this2._toFlatColumn(props.columns, -1, flatColumns);
|
_this2._toFlatColumn(props.columns, -1, flatColumns);
|
||||||
_this2.state = { data: _this2.props.data, columns: props.columns, flatColumns: flatColumns };
|
_this2.state = { data: _this2.props.data, columns: props.columns, flatColumns: flatColumns };
|
||||||
|
_this2._initSort();
|
||||||
return _this2;
|
return _this2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//默认是前端排序,值为true为后端排序
|
//默认是前端排序,值为true为后端排序
|
||||||
|
|
||||||
SortTable.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
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) {
|
if (nextProps.columns !== this.props.columns) {
|
||||||
var flatColumns = [];
|
var flatColumns = [];
|
||||||
this._toFlatColumn(nextProps.columns, -1, flatColumns);
|
this._toFlatColumn(nextProps.columns, -1, flatColumns);
|
||||||
this.setState({ columns: nextProps.columns, flatColumns: 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扁平化处理,适应多表头避免递归操作
|
*column扁平化处理,适应多表头避免递归操作
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
SortTable.prototype._toFlatColumn = function _toFlatColumn(columns) {
|
SortTable.prototype._toFlatColumn = function _toFlatColumn(columns) {
|
||||||
var parentIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
|
var parentIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
|
||||||
var flatColumns = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
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() {
|
}(_react.Component), _class.defaultProps = { sort: { mode: "single", backSource: false } }, _initialiseProps = function _initialiseProps() {
|
||||||
var _this3 = this;
|
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 () {
|
this.getOrderNum = function () {
|
||||||
var orderNum = 0;
|
var orderNum = 0;
|
||||||
//todo 1
|
//todo 1
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", {
|
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; };
|
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) {
|
function sortBy(arr, prop, desc) {
|
||||||
var props = [],
|
var props = [],
|
||||||
ret = [],
|
ret = [],
|
||||||
i = 0,
|
i = 0,
|
||||||
len = arr.length;
|
len = arr.length;
|
||||||
if (typeof prop == 'string') {
|
if (typeof prop == 'string') {
|
||||||
for (; i < len; i++) {
|
for (; i < len; i++) {
|
||||||
var oI = arr[i];
|
var oI = arr[i];
|
||||||
(props[i] = new String(oI && oI[prop] || ''))._obj = oI;
|
(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') {
|
props.sort();
|
||||||
for (; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
var _oI = arr[i];
|
ret[i] = props[i]._obj;
|
||||||
(props[i] = new String(_oI && prop(_oI) || ''))._obj = _oI;
|
|
||||||
}
|
}
|
||||||
} else {
|
if (desc) ret.reverse();
|
||||||
throw '参数类型错误';
|
return ret;
|
||||||
}
|
|
||||||
props.sort();
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
ret[i] = props[i]._obj;
|
|
||||||
}
|
|
||||||
if (desc) ret.reverse();
|
|
||||||
return ret;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,11 +51,11 @@ function sortBy(arr, prop, desc) {
|
||||||
* @param {} property
|
* @param {} property
|
||||||
*/
|
*/
|
||||||
function compare(property) {
|
function compare(property) {
|
||||||
return function (a, b) {
|
return function (a, b) {
|
||||||
var value1 = a[property];
|
var value1 = a[property];
|
||||||
var value2 = b[property];
|
var value2 = b[property];
|
||||||
return value1 - value2;
|
return value1 - value2;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,17 +63,17 @@ function compare(property) {
|
||||||
* @param {*} obj 要拷贝的对象
|
* @param {*} obj 要拷贝的对象
|
||||||
*/
|
*/
|
||||||
function ObjectAssign(obj) {
|
function ObjectAssign(obj) {
|
||||||
var b = obj instanceof Array;
|
var b = obj instanceof Array;
|
||||||
var tagObj = b ? [] : {};
|
var tagObj = b ? [] : {};
|
||||||
if (b) {
|
if (b) {
|
||||||
//数组
|
//数组
|
||||||
obj.forEach(function (da) {
|
obj.forEach(function (da) {
|
||||||
var _da = {};
|
var _da = {};
|
||||||
_extends(_da, da);
|
_extends(_da, da);
|
||||||
tagObj.push(_da);
|
tagObj.push(_da);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
_extends(tagObj, obj);
|
_extends(tagObj, obj);
|
||||||
}
|
}
|
||||||
return tagObj;
|
return tagObj;
|
||||||
}
|
}
|
|
@ -43,8 +43,10 @@ export default function sort(Table, Icon) {
|
||||||
this.setState({
|
this.setState({
|
||||||
data: nextProps.data,
|
data: nextProps.data,
|
||||||
oldData: nextProps.data.concat()
|
oldData: nextProps.data.concat()
|
||||||
|
}, function(){
|
||||||
|
this._initSort(); // 数据更新后需要重新排序
|
||||||
});
|
});
|
||||||
this._initSort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue