ant-design/components/table/demo/ajax.md

56 lines
1.1 KiB
Markdown
Raw Normal View History

2015-07-09 20:29:26 +08:00
# 动态加载数据
- order: 7
2015-07-09 20:29:26 +08:00
远程读取的表格是**更为常见的模式**,下面的表格使用了 `dataSource` 对象和远程数据源绑定和适配,并具有筛选、排序等功能以及页面 loading 效果。
2015-07-09 20:29:26 +08:00
---
````jsx
2015-07-12 17:10:06 +08:00
var Table = antd.Table;
var columns = [{
title: '姓名',
dataIndex: 'name',
filters: [{
text: '姓李的',
value: '李'
}, {
text: '姓胡的',
value: '胡'
}]
2015-07-12 17:10:06 +08:00
}, {
title: '年龄',
dataIndex: 'age',
sorter: true
2015-07-12 17:10:06 +08:00
}, {
title: '住址',
dataIndex: 'address'
}];
2015-07-12 17:24:03 +08:00
function resolve(result) {
return result.data;
}
var dataSource = {
url: "/components/table/demo/data.json",
resolve: function(result) {
return result.data;
2015-07-14 17:58:00 +08:00
},
// 和后台接口返回的分页数据进行适配
getPagination: function(result) {
return {
total: result.totalCount,
pageSize: result.pageSize
}
},
getParams: function(pagination, filters, sorters) {
let params = {};
console.log(pagination, filters, sorters);
return params;
}
};
React.render(<Table columns={columns} dataSource={dataSource} />
2015-07-12 17:10:06 +08:00
, document.getElementById('components-table-demo-ajax'));
2015-07-09 20:29:26 +08:00
````