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

  • 为了获取和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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值