|
| 1 | +import {Component} from '@angular/core'; |
| 2 | +import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @title Table with re-orderable columns |
| 6 | + */ |
| 7 | +@Component({ |
| 8 | + selector: 'table-reorderable-example', |
| 9 | + templateUrl: './table-reorderable-example.html', |
| 10 | + styleUrls: ['./table-reorderable-example.css'] |
| 11 | +}) |
| 12 | +export class TableReorderableExample { |
| 13 | + columns: string[] = ['position', 'name', 'weight', 'symbol']; |
| 14 | + dataSource = ELEMENT_DATA; |
| 15 | + |
| 16 | + drop(event: CdkDragDrop<string[]>) { |
| 17 | + moveItemInArray(this.columns, event.previousIndex, event.currentIndex); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +export interface PeriodicElement { |
| 22 | + name: string; |
| 23 | + position: number; |
| 24 | + weight: number; |
| 25 | + symbol: string; |
| 26 | +} |
| 27 | + |
| 28 | +const ELEMENT_DATA: PeriodicElement[] = [ |
| 29 | + {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, |
| 30 | + {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, |
| 31 | + {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, |
| 32 | + {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, |
| 33 | + {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, |
| 34 | + {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'}, |
| 35 | + {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}, |
| 36 | + {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'}, |
| 37 | + {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, |
| 38 | + {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, |
| 39 | +]; |
0 commit comments