-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs(table): add example using http #5766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+239
−0
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
336ba43
docs(table): add example using http
andrewseguin 3eec04f
remove copyright
andrewseguin 092f3a6
revert table.md
andrewseguin e44df62
revert table.md
andrewseguin f11b923
revert table.md
andrewseguin d3cdc8e
remove extra line
andrewseguin 031889b
comments
andrewseguin f1e2fd8
update with paging and sorting
andrewseguin ab70774
remove sort on state
andrewseguin e97c4f7
if sort changed, go to first page
andrewseguin 5c0e4cc
add semicolon
andrewseguin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,33 @@ | ||
/* Structure */ | ||
.example-container { | ||
display: flex; | ||
flex-direction: column; | ||
max-height: 500px; | ||
min-width: 300px; | ||
} | ||
|
||
.example-header { | ||
min-height: 64px; | ||
display: flex; | ||
align-items: center; | ||
padding-left: 24px; | ||
font-size: 20px; | ||
} | ||
|
||
.mat-table { | ||
overflow: auto; | ||
} | ||
|
||
.mat-column-title { | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
flex: 1; | ||
overflow: hidden; | ||
} | ||
|
||
/* Column Widths */ | ||
.mat-column-number, | ||
.mat-column-state, | ||
.mat-column-commentCount { | ||
max-width: 64px; | ||
} |
This file contains hidden or 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,28 @@ | ||
<div class="example-container mat-elevation-z8"> | ||
<md-table #table [dataSource]="dataSource"> | ||
|
||
<!--- Note that these columns can be defined in any order. | ||
The actual rendered columns are set as a property on the row definition" --> | ||
|
||
<!-- Number Column --> | ||
<ng-container cdkColumnDef="number"> | ||
<md-header-cell *cdkHeaderCellDef> Number </md-header-cell> | ||
<md-cell *cdkCellDef="let row"> {{row.number}} </md-cell> | ||
</ng-container> | ||
|
||
<!-- Title Column --> | ||
<ng-container cdkColumnDef="title"> | ||
<md-header-cell *cdkHeaderCellDef> Title </md-header-cell> | ||
<md-cell *cdkCellDef="let row"> {{row.title}} </md-cell> | ||
</ng-container> | ||
|
||
<!-- State Column --> | ||
<ng-container cdkColumnDef="state"> | ||
<md-header-cell *cdkHeaderCellDef> State </md-header-cell> | ||
<md-cell *cdkCellDef="let row"> {{row.state}} </md-cell> | ||
</ng-container> | ||
|
||
<md-header-row *cdkHeaderRowDef="displayedColumns"></md-header-row> | ||
<md-row *cdkRowDef="let row; columns: displayedColumns;"></md-row> | ||
</md-table> | ||
</div> |
This file contains hidden or 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,70 @@ | ||
import {Component} from '@angular/core'; | ||
import {Http, Response} from '@angular/http'; | ||
import {DataSource} from '@angular/cdk'; | ||
import {Observable} from 'rxjs/Observable'; | ||
import 'rxjs/add/operator/startWith'; | ||
import 'rxjs/add/observable/merge'; | ||
import 'rxjs/add/operator/map'; | ||
|
||
@Component({ | ||
selector: 'table-http-example', | ||
styleUrls: ['table-http-example.css'], | ||
templateUrl: 'table-http-example.html', | ||
}) | ||
export class TableHttpExample { | ||
displayedColumns = ['number', 'state', 'title']; | ||
exampleDatabase: ExampleHttpDao | null; | ||
dataSource: ExampleDataSource | null; | ||
|
||
constructor(http: Http) { | ||
this.exampleDatabase = new ExampleHttpDao(http); | ||
this.dataSource = new ExampleDataSource(this.exampleDatabase); | ||
} | ||
} | ||
|
||
export interface GithubIssue { | ||
number: string; | ||
state: string; | ||
title: string; | ||
} | ||
|
||
/** An example database that the data source uses to retrieve data for the table. */ | ||
export class ExampleHttpDao { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should include sorting and pagination in this example. The github api supports it. |
||
private issuesUrl = 'https://api.github.com/repos/angular/material2/issues'; // URL to web API | ||
|
||
constructor(private http: Http) {} | ||
|
||
getRepoIssues(): Observable<GithubIssue[]> { | ||
return this.http.get(this.issuesUrl).map(this.readGithubResult); | ||
} | ||
|
||
private readGithubResult(result: Response): GithubIssue[] { | ||
return result.json().map(issue => { | ||
return { | ||
number: issue.number, | ||
state: issue.state, | ||
title: issue.title, | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Data source to provide what data should be rendered in the table. Note that the data source | ||
* can retrieve its data in any way. In this case, the data source is provided a reference | ||
* to a common data base, ExampleHttpDao. It is not the data source's responsibility to manage | ||
* the underlying data. Instead, it only needs to take the data and send the table exactly what | ||
* should be rendered. | ||
*/ | ||
export class ExampleDataSource extends DataSource<GithubIssue> { | ||
constructor(private _exampleDatabase: ExampleHttpDao) { | ||
super(); | ||
} | ||
|
||
/** Connect function called by the table to retrieve one stream containing the data to render. */ | ||
connect(): Observable<GithubIssue[]> { | ||
return this._exampleDatabase.getRepoIssues(); | ||
} | ||
|
||
disconnect() {} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these classes need to be under an
.example-
prefix