question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Table] Posibility to have more rows for item with second row colspan

See original GitHub issue

Feature request

What is the expected behavior?

declare two rows for one item in dataSource

What is the use-case or motivation for changing an existing behavior?

Table with items with second row for labels.

First column Second column
Item 1 - One Item 1 - Two
Item 1 - Two cols
Item 2 - One Item 2 - Two
Item 2 - Two cols

Is there anything else we should know?

Is this posible with the current implementation in cdk-table or mat-table

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:16
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
willshowellcommented, Nov 9, 2017

Though not yet documented, this is possible with the when predicate on the row.

<mat-header-row *matHeaderRowDef="['data', 'id']"></mat-header-row>
<mat-row *matRowDef="let row; columns: ['data', 'id'];"></mat-row>
<mat-row
    *matRowDef="let row; columns: ['data']; when: isExtendedRow"
    class="darken">
</mat-row>
isExtendedRow = (index, item) => item.extend;

// ...

const DATA = [
  { data: 'ABC', id: 1 },
  { data: 'DEF', id: 2 },
  { data: 'GHI', id: 3, extend: true },
  { data: 'JKL', id: 4, },
  { data: 'MNO', id: 5, extend: true },
]

https://stackblitz.com/edit/material2-rc0-6drmzf?file=app%2Fapp.component.html

6reactions
DmitryEfimenkocommented, Feb 5, 2019

How can I have multiple rows based on an array in an element? For example, I have a records with structure like:

[
  {
    id: 1,
    name: 'Luke',
    books: ['book1', 'book2']
  }
]

So I’d like to create 3 rows per that record:

<tr>
  <td>1</td>
  <td>Luke</td>
</tr>
<tr>
  <td colspan="2">book1</td>
</tr>
<tr>
  <td colspan="2">book2</td>
</tr>

I understand that multiTemplateDataRows lets me have multiple row definitions, but I need dynamic number of these row definitions. I need to put *matRowDef into a *ngFor loop somehow.

How can I achieve that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Table Rowspan And Colspan In HTML Explained (With ...
Allows a single table cell to span the height of more than one cell or row. Why use colspan= or rowspan= ? Sometimes...
Read more >
Material table: create extra row with max colspan
I have a table (a non material one) for which I create after each row an extra one with a progress bar like...
Read more >
Tables in HTML documents
The HTML table model allows authors to arrange data -- text, preformatted text, images, links, forms, form fields, other tables, etc. -- into...
Read more >
<tr>: The Table Row element - HTML - MDN Web Docs - Mozilla
Having the first row's "Name", "ID", and "Balance" heading cells span two rows using the rowspan attribute, making them each be two rows...
Read more >
HTML | rowspan Attribute - GeeksforGeeks
That is if a row spans two rows, it means it will take up the space of two rows in that table. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found