Combining rows in an Angular Material MAT table

Having difficulty with a transition from a basic html table to a mat-table. Struggling to merge two rows on the first two columns.

The current setup has the mat-table on top and the basic html table below:

[![enter image description here][1]][1]

Desired layout for the mat table is as follows: two rows for each reference + invoice, one for invoiced and one for expected, similar to the format in the basic html table.

Basic html table structure:

<table>
  <thead>
    <th *ngFor= "let column of headersContainers">
      {{column}}
    </th>
  </thead>

  <tbody *ngFor = "let container of completeContainers">
    <th rowspan = "2" >{{container.containerReference}}</th>
    <th rowspan = "2" >{{container.invoiceReference}}</th>
      <td>Invoiced</td>
      <td>{{container.InvoicedCosts.OFC | currency :'€ '}}</td>
      <td>{{container.InvoicedCosts.THC | currency :'€ '}}</td>
      <td>{{container.InvoicedCosts.BAF | currency :'€ '}}</td>
      <td>{{container.InvoicedCosts.Total | currency :'€ '}}</td>
    <tr> 
      <td>Expected</td> 
      <td>{{container.ExpectedCosts.OFC | currency :'€ '}}</td>
      <td>{{container.ExpectedCosts.THC | currency :'€ '}}</td>
      <td>{{container.ExpectedCosts.BAF | currency :'€ '}}</td>
      <td>{{container.ExpectedCosts.Total | currency :'€ '}}</td>
    </tr>
  </tbody>
</table>
... (Original content continues) [1]: https://i.sstatic.net/JzP51.png (Note: Content above is derived from original text provided)

Answer №1

Using CSS grid could be a great solution for this scenario. Instead of worrying about rowSpans in your template, consider placing each piece of data into its own column (such as having separate columns for Invoiced and Expected values).

You can set a rule for your tr tags to have a display: grid property and specify the necessary grid-template-columns. Then, assign a grid-area to each column and establish your 'rowSpan' by utilizing the grid-template-areas rule.

If desired, you can define another set of grid-template-areas rules for tr.mat-header-row to display the header differently.

I've created a small example that demonstrates a possible solution similar to what you need: https://stackblitz.com/edit/angular-u2b8qa?file=src/app/table-basic-example.scss

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

Setting up Thrift in an Angular and Electron project

Attempting to incorporate Thrift API calls into my Angular application, I used the following command to generate client files: thrift-0.18.1.exe -r --gen js:ts <myService.thrift> The command successfully created both JavaScript (js) and TypeScript ( ...

What is the correct way to properly cancel a request?

Imagine a scenario where I am utilizing a service that sends HTTP requests to my API and returns observables, which is pretty common. While using this service, the user might become impatient and decide to cancel the request by calling my-subscription.uns ...

The selected image should change its border color, while clicking on another image within the same div should deselect the previous image

https://i.sstatic.net/jp2VF.png I could really use some assistance! I've been working on Angular8 and I came across an image that shows how all the div elements are being selected when clicking on an image. Instead of just removing the border effect f ...

Having trouble getting the MatButtonModule to work when imported into the main module.ts

Within the app folder, there exists a sub module named login. This sub-module includes login.component.ts, login.module.ts, and login.component.html. I am looking to utilize angular-material for the login.component.html. When I import the material componen ...

Storing information in a MySQL database using an HTML table

My goal is to create a form that allows users to input data into my MySQL database. However, I am encountering an error message and the form is submitting blank data every time the page loads. Below is the code I am using: <form action="insert.ph ...

Instructions on how to save HTML "innerHTML" along with attributes to a text document

I'm currently developing an HTML export feature from a DIV tag that includes various elements and attributes. HTML: <div id="master"><span class="classname">content goes here</span></div> <span class="download" onclick="ca ...

Issue with empty attribute selector not functional in Edge browser

In my current version of Edge, I am facing an issue where the empty attribute selector is not functioning correctly. You can find more information about this problem here. The selector I am using is: [ct-validation]:not([ct-validation=""]) { border-col ...

Waiting for the function to complete within an if statement

When attempting a test, I encountered an issue where the function does not wait for the database request to be made. It seems like the function initially returns undefined, and only after the request is completed it returns true or false causing the test t ...

Concealing elements in Angular 2

My intention was to conceal the components, so that when he came back later everything would be just as it was before. The only issue is that I am unsure of how to achieve this. Does anyone have any examples or know of a similar method that could help me ...

If the window width is less than the specified value, hide the DIV and replace it with a

I came across a discussion about hiding a div if the screen is narrower than 1024px, and I'm looking to implement something similar based on the quoted code below. Essentially, I want to hide one div (id="krug_wide") if the window width is less than 1 ...

Steps to opening a second hyperlink in the same window after initially clicking on Hyperlink1

I'm currently working on a project that involves a main web page with three links: Link1, Link2 and Link3. The requirement is for Link1 to open in a new window (window1) when clicked, while Link2 and Link3 should open in the same window as Link1 (wind ...

Understanding the loading process of Google Fonts

I am curious about how Google Fonts determines which fonts to load. For instance, when I include this in my CSS: @import '//fonts.googleapis.com/css?family=Roboto:300'; it generates a CSS file that is immediately interpreted (the loading of thi ...

Issue with Cascading Dropdowns in jQuery

I am currently experiencing issues with a piece of code on my website (also accessible via this link). The code consists of 2 select fields that should display different data based on the selection made. However, I have identified 2 bugs within the code. ...

Guide on utilizing Angular CDK Drag and Drop library for uploading files

I've been working on a unique angular file-upload component and wanted to integrate Angular CDK drag&drop for an enhanced user experience. Unfortunately, when attempting to use it for file uploads (dragging files into the dropzone), I encountered ...

Struggling to achieve consistent height for each div table box

Currently working on creating a table using CSS and divs, and I've got most of it set up except for the issue of uneven heights in the boxes. I've tried adjusting the heights and various commands, but to no avail. I'm unsure whether the prob ...

Is there a way to substitute a custom <form> element for the default <form> in an already existing plugin?

I am currently in the process of customizing a theme and a plugin within WordPress. In the plugin, there is a button that allows users to click on it to bring up a form where they can ask questions. While I want users to post their questions through this p ...

Substituting Meta Viewport tag with alternative CSS method for HTML emails

In an effort to improve support for legacy Blackberrys, we made the decision to take out the meta viewport tag <meta name="viewport" content="width=device-width, initial-scale = 1.0, maximum-scale = 1.0" /> from our HTML emails. Some major email test ...

What is the best way to prevent the navbar from covering content? The navbar-static-top option helps, but it doesn't allow for fixed-scroll

I am facing an issue with my navigation bar while using asp.net. When I apply the class navbar-fixed-top, the navigation bar becomes fixed and scrolls with the page, but it overlaps the content in the contentplaceholder However, when I switch to the clas ...

Using dots instead of lines for the carousel indicators in PrimeNG

I'm currently working on a carousel feature, but I want to change the indicators from lines to small dots. I know the solution lies within the CSS files, but I'm not sure how to implement it. I think I need to create a new CSS class, but I could ...

How can I calculate the width of a character in an HTML5 canvas?

When using the .fillText function with a fixed-width font, I can easily adjust the height by setting the .font property. However, is there a way to accurately determine the width of an individual character? ...