|
@ -59,6 +59,7 @@ export default class Table extends React.Component { |
|
|
onChange: noop, |
|
|
onChange: noop, |
|
|
locale: {}, |
|
|
locale: {}, |
|
|
rowKey: 'key', |
|
|
rowKey: 'key', |
|
|
|
|
|
childrenColumnName: 'children', |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static contextTypes = { |
|
|
static contextTypes = { |
|
@ -717,18 +718,23 @@ export default class Table extends React.Component { |
|
|
return flatArray(this.getCurrentPageData()); |
|
|
return flatArray(this.getCurrentPageData()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
recursiveSort(data, sorterFn) { |
|
|
|
|
|
const { childrenColumnName } = this.props; |
|
|
|
|
|
return data.sort(sorterFn).map(item => (item[childrenColumnName] ? { |
|
|
|
|
|
...item, |
|
|
|
|
|
[childrenColumnName]: this.recursiveSort(item[childrenColumnName], sorterFn), |
|
|
|
|
|
} : item)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
getLocalData() { |
|
|
getLocalData() { |
|
|
const state = this.state; |
|
|
const state = this.state; |
|
|
const { dataSource, childrenColumnName } = this.props; |
|
|
const { dataSource } = this.props; |
|
|
let data = dataSource || []; |
|
|
let data = dataSource || []; |
|
|
// 优化本地排序 |
|
|
// 优化本地排序 |
|
|
data = data.slice(0); |
|
|
data = data.slice(0); |
|
|
const sorterFn = this.getSorterFn(); |
|
|
const sorterFn = this.getSorterFn(); |
|
|
if (sorterFn) { |
|
|
if (sorterFn) { |
|
|
data = data.sort(sorterFn).map(dataItem => (dataItem[childrenColumnName] ? { |
|
|
data = this.recursiveSort(data, sorterFn); |
|
|
...dataItem, |
|
|
|
|
|
[childrenColumnName]: dataItem[childrenColumnName].sort(sorterFn), |
|
|
|
|
|
} : dataItem)); |
|
|
|
|
|
} |
|
|
} |
|
|
// 筛选 |
|
|
// 筛选 |
|
|
if (state.filters) { |
|
|
if (state.filters) { |
|
|