Skip to content

Commit 49d6080

Browse files
devversionmmalerba
authored andcommitted
chore: add cdk table to universal app (#6300)
* Adds the CDK table to the universal app. This ensures that CDK tables can be rendered inside of platform-server.
1 parent 3944d70 commit 49d6080

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/universal-app/kitchen-sink/kitchen-sink.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,15 @@ <h2>Expansion Panel</h2>
227227
This is the content text that makes sense here.
228228
<md-action-row>Action</md-action-row>
229229
</md-expansion-panel>
230+
231+
<h2>CDK Table</h2>
232+
233+
<cdk-table #table [dataSource]="cdkTableDataSource">
234+
<ng-container cdkColumnDef="userId">
235+
<cdk-header-cell *cdkHeaderCellDef>ID</cdk-header-cell>
236+
<cdk-cell *cdkCellDef="let row">{{row.userId}}</cdk-cell>
237+
</ng-container>
238+
239+
<cdk-header-row *cdkHeaderRowDef="cdkTableColumns" ></cdk-header-row>
240+
<cdk-row *cdkRowDef="let row; columns: cdkTableColumns;"></cdk-row>
241+
</cdk-table>

src/universal-app/kitchen-sink/kitchen-sink.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Component, NgModule} from '@angular/core';
22
import {ServerModule} from '@angular/platform-server';
33
import {BrowserModule} from '@angular/platform-browser';
4+
import {Observable} from 'rxjs/Observable';
45
import {
56
MdAutocompleteModule,
67
MdButtonModule,
@@ -29,14 +30,33 @@ import {
2930
MdToolbarModule,
3031
MdTooltipModule,
3132
} from '@angular/material';
33+
import {
34+
CdkTableModule,
35+
DataSource
36+
} from '@angular/cdk/table';
3237

38+
import 'rxjs/add/observable/of';
3339

3440
@Component({
3541
selector: 'kitchen-sink',
3642
templateUrl: './kitchen-sink.html',
3743
styleUrls: ['./kitchen-sink.css'],
3844
})
39-
export class KitchenSink { }
45+
export class KitchenSink {
46+
47+
/** List of columns for the CDK table. */
48+
cdkTableColumns = ['userId'];
49+
50+
/** Data source for the CDK table. */
51+
cdkTableDataSource: DataSource<any> = {
52+
connect: () => Observable.of([
53+
{ userId: 1 },
54+
{ userId: 2 }
55+
]),
56+
disconnect: () => {}
57+
};
58+
59+
}
4060

4161

4262
@NgModule({
@@ -70,7 +90,10 @@ export class KitchenSink { }
7090
MdTabsModule,
7191
MdToolbarModule,
7292
MdTooltipModule,
73-
MdExpansionModule
93+
MdExpansionModule,
94+
95+
// CDK Modules
96+
CdkTableModule
7497
],
7598
bootstrap: [KitchenSink],
7699
declarations: [KitchenSink],

0 commit comments

Comments
 (0)