mat-table creating columns dynamically vs static change table look
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Sorry if this question is trivial, I'm very new to Angular and Web UI Kingdom
I'm currently looking at this sample project: https://github.com/marinantonio/angular-mat-table-crud
I was replacing the way the columns were created (from static to dynamic) and the table layout changed into something that is hard to read. I am having trouble understanding how/why this is happening. What makes the difference in how I created my columns? But, most importantly, how do i fix it?
Here is what I have:
componnent.html:
<ng-container *ngFor="let column of columns" matColumnDef="{{column.name}}">
<th mat-header-cell *matHeaderCellDef mat-sort-header>{{column.label}}</th>
<td mat-cell *matCellDef="let row"> {{row[column.name]}} </td>
</ng-container>
component.ts
columns: Array<any> = [
{ name: 'id', label: 'ID', cell: (element: any) => `${element.id}` },
{ name: 'title', label: 'Title', cell: (element: any) => `${element.title}` },
{ name: 'state', label: 'State', cell: (element: any) => `${element.state}` },
{ name: 'url', label: 'Url', cell: (element: any) => `${element.url}`},
{ name: 'created_at', label: 'Created at', cell: (element: any) => `${element.created_at}`},
{ name: 'updated_at', label: 'Updated at', cell: (element: any) => `${element.updated_at}`},
]
// displayedColumns = ['id', 'title', 'state', 'url', 'created_at', 'updated_at', 'actions'];
displayedColumns = this.columns.map(x => x.name).concat(['actions']);
I didn't touch the components.css
angular angular-material mat-table
add a comment |
Sorry if this question is trivial, I'm very new to Angular and Web UI Kingdom
I'm currently looking at this sample project: https://github.com/marinantonio/angular-mat-table-crud
I was replacing the way the columns were created (from static to dynamic) and the table layout changed into something that is hard to read. I am having trouble understanding how/why this is happening. What makes the difference in how I created my columns? But, most importantly, how do i fix it?
Here is what I have:
componnent.html:
<ng-container *ngFor="let column of columns" matColumnDef="{{column.name}}">
<th mat-header-cell *matHeaderCellDef mat-sort-header>{{column.label}}</th>
<td mat-cell *matCellDef="let row"> {{row[column.name]}} </td>
</ng-container>
component.ts
columns: Array<any> = [
{ name: 'id', label: 'ID', cell: (element: any) => `${element.id}` },
{ name: 'title', label: 'Title', cell: (element: any) => `${element.title}` },
{ name: 'state', label: 'State', cell: (element: any) => `${element.state}` },
{ name: 'url', label: 'Url', cell: (element: any) => `${element.url}`},
{ name: 'created_at', label: 'Created at', cell: (element: any) => `${element.created_at}`},
{ name: 'updated_at', label: 'Updated at', cell: (element: any) => `${element.updated_at}`},
]
// displayedColumns = ['id', 'title', 'state', 'url', 'created_at', 'updated_at', 'actions'];
displayedColumns = this.columns.map(x => x.name).concat(['actions']);
I didn't touch the components.css
angular angular-material mat-table
Try taking the spaces out of the name columns for'url '
,'created_at '
, etc.
– dmcgrandle
Nov 16 '18 at 17:05
@dmcgrandle thanks, but it doesn't work
– Maria Finkelstein
Nov 16 '18 at 17:40
add a comment |
Sorry if this question is trivial, I'm very new to Angular and Web UI Kingdom
I'm currently looking at this sample project: https://github.com/marinantonio/angular-mat-table-crud
I was replacing the way the columns were created (from static to dynamic) and the table layout changed into something that is hard to read. I am having trouble understanding how/why this is happening. What makes the difference in how I created my columns? But, most importantly, how do i fix it?
Here is what I have:
componnent.html:
<ng-container *ngFor="let column of columns" matColumnDef="{{column.name}}">
<th mat-header-cell *matHeaderCellDef mat-sort-header>{{column.label}}</th>
<td mat-cell *matCellDef="let row"> {{row[column.name]}} </td>
</ng-container>
component.ts
columns: Array<any> = [
{ name: 'id', label: 'ID', cell: (element: any) => `${element.id}` },
{ name: 'title', label: 'Title', cell: (element: any) => `${element.title}` },
{ name: 'state', label: 'State', cell: (element: any) => `${element.state}` },
{ name: 'url', label: 'Url', cell: (element: any) => `${element.url}`},
{ name: 'created_at', label: 'Created at', cell: (element: any) => `${element.created_at}`},
{ name: 'updated_at', label: 'Updated at', cell: (element: any) => `${element.updated_at}`},
]
// displayedColumns = ['id', 'title', 'state', 'url', 'created_at', 'updated_at', 'actions'];
displayedColumns = this.columns.map(x => x.name).concat(['actions']);
I didn't touch the components.css
angular angular-material mat-table
Sorry if this question is trivial, I'm very new to Angular and Web UI Kingdom
I'm currently looking at this sample project: https://github.com/marinantonio/angular-mat-table-crud
I was replacing the way the columns were created (from static to dynamic) and the table layout changed into something that is hard to read. I am having trouble understanding how/why this is happening. What makes the difference in how I created my columns? But, most importantly, how do i fix it?
Here is what I have:
componnent.html:
<ng-container *ngFor="let column of columns" matColumnDef="{{column.name}}">
<th mat-header-cell *matHeaderCellDef mat-sort-header>{{column.label}}</th>
<td mat-cell *matCellDef="let row"> {{row[column.name]}} </td>
</ng-container>
component.ts
columns: Array<any> = [
{ name: 'id', label: 'ID', cell: (element: any) => `${element.id}` },
{ name: 'title', label: 'Title', cell: (element: any) => `${element.title}` },
{ name: 'state', label: 'State', cell: (element: any) => `${element.state}` },
{ name: 'url', label: 'Url', cell: (element: any) => `${element.url}`},
{ name: 'created_at', label: 'Created at', cell: (element: any) => `${element.created_at}`},
{ name: 'updated_at', label: 'Updated at', cell: (element: any) => `${element.updated_at}`},
]
// displayedColumns = ['id', 'title', 'state', 'url', 'created_at', 'updated_at', 'actions'];
displayedColumns = this.columns.map(x => x.name).concat(['actions']);
I didn't touch the components.css
angular angular-material mat-table
angular angular-material mat-table
edited Nov 16 '18 at 17:32
rhavelka
730321
730321
asked Nov 16 '18 at 16:33
Maria FinkelsteinMaria Finkelstein
141110
141110
Try taking the spaces out of the name columns for'url '
,'created_at '
, etc.
– dmcgrandle
Nov 16 '18 at 17:05
@dmcgrandle thanks, but it doesn't work
– Maria Finkelstein
Nov 16 '18 at 17:40
add a comment |
Try taking the spaces out of the name columns for'url '
,'created_at '
, etc.
– dmcgrandle
Nov 16 '18 at 17:05
@dmcgrandle thanks, but it doesn't work
– Maria Finkelstein
Nov 16 '18 at 17:40
Try taking the spaces out of the name columns for
'url '
, 'created_at '
, etc.– dmcgrandle
Nov 16 '18 at 17:05
Try taking the spaces out of the name columns for
'url '
, 'created_at '
, etc.– dmcgrandle
Nov 16 '18 at 17:05
@dmcgrandle thanks, but it doesn't work
– Maria Finkelstein
Nov 16 '18 at 17:40
@dmcgrandle thanks, but it doesn't work
– Maria Finkelstein
Nov 16 '18 at 17:40
add a comment |
1 Answer
1
active
oldest
votes
I found the solution!!!
use cdkColumnDef and cdkHeaderCellDef instead of matColumnDef and mat-header-cell
<ng-container *ngFor="let column of columns; let colIndex = index" [cdkColumnDef]="column.name">
<mat-header-cell *cdkHeaderCellDef>{{ column.label }}</mat-header-cell>
<mat-cell *cdkCellDef="let row">{{ row[column.name] }}</mat-cell>
</ng-container>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341939%2fmat-table-creating-columns-dynamically-vs-static-change-table-look%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I found the solution!!!
use cdkColumnDef and cdkHeaderCellDef instead of matColumnDef and mat-header-cell
<ng-container *ngFor="let column of columns; let colIndex = index" [cdkColumnDef]="column.name">
<mat-header-cell *cdkHeaderCellDef>{{ column.label }}</mat-header-cell>
<mat-cell *cdkCellDef="let row">{{ row[column.name] }}</mat-cell>
</ng-container>
add a comment |
I found the solution!!!
use cdkColumnDef and cdkHeaderCellDef instead of matColumnDef and mat-header-cell
<ng-container *ngFor="let column of columns; let colIndex = index" [cdkColumnDef]="column.name">
<mat-header-cell *cdkHeaderCellDef>{{ column.label }}</mat-header-cell>
<mat-cell *cdkCellDef="let row">{{ row[column.name] }}</mat-cell>
</ng-container>
add a comment |
I found the solution!!!
use cdkColumnDef and cdkHeaderCellDef instead of matColumnDef and mat-header-cell
<ng-container *ngFor="let column of columns; let colIndex = index" [cdkColumnDef]="column.name">
<mat-header-cell *cdkHeaderCellDef>{{ column.label }}</mat-header-cell>
<mat-cell *cdkCellDef="let row">{{ row[column.name] }}</mat-cell>
</ng-container>
I found the solution!!!
use cdkColumnDef and cdkHeaderCellDef instead of matColumnDef and mat-header-cell
<ng-container *ngFor="let column of columns; let colIndex = index" [cdkColumnDef]="column.name">
<mat-header-cell *cdkHeaderCellDef>{{ column.label }}</mat-header-cell>
<mat-cell *cdkCellDef="let row">{{ row[column.name] }}</mat-cell>
</ng-container>
answered Nov 16 '18 at 18:39
Maria FinkelsteinMaria Finkelstein
141110
141110
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341939%2fmat-table-creating-columns-dynamically-vs-static-change-table-look%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try taking the spaces out of the name columns for
'url '
,'created_at '
, etc.– dmcgrandle
Nov 16 '18 at 17:05
@dmcgrandle thanks, but it doesn't work
– Maria Finkelstein
Nov 16 '18 at 17:40