Angular Material table featuring nested subrows with varying cell heights

I am attempting to create a table with nested cells that mimic subrows. Everything works well as long as the content in each cell does not exceed the min-height property value of the nested cell (A).

Unfortunately, if this value is exceeded, the table layout breaks down (B). Is there a straightforward way to properly align the nested cells to achieve a table layout like (C)?

Here is the code: https://stackblitz.com/edit/angular-aejwfm

https://i.sstatic.net/vvg6B.png

(*) I am aware that JavaScript can be used to set the height of all cells representing a specific subrow to the maximum height of all cells from that subrow, but I would prefer a solution using pure HTML/CSS/Angular.

Answer №1

If you want to ensure that all cells in a row have the same height, one solution is to create a directive that can identify cells of a single row based on a specific criteria.

Since you are rendering data column by column, you'll need to provide some information to the directive so it can determine which cells belong to the same row.

I've made updates to your code to achieve the desired outcome.

Here is the link to the modified demo.

Below is a summary of the changes I made:

Create a directive named MatchCellHeightDirective that takes the 'book' object as input. This object helps identify cells belonging to the same row.

@Directive({
  selector: '[matchCellHeight]'
})
export class MatchCellHeightDirective {

  @Input() matchCellHeight: any;

  constructor(private el: ElementRef) { 

  }
}

Bind this directive to each cell element in your template.

<mat-cell [matchCellHeight]='book' *ngFor="let book of genre.books">
    {{book.title}} 
</mat-cell>

Create a service named MatchCellHeightService to store references of each cell and handle the logic for matching heights.

If you're interested, you can also check out another implementation of a directive that achieves similar results here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The impact of empty space on design aesthetics and practical solutions to utilize white space effectively

Within this example <html> <head> <style> .q_show_spaces { white-space: pre-wrap; } .q_inline { display: inline; } .q_no_wrap { white-space: pre; } </style> </head> &l ...

What is the best way to expand my navigation bar to fill the entire width of my div?

A big shoutout to @seva.rubbo for fixing the issue! Check out the updated code on JSFiddle I recently designed a layout with a fixed width div of width: 900px;. I centered this div, leaving blank spaces on either side. Now, I'm looking to add a navig ...

Refreshing the PrimeNg Organization Chart through code executionPrimeNg Organization Chart

Using the p-organizationChart to display hierarchy, I encounter an issue where dynamically added child nodes do not display the expand arrow until I select a Node. Therefore, I am seeking a way to programmatically refresh the org-chart. Any suggestions on ...

Replace current CSS classes with new classes provided by the API

One of the challenges I'm facing involves overriding existing classes that I've defined in an Angular component's SCSS file. In this unique scenario, different styles will be retrieved from an API, each with a class name associated with the ...

Can someone help me extract a value from Bootstrap's datetimepicker using Angular 4?

Currently, I am attempting to retrieve dates from two Bootstrap date time pickers by utilizing the Angular event (mouseup). The template code snippet is as follows: <h2>{{title}}</h2> <form [formGroup]="leaveCreateForm" (ngSubmit)="onSubmit ...

Image input not working in Internet Explorer

While the button displays correctly in Chrome and Firefox, it appears differently in IE: To address this issue in IE, you may need to make adjustments to the CSS styles specifically for that browser. One potential solution could involve creating a separat ...

Event emitter in Ionic/Angular 2 component fails to refresh the view

I am currently developing a custom component for an Ionic 2 app. The component code is as follows: import {Component, EventEmitter} from 'angular2/core'; import {Button, Icon, Item} from 'ionic-angular'; import {DatePicker} from ' ...

Retrieving user input from a personalized autocomplete cell editor

Struggling to create a custom autocomplete feature with ag grid. Unable to update the returned value with the selected item from the dropdown list. In simpler terms: I input 'A' => Receive a list of options => Select one => The input s ...

Issue with Reactive Form - The call signatures of 'FormGroup' are not compatible

I have a function written in TypeScript: // Form summaryAreaForm = new FormGroup ({ summary: new FormControl(null) }) // Function update() { document.getElementById('textDiv').innerHTML = this.summaryAreaForm('summary').value ...

Displaying information collected from a submission form

I am in the process of designing a cheerful birthday card and I need to transfer data from a form to the birthday card page. How can I take information from the first div (which contains the form) and display that data in the second div? <!DOCTYPE ...

The vertical alignment of an image within a colorbox is not functioning properly

I recently attempted to center an image vertically using the line-height property in the parent and the vertical-align property in the child element: <div style="height:500px; line-height:500px"> <img src="someimage.jpg" style="vertical-align:m ...

Issue with registering Service worker for Angular 9 PWA with Carousel remains unresolved

Hi everyone, I've run into a bit of a strange situation, Currently, I am using Angular 9 along with Bootstrap 3.3.5 (haven't been able to update to the latest version yet), On the homepage, I have a Carousel implemented and also integrated Angu ...

Having trouble incorporating symbols with functionalities using HTML, CSS, and JS

I have implemented a table with three columns: "Action", "Question Subquestion/Text", and "Sort order". Additionally, I have incorporated a feature that allows for drag and drop functionality on the rows. Below is my code snippet: <!DOCTYPE html> &l ...

Preventing Partial Overlap of Two Divs in HTML5

I found a template that caught my eye here: w3schools template My latest project involves using this template to create a basic online shop layout with three main vertical sections: left, middle, and right. The left panel serves as a preview area ...

Triggering an event from a component to its parent module resulting in an exception situation

Here is my app.component.ts code: import { Component, Input, OnInit, OnChanges, SimpleChanges} from '@angular/core'; import {Counter } from './counter' @Component({ selector: 'my-app', template: ` <custom-counter [ ...

Utilizing Bootstrap for Efficient Image Alignment

I'm encountering an issue with my code and I am unsure of how to fix it. The current state of my code is different from the desired outcome https://i.sstatic.net/Ti1kK.jpg As you can see, the image above does not match the appearance of the image I ...

Can you explain the expected behavior of the ::before and ::after pseudo-elements when used with the <details> element?

I observed that the <details> element is rendered differently in Chrome and Firefox. Take a look at the code sample below. According to the HTML Standard: The first summary element child of the details element represents the summary or legend of the ...

Creating a visually appealing layout with three equal columns side by side in Bootstrap 4

I am trying to keep my CSS efforts minimal by utilizing Bootstrap for a simple layout. However, I am encountering an issue with a horizontal scroll. If anyone has a solution or can point out what I may be missing, please share. <!DOCTYPE html> < ...

Is there a way to change the text (price) when I select an option?

<div class="single-pro-details"> <!--Customize in the CSS--> <h6>Home / Beats</h6> <h4>Unique Lil Tecca Type Beat - New Love</h4> <h2 id="price">$ ...

A linear progress indicator composed of a continuous solid line and dotted markers to represent individual steps

I am currently working on creating a vertical progress bar with 8 dots displayed on a solid line, where each dot represents a step in the process. Please refer to the attached screenshot (located at the bottom of this question to maintain clarity). My att ...