ng2-smart-table with paging from back-end (Spring)

后端 未结 4 1974
说谎
说谎 2021-01-17 20:39

I am using a back-end server (Java Spring) that has Pager enabled. I am loading 100 records per page on a HTTP call.

On angular2 service, it is consuming the API ca

4条回答
  •  清酒与你
    2021-01-17 21:08

    When you have your endpoint for some entity on {endPointBase}/ng2-smart-table, where you are processing key_like request params (i.e: @Requestparam Map to spring data Example) , you can use on client side:

    export class SpringDataSource extends ServerDataSource {
        constructor(http: HttpClient, endPointBase: string) {
            const serverSourceConf = new ServerSourceConf();
            serverSourceConf.dataKey = 'content';
            serverSourceConf.endPoint = endPointBase + `/ng2-smart-table`;
            serverSourceConf.pagerLimitKey = 'size';
            serverSourceConf.pagerPageKey = 'page';
            serverSourceConf.sortFieldKey = 'sort';
            serverSourceConf.totalKey = 'totalElements';
    
            super(http, serverSourceConf);
        }
    
        protected addPagerRequestParams(httpParams: HttpParams): HttpParams {
            const paging = this.getPaging();
            return httpParams
                .set(this.conf.pagerPageKey, (paging.page - 1).toString())
                .set(this.conf.pagerLimitKey, paging.perPage.toString());
        }
    
        protected addSortRequestParams(httpParams: HttpParams): HttpParams {
            const sort: {field: string, direction: string}[] = this.getSort();
    
            sort.forEach((column) => {
                httpParams = httpParams.append(this.conf.sortFieldKey, `${column.field},${column.direction}`);
            });
            return httpParams;
        }
    }
    

提交回复
热议问题