将值传递给扩展插件 ng2 smart table
Pass value to extends plugin ng2 smart table
我已经检查了分页实现的文档和源代码(高级示例-server.component.ts)。
并且发现它使用的 ServerDataSource 仅通过 HTTP GET (_sort, _limit, _page, etc parameters expose in URL 实现了分页)..... 因为我当前的项目需要使用 POST 将前端参数发送到后端 Restful API,
使用 extends to HTTP post 调用实现,我不知道如何在分页请求中添加额外的参数。我需要将 request_server 传递给 extendsplugin.ts
import { Observable } from 'rxjs/internal/Observable';
import { ServerDataSource } from 'ng2-smart-table';
export class PostServerDataSource extends ServerDataSource {
protected requestElements(): Observable<any> {
let httpParams = this.createRequesParams();
return this.http.post(this.conf.endPoint, request_server, { observe: 'response' });
}
}
anotherComponent.ts
swiftListTable() {
const request_server = { "userType": this.currentUser.role, "authName": this.currentUser.username }
this.source = new PostServerDataSource(this.http,{endPoint: this.service.apiURL + 'swift/pagination', dataKey: 'content', pagerLimitKey:"_limit",
pagerPageKey:"_page",
sortDirKey: "pageable",
sortFieldKey: "pageable",
totalKey:'totalElements'});
}
有两种方法可以处理它,
一种方法是在查询字符串中附加参数并附加到 url,如
this.service.apiURL + 'swift/pagination?param1=p¶m2=q'
其他方法可以在 requestElements 和 swiftListTable 函数中处理它,如下所示。
swiftListTable() {
const request_server = {
"userType": this.currentUser.role,
"authName": this.currentUser.username
}
this.source = new PostServerDataSource(http,
{ endPoint: url, dataKey: 'content', pagerLimitKey:'_limit'}, request_server);
export class PostServerDataSource extends ServerDataSource {
params: any;
constructor(http: HttpClient, config: any, params?: any) {
super(http, config);
this.params = params;
}
protected requestElements(): Observable<any> {
let httpParams = this.createRequesParams();
if (this.params) {
let keys = Object.keys(this.params);
keys.forEach((key) => {
httpParams = httpParams.set(key, this.params[key]);
});
}
return this.http.post(this.conf.endPoint, httpParams, { observe: 'response' });
}
}
我已经检查了分页实现的文档和源代码(高级示例-server.component.ts)。
并且发现它使用的 ServerDataSource 仅通过 HTTP GET (_sort, _limit, _page, etc parameters expose in URL 实现了分页)..... 因为我当前的项目需要使用 POST 将前端参数发送到后端 Restful API,
使用 extends to HTTP post 调用实现,我不知道如何在分页请求中添加额外的参数。我需要将 request_server 传递给 extendsplugin.ts
import { Observable } from 'rxjs/internal/Observable';
import { ServerDataSource } from 'ng2-smart-table';
export class PostServerDataSource extends ServerDataSource {
protected requestElements(): Observable<any> {
let httpParams = this.createRequesParams();
return this.http.post(this.conf.endPoint, request_server, { observe: 'response' });
}
}
anotherComponent.ts
swiftListTable() {
const request_server = { "userType": this.currentUser.role, "authName": this.currentUser.username }
this.source = new PostServerDataSource(this.http,{endPoint: this.service.apiURL + 'swift/pagination', dataKey: 'content', pagerLimitKey:"_limit",
pagerPageKey:"_page",
sortDirKey: "pageable",
sortFieldKey: "pageable",
totalKey:'totalElements'});
}
有两种方法可以处理它, 一种方法是在查询字符串中附加参数并附加到 url,如
this.service.apiURL + 'swift/pagination?param1=p¶m2=q'
其他方法可以在 requestElements 和 swiftListTable 函数中处理它,如下所示。
swiftListTable() {
const request_server = {
"userType": this.currentUser.role,
"authName": this.currentUser.username
}
this.source = new PostServerDataSource(http,
{ endPoint: url, dataKey: 'content', pagerLimitKey:'_limit'}, request_server);
export class PostServerDataSource extends ServerDataSource {
params: any;
constructor(http: HttpClient, config: any, params?: any) {
super(http, config);
this.params = params;
}
protected requestElements(): Observable<any> {
let httpParams = this.createRequesParams();
if (this.params) {
let keys = Object.keys(this.params);
keys.forEach((key) => {
httpParams = httpParams.set(key, this.params[key]);
});
}
return this.http.post(this.conf.endPoint, httpParams, { observe: 'response' });
}
}