|
|
@@ -5,6 +5,7 @@ import Animate from 'rc-animate';
|
|
|
import {isEqual} from '../utils/BaseUtils.js';
|
|
|
import '../assets/Table/index.less';
|
|
|
import '../assets/Table/animation.less';
|
|
|
+import {sort} from '../utils/BaseUtils.js';
|
|
|
|
|
|
class TableModel extends React.Component {
|
|
|
constructor(props) {
|
|
|
@@ -15,6 +16,39 @@ class TableModel extends React.Component {
|
|
|
data: []
|
|
|
};
|
|
|
this.timerKeys = []; // 定时器key数组
|
|
|
+ this.sorts = []; // 排序规则
|
|
|
+ }
|
|
|
+ // 初始化检索columns,获得排序规则
|
|
|
+ initSort() {
|
|
|
+ // 先重置
|
|
|
+ this.sorts = [];
|
|
|
+
|
|
|
+ let cols = this.columns;
|
|
|
+ let i = 0;
|
|
|
+ for (i; i < cols.length; i++) {
|
|
|
+ let col = cols[i];
|
|
|
+ if (Math.abs(col['sort']) > 0) {
|
|
|
+ this.sorts.push({
|
|
|
+ sortKey: col['dataIndex'],
|
|
|
+ sortLevel: Math.abs(col['sort']), // 仅用于规则排序
|
|
|
+ direction: col['sort'] > 0 ? 1 : -1
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 把排序规则排序
|
|
|
+ sort(this.sorts, [{ key: 'sortLevel', direction: 1 }]);
|
|
|
+ }
|
|
|
+ // 根据sort值分层排序data
|
|
|
+ sortData(data) {
|
|
|
+ let sortArray = this.sorts.map(function (s, i) {
|
|
|
+ return {
|
|
|
+ key: s.sortKey,
|
|
|
+ direction: s.direction
|
|
|
+ };
|
|
|
+ });
|
|
|
+ if (sortArray) { }
|
|
|
+ let sortData = sort(data || [], sortArray);
|
|
|
+ return sortData;
|
|
|
}
|
|
|
// 根据renderName设置每列的render
|
|
|
setColumnsRender(columns) {
|
|
|
@@ -112,7 +146,7 @@ class TableModel extends React.Component {
|
|
|
let thead = node.getElementsByClassName('rc-table-thead')[0];
|
|
|
this.cHeight = node.offsetHeight - title.offsetHeight - thead.offsetHeight;
|
|
|
this.cWidth = node.offsetWidth;
|
|
|
- this.rowCount = (pageSize + 0) || Math.round(this.cHeight / (fontSize / .6));
|
|
|
+ this.rowCount = pageSize || Math.round(this.cHeight / (fontSize / .6));
|
|
|
this.rowHeight = this.cHeight / this.rowCount;
|
|
|
let a = this.newProps.data;
|
|
|
let result = [];
|
|
|
@@ -136,7 +170,7 @@ class TableModel extends React.Component {
|
|
|
intervalFunction: function () {
|
|
|
this.changeData();
|
|
|
}.bind(this),
|
|
|
- intervalTime: this.newProps.refreshInterval * 1000 || 2000
|
|
|
+ intervalTime: this.newProps.refreshInterval * 1000 || 5000
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
@@ -163,6 +197,8 @@ class TableModel extends React.Component {
|
|
|
componentWillMount() {
|
|
|
}
|
|
|
componentDidMount() {
|
|
|
+ this.initSort();
|
|
|
+ this.sortData(this.newProps.data);
|
|
|
this.splitData();
|
|
|
this.setRefresh();
|
|
|
}
|
|
|
@@ -170,7 +206,7 @@ class TableModel extends React.Component {
|
|
|
this.clearInterval();
|
|
|
}
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
- if (isEqual(nextProps.data, this.newProps.data)) {
|
|
|
+ if (isEqual(this.sortData(nextProps.data), this.newProps.data)) {
|
|
|
this.newProps = nextProps;
|
|
|
return;
|
|
|
}
|