-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example of a re-orederable table
- Loading branch information
Showing
6 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/components-examples/material/table/table-reorderable/table-reorderable-example.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
table { | ||
width: 100%; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/components-examples/material/table/table-reorderable/table-reorderable-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<table mat-table | ||
[dataSource]="dataSource" | ||
cdkDropList | ||
cdkDropListOrientation="horizontal" | ||
(cdkDropListDropped)="drop($event)"> | ||
|
||
<ng-container matColumnDef="position"> | ||
<th mat-header-cell cdkDrag *matHeaderCellDef> No. </th> | ||
<td mat-cell *matCellDef="let element"> {{element.position}} </td> | ||
</ng-container> | ||
|
||
<ng-container matColumnDef="name"> | ||
<th mat-header-cell cdkDrag *matHeaderCellDef> Name </th> | ||
<td mat-cell *matCellDef="let element"> {{element.name}} </td> | ||
</ng-container> | ||
|
||
<ng-container matColumnDef="weight"> | ||
<th mat-header-cell cdkDrag *matHeaderCellDef> Weight </th> | ||
<td mat-cell *matCellDef="let element"> {{element.weight}} </td> | ||
</ng-container> | ||
|
||
<ng-container matColumnDef="symbol"> | ||
<th mat-header-cell cdkDrag *matHeaderCellDef> Symbol </th> | ||
<td mat-cell *matCellDef="let element"> {{element.symbol}} </td> | ||
</ng-container> | ||
|
||
<tr mat-header-row *matHeaderRowDef="columns"></tr> | ||
<tr mat-row *matRowDef="let row; columns: columns;"></tr> | ||
</table> |
46 changes: 46 additions & 0 deletions
46
src/components-examples/material/table/table-reorderable/table-reorderable-example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Component } from '@angular/core'; | ||
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; | ||
|
||
/** | ||
* @title Table with re-orderable columns | ||
*/ | ||
@Component({ | ||
selector: 'table-reorderable-example', | ||
templateUrl: './table-reorderable-example.html', | ||
styleUrls: [ './table-reorderable-example.css' ] | ||
}) | ||
export class TableReorderableExample { | ||
private originalColumnPositions: string[] = ['position', 'name', 'weight', 'symbol']; | ||
columns: string[] = Object.assign([], this.originalColumnPositions); | ||
dataSource = ELEMENT_DATA; | ||
|
||
drop(event: CdkDragDrop<string[]>) { | ||
moveItemInArray(this.columns, this.getCurPosition(event.previousIndex), event.currentIndex); | ||
} | ||
|
||
getCurPosition(colOldIndex: number): number { | ||
const colName: string = this.originalColumnPositions[colOldIndex]; | ||
const p = (e: string) => e == colName; | ||
return this.columns.findIndex(e => e == colName); | ||
} | ||
} | ||
|
||
export interface PeriodicElement { | ||
name: string; | ||
position: number; | ||
weight: number; | ||
symbol: string; | ||
} | ||
|
||
const ELEMENT_DATA: PeriodicElement[] = [ | ||
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, | ||
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, | ||
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, | ||
{position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, | ||
{position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, | ||
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'}, | ||
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}, | ||
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'}, | ||
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, | ||
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters