Sov*_*sra 7 pagination web angular2-services ng2-smart-table angular
我正在使用启用了Pager的后端服务器(Java Spring).我在HTTP调用上每页加载100条记录.
在angular2服务上,它使用"?page = 1&size = 100"作为初始调用的API调用,而在客户端大小的寻呼机上,它显示10并且最多移动10页,这很好.但我无法从服务器加载下一块数据.我检查了ServerDataSource并使用了.setPaging(1,100).
如何加载下一个数据块(2-200)以及如何实现此目的.任何提示都会有所帮助.
@Injectable()
export class AmazonService extends ServerDataSource {
constructor(protected http: Http) {
super(http);
}
public getAmazonInformation(page, size): Observable<Amazon[]> {
let url = 'http://localhost:8080/plg-amazon?page=1&size=100';
this.setPaging(1, 100, true);
if (this.pagingConf && this.pagingConf['page'] &&
this.pagingConf['perPage']) {
url +=
`page=${this.pagingConf['page']}&size=${this.pagingConf['perPage']}`;
}
return this.http.get(url).map(this.extractData).catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我用LocalDataSource.
HTML :
<ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>
Run Code Online (Sandbox Code Playgroud)
TS :
source: LocalDataSource = new LocalDataSource();
pageSize = 25;
ngOnInit() {
this.source.onChanged().subscribe((change) => {
if (change.action === 'page') {
this.pageChange(change.paging.page);
}
});
}
pageChange(pageIndex) {
const loadedRecordCount = this.source.count();
const lastRequestedRecordIndex = pageIndex * this.pageSize;
if (loadedRecordCount <= lastRequestedRecordIndex) {
let myFilter; //This is your filter.
myFilter.startIndex = loadedRecordCount + 1;
myFilter.recordCount = this.pageSize + 100; //extra 100 records improves UX.
this.myService.getData(myFilter) //.toPromise()
.then(data => {
if (this.source.count() > 0){
data.forEach(d => this.source.add(d));
this.source.getAll()
.then(d => this.source.load(d))
}
else
this.source.load(data);
})
}
}
Run Code Online (Sandbox Code Playgroud)
尝试像这样将设置设置为智能表
<ng2-smart-table #grid [settings]="settings" ... >
Run Code Online (Sandbox Code Playgroud)
在您的组件中,定义设置,如下所示:
<ng2-smart-table #grid [settings]="settings" ... >
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5550 次 |
| 最近记录: |