0

I want to create something like this but I don't want it to be an expansion panel just because I want the nested rows to be added or removed dynamically based on Add and delete button. I have a material data table with multiple rows and want to add nested rows in between 2 rows and these nested rows could be n numbers and I can increase or decrease the value of n. enter image description here

2
  • I highly suggest you add what you've tried so far with code before this post get's downvotted to China. Commented Jan 21, 2021 at 22:01
  • @Pytth hahahaa I tried reading the APIs of Material data table but couldn't find anything, that is why I am looking for suggestions as I am confused. Commented Jan 22, 2021 at 6:26

1 Answer 1

0

To my knowledge Angular Material does not cater for nested rows.

I solved this issue by maintaining a "flat" table and changing the style of sub/nested rows to appear as such. To do this, the data needs to be ordered so that each row's sub rows are placed after it.

Ordering ex.

  1. Row 1
  2. Row 1 Nested Row 1
  3. Row 1 Nested Row 2
  4. Row 2
  5. Row 2 Nested Row 1
  6. etc.

Once the data is ordered, you need to identify and apply your class to the nested rows.

CSS - Nested row class example:

  .example-table {
    width: 100%;
   
    .cdk-column-a {
     
    }

    ..

    .sub-level-row {
      td {
        font-size: 11px;
        opacity: 0.85;
        border-bottom: 1px solid;
      }
    }
  }

HTML - Apply class using [ngClass] to nested rows:

  <tr mat-row [ngClass]="{'sub-level-row': isSubLevelRow(rowData)}"
  *matRowDef="let rowData; columns: tableColumns"></tr>

TS - Determine if row is nested:

  isSubLevelRow(rowData) {
    // use your data to determine if nested row
    return rowData.parentId !== null;
  }

Result:

Result

Apply padding, margins, colors etc. for more nested look.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.