feat: 支持表格初始化时根据soter属性进行默认排序

This commit is contained in:
izbz wh 2020-10-30 16:19:12 +08:00
parent 5bb2478cda
commit f346d7a45c
3 changed files with 3667 additions and 4033 deletions

7665
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -27,24 +27,45 @@ export default function sort(Table, Icon) {
let flatColumns = [];
this._toFlatColumn(props.columns,-1,flatColumns);
this.state = { data: this.props.data, columns: props.columns,flatColumns:flatColumns };
this._initSort();
}
static defaultProps = { sort: { mode: "single", backSource: false } }; //默认是前端排序值为true为后端排序
componentWillReceiveProps(nextProps) {
if (nextProps.columns !== this.props.columns) {
let flatColumns = [];
this._toFlatColumn(nextProps.columns,-1,flatColumns);
this.setState({ columns: nextProps.columns ,flatColumns});
}
if (nextProps.data !== this.props.data) {
this.setState({
data: nextProps.data,
oldData: nextProps.data.concat()
});
this._initSort();
}
if (nextProps.columns !== this.props.columns) {
let flatColumns = [];
this._toFlatColumn(nextProps.columns,-1,flatColumns);
this.setState({ columns: nextProps.columns ,flatColumns});
}
_initSort = () => {
const {flatColumns} = this.state;
let needSort = false;
flatColumns.forEach(item => {
if(item.order == 'descend' || item.order == 'ascend') {
needSort = true;
return
}
})
if(needSort) {
const data = this.multiSort(flatColumns)
this.setState({
data
})
}
}
/**
*column扁平化处理适应多表头避免递归操作
*