```javascript
import { Observable, of } from 'rxjs';
import { delay } from 'rxjs/operators';
import { Injectable, InjectionToken, Optional, Inject } from '@angular/core';
import { RestService, DataResult } from '@farris/ui-datagrid';
import { DemoDataSeed } from './demo-data-seed';

export const RECORD_COUNT = new InjectionToken('demo data record total.');
interface IServerResponse {
    items: string[];
    total: number;
}
@Injectable({
    providedIn: 'root'
})
export class DemoDataService implements RestService {

    data: any[];
    private datacount = 1000;
    get dataLength() {
        return this.datacount;
    }

    set dataLength(count) {
        this.datacount = count;
        this.data = this.createData(count);
    }


    constructor(@Optional() @Inject(RECORD_COUNT) recordCount?: number) {
        recordCount = recordCount || this.datacount;
        this.data = this.createData(recordCount);
    }

    private compare(a, b) {
        return a === b ? 0 : (a > b ? 1 : -1);
    }

    getData(url: string, param?: any): Observable<DataResult> {
        const pageSize = param.pageSize;
        const start = (param.pageIndex - 1) * pageSize;
        const sortName = param.sortName;
        const sortOrder = param.sortOrder;
        const end = start + pageSize;
        const total = this.data.length;
        if (sortName) {
            this.data = this.data.sort((r1, r2) => {
                let r = 0;
                const sortFields = sortName.split(',');
                const orders = sortOrder.split(',');
                for (let i = 0; i < sortFields.length; i++) {
                    const sn = sortFields[i];
                    const so = orders[i];
                    r = this.compare(r1[sn], r2[sn]) * (so === 'asc' ? 1 : -1);
                    if (r !== 0) {
                        return r;
                    }
                }
                return r;
            });
        }
        return of({
            items: this.data.slice(start, end),
            total,
            pageSize,
            pageIndex: param.pageIndex
        }).pipe(delay(1000));
    }

    createData(len: number) {
        const arr = [];
        for (let i = 0; i < len; i++) {
            const k = i + 1;
            arr.push({
                id: k,
                name: DemoDataSeed.userNames[DemoDataSeed.randomNum(0, 19)],
                sex: DemoDataSeed.getXingBie(),
                birthday: DemoDataSeed.getFullDate(),
                maray: [true, false][DemoDataSeed.randomNum(0, 1)],
                city: '',
                addr: this.buildLongText(i, `天齐/大\\道${7000 + i}号`),
                company: DemoDataSeed.getCompany(),
                nianxin: Math.round(Math.random() * 10000) * 12,
                zhiwei: DemoDataSeed.getZhiWei(),
                xss:  DemoDataSeed.xssTexts[k % 2]
            });
        }
        this.data = arr;
        return arr;
    }

    createFooterData() {
        const arr = [];
        arr.push({
            id: '合计',
            nianxin: '￥123456'
        });

        arr.push({
            name: '总记录数：',
            sex: '100条'
        });

        return arr;
    }


    buildLongText(index, t: string) {
        if (index % 5 === 0) {
            return t.repeat(5);
        }

        return t;
    }

    serverCall(data: any[], pageIdx: number, pageSize = 10): Observable<IServerResponse> {
        const perPage = pageSize;
        const start = (pageIdx - 1) * perPage;
        const end = start + perPage;
        const total = data.length;
        return of({
            items: data.slice(start, end),
            total
        }).pipe(delay(1000));
    }
}

```