diff --git a/src/material-examples/table-basic/table-basic-example.css b/src/material-examples/table-basic/table-basic-example.css
index 5b9032d196b3..31bd3b658d8b 100644
--- a/src/material-examples/table-basic/table-basic-example.css
+++ b/src/material-examples/table-basic/table-basic-example.css
@@ -1,19 +1,10 @@
-/* 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;
- max-height: 500px;
}
diff --git a/src/material-examples/table-basic/table-basic-example.html b/src/material-examples/table-basic/table-basic-example.html
index 03bef390337d..66dd020c6d55 100644
--- a/src/material-examples/table-basic/table-basic-example.html
+++ b/src/material-examples/table-basic/table-basic-example.html
@@ -4,28 +4,28 @@
-
-
- ID
- {{row.id}}
-
-
-
-
- Progress
- {{row.progress}}%
+
+
+ No.
+ {{element.position}}
-
+
Name
- {{row.name}}
+ {{element.name}}
+
+
+
+
+ Weight
+ {{element.weight}}
-
- Color
- {{row.color}}
+
+ Symbol
+ {{element.symbol}}
diff --git a/src/material-examples/table-basic/table-basic-example.ts b/src/material-examples/table-basic/table-basic-example.ts
index 4db0a4aaa62e..be57119ec16e 100644
--- a/src/material-examples/table-basic/table-basic-example.ts
+++ b/src/material-examples/table-basic/table-basic-example.ts
@@ -1,91 +1,58 @@
import {Component} from '@angular/core';
import {DataSource} from '@angular/cdk/table';
-import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import {Observable} from 'rxjs/Observable';
-import 'rxjs/add/operator/startWith';
-import 'rxjs/add/observable/merge';
-import 'rxjs/add/operator/map';
+import 'rxjs/add/observable/of';
-/**
- * @title Basic table
- */
@Component({
selector: 'table-basic-example',
styleUrls: ['table-basic-example.css'],
templateUrl: 'table-basic-example.html',
})
export class TableBasicExample {
- displayedColumns = ['userId', 'userName', 'progress', 'color'];
- exampleDatabase = new ExampleDatabase();
- dataSource: ExampleDataSource | null;
-
- ngOnInit() {
- this.dataSource = new ExampleDataSource(this.exampleDatabase);
- }
+ displayedColumns = ['position', 'name', 'weight', 'symbol'];
+ dataSource = new ExampleDataSource();
}
-/** Constants used to fill up our data base. */
-const COLORS = ['maroon', 'red', 'orange', 'yellow', 'olive', 'green', 'purple',
- 'fuchsia', 'lime', 'teal', 'aqua', 'blue', 'navy', 'black', 'gray'];
-const NAMES = ['Maia', 'Asher', 'Olivia', 'Atticus', 'Amelia', 'Jack',
- 'Charlotte', 'Theodore', 'Isla', 'Oliver', 'Isabella', 'Jasper',
- 'Cora', 'Levi', 'Violet', 'Arthur', 'Mia', 'Thomas', 'Elizabeth'];
-
-export interface UserData {
- id: string;
+export interface Element {
name: string;
- progress: string;
- color: string;
+ position: number;
+ weight: number;
+ symbol: string;
}
-/** An example database that the data source uses to retrieve data for the table. */
-export class ExampleDatabase {
- /** Stream that emits whenever the data has been modified. */
- dataChange: BehaviorSubject = new BehaviorSubject([]);
- get data(): UserData[] { return this.dataChange.value; }
-
- constructor() {
- // Fill up the database with 100 users.
- for (let i = 0; i < 100; i++) { this.addUser(); }
- }
-
- /** Adds a new user to the database. */
- addUser() {
- const copiedData = this.data.slice();
- copiedData.push(this.createNewUser());
- this.dataChange.next(copiedData);
- }
-
- /** Builds and returns a new User. */
- private createNewUser() {
- const name =
- NAMES[Math.round(Math.random() * (NAMES.length - 1))] + ' ' +
- NAMES[Math.round(Math.random() * (NAMES.length - 1))].charAt(0) + '.';
-
- return {
- id: (this.data.length + 1).toString(),
- name: name,
- progress: Math.round(Math.random() * 100).toString(),
- color: COLORS[Math.round(Math.random() * (COLORS.length - 1))]
- };
- }
-}
+const data: Element[] = [
+ {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'},
+ {position: 11, name: 'Sodium', weight: 22.9897, symbol: 'Na'},
+ {position: 12, name: 'Magnesium', weight: 24.305, symbol: 'Mg'},
+ {position: 13, name: 'Aluminum', weight: 26.9815, symbol: 'Al'},
+ {position: 14, name: 'Silicon', weight: 28.0855, symbol: 'Si'},
+ {position: 15, name: 'Phosphorus', weight: 30.9738, symbol: 'P'},
+ {position: 16, name: 'Sulfur', weight: 32.065, symbol: 'S'},
+ {position: 17, name: 'Chlorine', weight: 35.453, symbol: 'Cl'},
+ {position: 18, name: 'Argon', weight: 39.948, symbol: 'Ar'},
+ {position: 19, name: 'Potassium', weight: 39.0983, symbol: 'K'},
+ {position: 20, name: 'Calcium', weight: 40.078, symbol: 'Ca'},
+];
/**
- * 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, ExampleDatabase. 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.
+ * Data source to provide what data should be rendered in the table. The observable provided
+ * in connect should emit exactly the data that should be rendered by the table. If the data is
+ * altered, the observable should emit that new set of data on the stream. In our case here,
+ * we return a stream that contains only one set of data that doesn't change.
*/
export class ExampleDataSource extends DataSource {
- constructor(private _exampleDatabase: ExampleDatabase) {
- super();
- }
-
/** Connect function called by the table to retrieve one stream containing the data to render. */
- connect(): Observable {
- return this._exampleDatabase.dataChange;
+ connect(): Observable {
+ return Observable.of(data);
}
disconnect() {}