This repository has been archived by the owner on Feb 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: merge branch 'data-table-review'
- Loading branch information
Showing
16 changed files
with
621 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<md-data-table layout-fill> | ||
<thead> | ||
<tr> | ||
<th class="md-text-cell">Material</th> | ||
<th>Quantity</th> | ||
<th>Unit price</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="#material of materials"> | ||
<td class="md-text-cell">{{ material.name }}</td> | ||
<td>{{ material.quantity }}</td> | ||
<td>{{ material.price }}</td> | ||
</tr> | ||
</tbody> | ||
</md-data-table> |
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,15 @@ | ||
import {Component} from 'angular2/core'; | ||
import {MATERIAL_DIRECTIVES} from 'ng2-material/all'; | ||
|
||
@Component({ | ||
selector: 'data-table-basic-usage', | ||
templateUrl: 'examples/components/data_table/basic_usage.html', | ||
directives: [MATERIAL_DIRECTIVES] | ||
}) | ||
export default class DataTableBasicUsage { | ||
materials: Array<any> = [ | ||
{'id': 1, 'name': 'Acrylic (Transparent)', 'quantity': '25', 'price': '$2.90'}, | ||
{'id': 2, 'name': 'Plywood (Birch)', 'quantity': '50', 'price': '$1.25'}, | ||
{'id': 3, 'name': 'Laminate (Gold on Blue)', 'quantity': '10', 'price': '$2.35'} | ||
] | ||
} |
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 @@ | ||
A data table that supports static and selectable rows. |
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,26 @@ | ||
<md-toolbar> | ||
<div class="md-toolbar-tools" *ngIf="!selection"> | ||
<span>Materials</span> | ||
</div> | ||
<div class="md-toolbar-tools selection" *ngIf="selection"> | ||
<span>{{count}} item{{count > 1 ? 's' : ''}} selected</span> | ||
<span flex hide show-gt-md></span> | ||
<span class="md-caption" hide show-gt-md>{{selection}}</span> | ||
</div> | ||
</md-toolbar> | ||
<md-data-table layout-fill [selectable]="true" (onSelectableChange)="change($event)"> | ||
<thead> | ||
<tr> | ||
<th class="md-text-cell">Material</th> | ||
<th>Quantity</th> | ||
<th>Unit price</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="#material of materials" [selectableValue]="material.id"> | ||
<td class="md-text-cell">{{ material.name }}</td> | ||
<td>{{ material.quantity }}</td> | ||
<td>{{ material.price }}</td> | ||
</tr> | ||
</tbody> | ||
</md-data-table> |
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,14 @@ | ||
@import "../../../ng2-material/core/style/variables"; | ||
@import "../../../ng2-material/core/style/default-theme"; | ||
|
||
md-toolbar { | ||
background-color: transparent; | ||
border-bottom: 1px solid md-color($md-foreground, divider); | ||
color: md-color($md-foreground, text); | ||
.md-toolbar-tools { | ||
&.selection { | ||
background-color: md-color($md-accent, 50); | ||
color: md-color($md-accent, 900); | ||
} | ||
} | ||
} |
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 @@ | ||
import {Component} from "angular2/core"; | ||
import {MATERIAL_DIRECTIVES, ITableSelectionChange} from "ng2-material/all"; | ||
|
||
@Component({ | ||
selector: 'data-table-selectable-usage', | ||
templateUrl: 'examples/components/data_table/selectable_usage.html', | ||
styleUrls: ['examples/components/data_table/selectable_usage.css'], | ||
directives: [MATERIAL_DIRECTIVES] | ||
}) | ||
export default class DataTableSelectableUsage { | ||
selection: string; | ||
count: number; | ||
materials: Array<any> = [ | ||
{'id': 1, 'name': 'Acrylic (Transparent)', 'quantity': '25', 'price': '$2.90'}, | ||
{'id': 2, 'name': 'Plywood (Birch)', 'quantity': '50', 'price': '$1.25'}, | ||
{'id': 3, 'name': 'Laminate (Gold on Blue)', 'quantity': '10', 'price': '$2.35'} | ||
]; | ||
|
||
change(data: ITableSelectionChange) { | ||
let names = []; | ||
this.materials.forEach((mat: any) => { | ||
if (data.values.indexOf(mat.id) !== -1) { | ||
names.push(mat.name); | ||
} | ||
}); | ||
this.selection = names.join(', '); | ||
this.count = names.length; | ||
} | ||
} |
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
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,40 @@ | ||
# MdDataTable | ||
MdDataTable is an enhancment of classic data tables. | ||
|
||
## Basic data table | ||
### Classes | ||
| Name | Target | Description | | ||
| --- | --- | --- | | ||
| md-text-cell | thead th, tbody td | Declare a cell as non-numeric and left align its text. | | ||
|
||
## Selectable data table | ||
### Properties | ||
| Name | Target | Type | Description | | ||
| --- | --- | --- | --- | | ||
| selectable | md-data-table | boolean | Enable one checkbox per line and a master checkbox to rule them all. | | ||
| selectableValue | tbody tr | string | value of the checkbox. If it's not set the checkbox's value will be the index of the row. | | ||
|
||
### Events | ||
| Name | Description | | ||
| --- | --- | | ||
| selectable_change | Emmited when the user select or unselect a row | | ||
|
||
## Examples | ||
``` | ||
<md-data-table [selectable]="true"> | ||
<thead> | ||
<tr> | ||
<th class="md-text-cell">Material</th> | ||
<th>Quantity</th> | ||
<th>Unit price</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="#material of materials" [selectableValue]="material.id"> | ||
<td class="md-text-cell">{{ material.name }}</td> | ||
<td>{{ material.quantity }}</td> | ||
<td>{{ material.price }}</td> | ||
</tr> | ||
</tbody> | ||
</md-data-table> | ||
``` |
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,44 @@ | ||
@import "../../core/style/variables"; | ||
@import "../../core/style/default-theme"; | ||
|
||
md-data-table { | ||
display: table; | ||
border-spacing: 0; | ||
border-collapse: collapse; | ||
|
||
md-checkbox { | ||
margin: 0; | ||
} | ||
tr { | ||
vertical-align: top; | ||
} | ||
th, td { | ||
text-align: right; | ||
&.md-text-cell { text-align: left; } | ||
} | ||
th { | ||
padding: 22px 12px; | ||
font-size: 12px; | ||
font-weight: 600; | ||
color: md-color($md-foreground, secondary-text); | ||
} | ||
td { | ||
border-top: 1px solid md-color($md-foreground, divider); | ||
padding: 14px 12px; | ||
font-size: 13px; | ||
color: md-color($md-foreground, text); | ||
} | ||
th:first-child, td:first-child{ | ||
padding-left: 24px; | ||
} | ||
th:last-child, td:last-child{ | ||
padding-right: 24px; | ||
} | ||
|
||
tr:hover td { | ||
background-color: md-color($md-grey, 200); | ||
} | ||
.active td { | ||
background-color: md-color($md-grey, 100); | ||
} | ||
} |
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,86 @@ | ||
import {Component, Input, Output, EventEmitter, ContentChildren, QueryList} from "angular2/core"; | ||
import {MdDataTableTr} from "./data_table_tr"; | ||
import "rxjs/add/operator/share"; | ||
|
||
export * from './data_table_tr'; | ||
|
||
/** | ||
* Selectable change event data | ||
*/ | ||
export interface ITableSelectionChange { | ||
name: string; | ||
allSelected: boolean; | ||
values: any[]; | ||
} | ||
|
||
|
||
@Component({ | ||
selector: 'md-data-table', | ||
template: `<ng-content></ng-content>`, | ||
directives: [MdDataTableTr], | ||
host: { | ||
'[class.md-data-table]': 'true', | ||
'[class.md-data-table-selectable]': 'selectable', | ||
} | ||
}) | ||
export class MdDataTable { | ||
@Input() | ||
selectable: boolean; | ||
@Output() | ||
onSelectableAll: EventEmitter<any> = new EventEmitter(false); | ||
@Output() | ||
onSelectableChange: EventEmitter<any> = new EventEmitter(false); | ||
|
||
@ContentChildren(MdDataTableTr, true) | ||
_rows: QueryList<MdDataTableTr>; | ||
selected: Array<string> = []; | ||
|
||
constructor() { | ||
this.onSelectableChange.share(); | ||
} | ||
|
||
/** | ||
* Fill/Empty the array of selected values | ||
* | ||
* @param {MdDataTableTr} tr | ||
*/ | ||
toggleActivity(tr: MdDataTableTr) { | ||
let event: ITableSelectionChange = { | ||
name: 'selectable_change', | ||
allSelected: false, | ||
values: [] | ||
}; | ||
|
||
if (tr.isInHeader === true) { | ||
if (tr.isActive === true) { | ||
event.allSelected = true; | ||
event.values = this._getRowsValues(); | ||
} | ||
} else { | ||
event.values = this.selected.slice(0); | ||
|
||
if (tr.isActive === true) { | ||
event.values.push(tr.selectableValue); | ||
} else { | ||
let index = event.values.indexOf(tr.selectableValue); | ||
if (index !== -1) { | ||
event.values.splice(index, 1); | ||
} | ||
} | ||
} | ||
|
||
// dispatch change | ||
this.selected = event.values; | ||
this.onSelectableChange.emit(event); | ||
} | ||
|
||
/** | ||
* @returns {Array<string>} | ||
*/ | ||
_getRowsValues(): any[] { | ||
return this._rows.toArray() | ||
.filter((data, index) => index > 0) | ||
.map((tr: MdDataTableTr) => tr.selectableValue); | ||
} | ||
|
||
} |
Oops, something went wrong.