沈斌
2017-12-15 f9b157566af34b8dc28ba10b34d025ac04f3168b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// tslint:disable:member-ordering
import { Component, OnInit } from '@angular/core';
import { RandomUserService } from '../randomUser.service';
import { NzMessageService } from 'ng-zorro-antd';
 
@Component({
    selector: 'app-table-standard',
    templateUrl: './standard.component.html'
})
export class TableStandardComponent implements OnInit {
 
    data = [
        {
            key: '1',
            name: 'John Brown',
            age: 32,
            address: 'New York No. 1 Lake Park',
        }, {
            key: '2',
            name: 'Jim Green',
            age: 42,
            address: 'London No. 1 Lake Park',
        }, {
            key: '3',
            name: 'Joe Black',
            age: 32,
            address: 'Sidney No. 1 Lake Park',
        }
    ];
 
    ageSort = '';
 
    ageSortChange($event) {
        if ($event === 'ascend') {
            this.data = [...this.data.sort((a, b) => {
                return a.age - b.age;
            })];
        } else if ($event === 'descend') {
            this.data = [...this.data.sort((a, b) => {
                return b.age - a.age;
            })];
        }
    }
 
    _allChecked = false;
    _indeterminate = false;
    _displayData = [];
 
    _displayDataChange($event) {
        this._displayData = $event;
        this._refreshStatus();
    }
 
    _refreshStatus() {
        const allChecked = this._displayData.every(value => value.checked === true);
        const allUnChecked = this._displayData.every(value => !value.checked);
        this._allChecked = allChecked;
        this._indeterminate = (!allChecked) && (!allUnChecked);
    }
 
    _checkAll(value) {
        if (value) {
            this._displayData.forEach(data => {
                data.checked = true;
            });
        } else {
            this._displayData.forEach(data => {
                data.checked = false;
            });
        }
        this._refreshStatus();
    }
 
    // ajax
    _current = 1;
    _pageSize = 3;
    _total = 1;
    _ajaxDataSet = [];
    _ajaxLoading = true;
 
    constructor(private _randomUser: RandomUserService, private message: NzMessageService) { }
 
    _ajaxRefreshData = () => {
        this._ajaxLoading = true;
        this._randomUser.getUsers(this._current, this._pageSize).subscribe((data: any) => {
            this._ajaxLoading = false;
            this._total = 200;
            this._ajaxDataSet = data.results;
        });
    }
 
    ngOnInit() {
        this._ajaxRefreshData();
 
        this._genData();
    }
 
    // dynamic
    _dataSet = [];
    _bordered = false;
    _loading = false;
    _pagination = true;
    _header = true;
    _title = true;
    _footer = true;
    _size = 'small';
    _noresult = false;
 
    _toggleData() {
        if (this._noresult) {
            this._dataSet = [];
        } else {
            this._genData();
        }
    }
 
    _genData() {
        this._dataSet = [];
        for (let i = 1; i <= 10; i++) {
            this._dataSet.push({
                key: i,
                name: 'John Brown',
                age: `${i}2`,
                address: `New York No. ${i} Lake Park`,
                description: `My name is John Brown, I am ${i}2 years old, living in New York No. ${i} Lake Park.`,
            });
        }
    }
 
    cancel = function () {
        this.message.info('click cancel');
    };
 
    confirm = () => {
        this.message.success('click confirm');
    }
}