mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
Improve table ajax dataSource
1. Add ajax data params support 2. improve dataSource.clone for new config
This commit is contained in:
parent
6bba4f755c
commit
f5afbf16aa
@ -60,7 +60,7 @@ var dataSource = new Table.DataSource({
|
||||
}
|
||||
});
|
||||
|
||||
var Test=React.createClass({
|
||||
var Test = React.createClass({
|
||||
getInitialState() {
|
||||
return {
|
||||
dataSource: dataSource
|
||||
@ -68,14 +68,28 @@ var Test=React.createClass({
|
||||
},
|
||||
refresh() {
|
||||
this.setState({
|
||||
dataSource: this.state.dataSource.clone()
|
||||
dataSource: dataSource.clone()
|
||||
});
|
||||
},
|
||||
changeAndRefresh() {
|
||||
// 可以修改原来的 dataSource 再发请求
|
||||
this.setState({
|
||||
dataSource: dataSource.clone({
|
||||
data: {
|
||||
city: 'hz'
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
render() {
|
||||
return <div>
|
||||
<Table columns={columns} dataSource={this.state.dataSource} />
|
||||
<button className="ant-btn ant-btn-primary" onClick={this.refresh}>
|
||||
外部重新加载数据
|
||||
重新加载数据
|
||||
</button>
|
||||
|
||||
<button className="ant-btn" onClick={this.changeAndRefresh}>
|
||||
加载 city=hz 的数据
|
||||
</button>
|
||||
</div>;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ class DataSource {
|
||||
this.getParams = config.getParams || noop;
|
||||
this.getPagination = config.getPagination || noop;
|
||||
this.headers = config.headers || {};
|
||||
this.data = config.data || {};
|
||||
}
|
||||
|
||||
constructor(config) {
|
||||
@ -31,10 +32,12 @@ class DataSource {
|
||||
}
|
||||
}
|
||||
|
||||
clone() {
|
||||
var d = new DataSource();
|
||||
d.init(this.config);
|
||||
return d;
|
||||
clone(config) {
|
||||
if (config) {
|
||||
return new DataSource(objectAssign(config, this.config));
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -358,9 +361,10 @@ var AntTable = React.createClass({
|
||||
}
|
||||
// remote 模式使用 this.dataSource
|
||||
let dataSource = this.getRemoteDataSource();
|
||||
let buildInParams = dataSource.getParams.apply(this, this.prepareParamsArguments(state)) || {};
|
||||
return jQuery.ajax({
|
||||
url: dataSource.url,
|
||||
data: dataSource.getParams.apply(this, this.prepareParamsArguments(state)) || {},
|
||||
data: objectAssign(buildInParams, dataSource.data),
|
||||
headers: dataSource.headers,
|
||||
dataType: 'json',
|
||||
success: (result) => {
|
||||
|
Loading…
Reference in New Issue
Block a user