|
1 | 1 | import { Component, OnInit } from '@angular/core'; |
2 | 2 |
|
| 3 | +import { MdlDefaultTableModel, IMdlTableModelItem } from '@angular-mdl/core'; |
| 4 | + |
| 5 | +declare var $: JQueryStatic; |
| 6 | + |
| 7 | +export interface ITableItem extends IMdlTableModelItem { |
| 8 | + name: string; |
| 9 | + sex: string; |
| 10 | + team: string; |
| 11 | + account: string; |
| 12 | + role: string; |
| 13 | + position: string; |
| 14 | +} |
| 15 | + |
3 | 16 | @Component({ |
4 | 17 | selector: 'app-demo1', |
5 | 18 | templateUrl: './demo1.component.html', |
6 | 19 | styleUrls: ['./demo1.component.css'] |
7 | 20 | }) |
8 | 21 | export class Demo1Component implements OnInit { |
9 | 22 |
|
10 | | - constructor() { } |
| 23 | + tableData: [ITableItem] = [ |
| 24 | + { name: '叶秋', sex: '男', team: '兴欣', account: '君莫笑', role: '散人', position: '队长', selected: true }, |
| 25 | + { name: '苏沐橙', sex: '女', team: '兴欣', account: '风梳烟沐', role: '枪炮师', position: '队员', selected: false }, |
| 26 | + { name: '方锐', sex: '男', team: '兴欣', account: '海无量', role: '气功师', position: '队员', selected: false } |
| 27 | + ]; |
11 | 28 |
|
| 29 | + selected: Array<ITableItem> = new Array<ITableItem>(); |
| 30 | + |
| 31 | + public tableModel = new MdlDefaultTableModel([ |
| 32 | + { key: 'name', name: '姓名', sortable: true }, |
| 33 | + { key: 'sex', name: '性别', sortable: true }, |
| 34 | + { key: 'team', name: '队伍', sortable: true }, |
| 35 | + { key: 'account', name: '账号', sortable: true }, |
| 36 | + { key: 'role', name: '角色', sortable: true }, |
| 37 | + { key: 'position', name: '职位', sortable: true }, |
| 38 | + ]); |
| 39 | + text1: string; |
| 40 | + text2: string; |
| 41 | + text3: string; |
| 42 | + |
| 43 | + constructor() { } |
12 | 44 | ngOnInit() { |
| 45 | + this.tableModel.addAll(this.tableData); |
| 46 | + this.selected = this.tableData.filter(data => data.selected); |
| 47 | + } |
| 48 | + |
| 49 | + initTable() { |
| 50 | + $('#example').DataTable({ |
| 51 | + columnDefs: [ |
| 52 | + { |
| 53 | + targets: [0, 1, 2], |
| 54 | + className: 'mdl-data-table__cell--non-numeric' |
| 55 | + } |
| 56 | + ] |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + selectionChanged($event) { |
| 61 | + this.selected = $event.value; |
13 | 62 | } |
14 | 63 |
|
| 64 | + onInputBlur(event) { |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | + onInputFocus(event) { |
| 69 | + } |
| 70 | + |
| 71 | + onInputKeyup(event) { } |
| 72 | + |
15 | 73 | } |
0 commit comments