您的位置:首页 > Web前端 > AngularJS

获取支持angular2 table 分页排序的公用类

2020-03-26 08:18 1041 查看
  • 为了获取和table属性匹配的数据类型,支持分页,跳转的公用类
import {AppComponentBase} from './app-component-base';
import {Injector, OnInit} from '@angular/core';

export class PagedResultDto {
items: any[];
totalCount: number;
}

export class EntityDto {
id: number;
}

export class PagedRequestDto {
skipCount: number;
maxResultCount: number;
}

export abstract class PagedListingComponentBase<EntityDto> extends AppComponentBase implements OnInit {

public pageSize = 10;
public pageNumber = 1;
public totalPages = 1;
public totalItems: number;
public isTableLoading = false;
public isQuery = false;
public filterText = "";

sortKey = null;
sortValue = null;

protected constructor(injector: Injector) {
super(injector);
}

ngOnInit(): void {
this.refresh();
}

sort(sort: {key: string, value: string }) {
this.sortKey = sort.key;
this.sortValue = sort.value;

this.refresh();
}

refresh(): void {
this.getDataPage(this.pageNumber, this.isQuery);
}

queryRefresh(): void {
this.isQuery = true;
this.pageNumber = 1;
this.getDataPage(this.pageNumber, this.isQuery);
this.isQuery = false;
}

public getSort(): string {
let sorting = '';

if (this.sortKey) {
sorting = this.sortKey;

if (this.sortValue === 'descend') {
sorting += ' DESC';
} else {
sorting += ' ASC';
}
}

return sorting;
}

public showPaging(result: PagedResultDto, pageNumber: number): void {
this.totalPages = ((result.totalCount - (result.totalCount % this.pageSize)) / this.pageSize) + 1;
this.totalItems = result.totalCount;
}

public getDataPage(page: number, isQuery: boolean): void {
let req = new PagedRequestDto();
req.maxResultCount = this.pageSize;
if(isQuery)
{
req.skipCount = 0;
}
else
{
req.skipCount = (page - 1) * this.pageSize;
}

if (req.skipCount < 0) {
req.skipCount = 0;
}

this.isTableLoading = true;
this.list(req, page, () => {
this.isTableLoading = false;
});
}

protected abstract list(request: PagedRequestDto, pageNumber: number, finishedCallback: Function): void;

protected abstract delete(entity: EntityDto): void;
}
  • 点赞
  • 收藏
  • 分享
  • 文章举报
Will Wang0715 发布了62 篇原创文章 · 获赞 0 · 访问量 738 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐