Reputation: 1629
I need to create a table with the first column that has a particular rowspan
.
The result that I want is like this in detail I want the all row in the first column together. This is the code .html:
//This row all toogether in one td
<tr *ngFor="let count of listCount">
<ng-container *ngIf="check()">
<td rowspan="?"....>
<td>..
</ng-container>
</tr>
The problem is that:
rowspan
which is its valueAnyone can help me?
Upvotes: 2
Views: 2154
Reputation: 136154
You can use [attr.rowspan]
and you can render all td
by looping over columns
(create a collection of columns) as well, and as you want you can apply rowspan
to first
column only. Not completely sure what *ngIf="check()"
is :(
<tr *ngFor="let count of listCount">
<ng-container *ngFor="let column of columns;let first = first; let last = last;">
<ng-container *ngIf="check()">
<td [attr.rowspan]="first ? 2: 1"....>
<td>..
</ng-container>
</ng-container>
</tr>
Upvotes: 0
Reputation: 39432
If you want the first column to span over the complete rows, you'll have to:
rowspan="listCount.length"
.let first = first
in *ngFor
.rowspan
count will be dynamic, you'll have to use the Attribute Binding Syntax([attr.rowspan]="listCount.length"
).Try this:
<tr *ngFor="let count of listCount; let first = first">
<ng-container *ngIf="check()">
<td *ngIf="first" [attr.rowspan]="listCount.length" ....>
<td>..
</ng-container>
</tr>
Here's a Sample StackBlitz for your ref.
Upvotes: 2
Reputation: 4650
If you want your column to fill the whole table, you have to set rowspan
attribute to equal rows count.
For conveniance, you can use Angular
ngFor first
local variable to check the first row.
Here is a stackblitz demonstration of the solution.
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<table>
<tr *ngFor="let i of rows; let isFirstRow = first">
<!-- only display first column if it is the first row and set rowspan attribute -->
<td *ngIf="isFirstRow" [attr.rowspan]="rows.length">Column 1</td>
<td>Row {{i}}, column 2</td>
<td>Row {{i}}, column 3</td>
</tr>
</table>
`,
styles: [`
td {
padding: 15px;
border: 1px solid;
}
`]
})
export class AppComponent
{
rows = [ 1, 2, 3 ];
}
Upvotes: 1