Creating an intricate table layout using AngularJS and the ngRepeat directive

I'm attempting to create a table similar to the one shown in the image below using HTML5.

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

In this table, there is a multi-dimensional matrix with Class A and Class B highlighted in yellow. Each class has three modes (highlighted in blue), and each mode has different parameter values (highlighted in green). The grey cells contain the values for all possible combinations.

The sizes of the modes and parameters are unknown beforehand but are consistent between Class A and Class B. I want to use ng-repeat to dynamically populate the vertical and horizontal headers of the table, adjusting column and row spans as needed.

My main challenge lies in creating the header for Class A and properly utilizing rowspan for the modes and parameters.

I initially attempted nested tables, but alignment issues arose between the grey cells and headers. Here's the code snippet I used:

<table class=" table-bordered">
  <tbody>
    <tr>
      <td></td>
      <td>
        <table class=" table-bordered">
          <tbody>
            <tr>
              <td colspan="{{getTotalNumCombinations()}}">class B</td>
            </tr>
            <tr>
              <td colspan="{{params.length}}" ng-repeat="m in modes track by $index">{{m}}</td>
            </tr>
            <tr>
              <td ng-repeat="i in getCombinationsArray() track by $index">{{params[getModule($index)]}}</td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>>
    ...

Since the nested approach didn't align correctly, I explored an alternative method without nesting:

<table class=" table-bordered">
  <tbody>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td colspan="{{getNumCombinations()}}">class B</td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td colspan="{{params.length}}" ng-repeat="m in modes track by $index">{{m}}</td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td ng-repeat="i in getCombinationsArray() track by $index">{{params[getModule($index)]}}</td>
    </tr>
    <tr>
      <td rowspan="{{getNumCombinations()}}">class A </td>
      <td ng-repeat="m in modes">{{m}}</td>
    </tr>
  </tbody>
</table>

Unfortunately, this second method also faced limitations and did not provide the desired outcome.

As a result, I am seeking alternative approaches or solutions that may address these challenges. Feel free to check out the Plunker link showcasing both versions.

Answer №1

I have decided to implement the second method you suggested. Instead of ng-repeating over column for modes, I will now ng-repeat over every row.

<tr>
    <td class="classColor" rowspan="{{getNumCombinations()}}">class A </td>
    <td class="modeColor" ng-repeat="m in modes">{{m}}</td>
</tr>

After considering your advice, I have made adjustments based on the following pseudo-code:

<tr ng-repeat="par in parsInClassA">
    <td ng-show="onlyFirstTime" rowspan="pars.length">
        Class A
    </td>
    <td ng-show="onlyForFirstParInMode" rowspan="lengthOfParsInThisMode()">
        {{ par.mode }}
    </td>
    <td>
        {{ par }}
    </td>
    <td ng-repeat="par2 in parsInClassB">
        {{ matrixValue(par,par2) }}
    </td>
</tr>

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

Is it possible to delete a <div> tag based on screen size using jQuery or JavaScript?

Hello, I was curious if it's possible to dynamically remove a specific div tag using jQuery or JavaScript when the screen reaches a certain size, for example 500px. ...

Exploring the Latest Features: Using Angular 7 with Bootstrap Collapse for Dynamic Aria-Controls

I am currently working on creating my own component to use within an *ngFor loop. I am facing an issue where I need a unique value for my Collapse feature. Right now, when I click on the second main row in the table, the collapse feature only shows the inn ...

The droplist functionality in jQuery does not seem to be functioning properly within an ASP.NET MVC 5

After adding an external theme to my project and writing a script for listing data in a dropdown list on a separate page, I encountered an issue where the script works on other pages but not on the Layout theme page. HomeController Note: The partial view ...

Oops! The controller is not defined properly, it's showing as undefined

I have searched for solutions to the error mentioned above on various websites, including Stack Overflow, but I am still encountering the same issue. Here is the HTML code I am working with: <div ng-app="importContactsApp" class="modal fade" id="invite ...

Updating meta tags dynamically in Angular Universal with content changes

Hello, I'm encountering an issue with a dynamic blog page. I am trying to update meta tags using data fetched from the page. Here's the code snippet: getBlogPost() { this.http.get(...) .subscribe(result => { this.blogPost = re ...

Can basic logic be applied to CSS?

Recently, I have been experimenting with CSS to blur NSFW images in a chatroom until they are hovered over. I have successfully accomplished this task and now my next goal is to implement checkboxes that can toggle the display of these images. I am aware o ...

What is the best way to interact with a checkbox that has a label using Selenium in Node.js?

My HTML document contains multiple checkbox classes with different texts for each checkbox name. Here is a snippet of the HTML code: <div class="col-md-12 syllabus-div-1"> <h4 class="vertical-spacing">Coaching<i class="fa fa-graduation- ...

Unchecked checkbox displays as checked in UI

I am facing an issue with checking checkboxes using JavaScript. Even though the checkbox appears to be checked in the program, it does not reflect the updates on the user interface. If anyone has a solution for this, please share. <!DOCTYPE html> ...

Navigating with UI-Router within a single view for both viewing and editing purposes

I have been encountering an issue with changing states between the view page and edit page using UI-Router. Here are some of the things I have attempted: Controller: $stateProvider .state('showViewA', { views: { ...

Embed the div within images of varying widths

I need help positioning a div in the bottom right corner of all images, regardless of their width. The issue I am facing is that when an image takes up 100% width, the div ends up in the center. How can I ensure the div stays in the lower right corner eve ...

When I click on any input field, button, or other controls on a webpage, the page automatically zoom

I am currently trying to troubleshoot an issue with a bootstrap theme. It seems to be working perfectly on all browsers except for ios safari browsers. Whenever I click on an input field or button, the page suddenly zooms in. It's quite frustrating. ...

Updating token using an Ajax request in a PHP webpage

Currently, I am encountering an issue with my token system for requesting PHP pages via Ajax. The problem arises when attempting to make multiple Ajax requests from the same page as I am unable to refresh the token on the initial page. To elaborate furthe ...

Is it possible for comments in HTML and CSS to cause issues with rendering?

Could HTML or CSS comments potentially lead to rendering issues? HTML Comment Example: <!-- additional details --> CSS Example: /* more information */ ...

Creating an email-friendly button in Outlook without using images by styling a hyperlink with padding

Presenting a basic HTML code snippet - https://jsfiddle.net/mark69_fnd/6g0L0jwc/ <body style="background-color: white; font: normal 14px Verdana"> Hello <p></p> <a style=" font: bold 11px; text-decoration: none; background-color ...

Navigating Through Grid and Card Content in React

My goal was to minimize the amount of code by incorporating a reusable component into my application. I am facing an issue on how to iterate through the columns and rows in Grid, Card, and Table. What would be the optimal solution for this problem? Please ...

How can we use Angular Table to automatically shift focus to the next row after we input a value in the last cell of the current row and press the Enter key

When the last cell of the first row is completed, the focus should move to the next row if there are no more cells in the current row. <!-- HTML file--> <tbody> <tr *ngFor="let row of rows;let i=index;" [c ...

Implementing the React Router into a ReactJS project: Methods to prevent users from clicking on links within React-Router's <Link> component

I'm exploring React-Router's Link and have set up the following: <Link to={...}>{this.props.live? "Live": "Not Live"}</Link> In this configuration, if this.props.live is present, I want to display the text "Live" which will lead to ...

Is there a more effective method for concealing arrows while scrolling?

I'm attempting to conceal the arrow that appears above the selected header, as depicted below. https://i.stack.imgur.com/wyxdF.png While scrolling, I aim to hide the arrow that appears on the header Company, especially when the first column is sticky ...

Is there a more efficient method to tally specific elements in a sparse array?

Review the TypeScript code snippet below: const myArray: Array<string> = new Array(); myArray[5] = 'hello'; myArray[7] = 'world'; const len = myArray.length; let totalLen = 0; myArray.forEach( arr => totalLen++); console.log(& ...

Updating JavaScript files generated from TypeScript in IntelliJ; encountering issues with js not being refreshed

Struggling with a puzzling issue in IntelliJ related to the automatic deployment of changes while my server is running (specifically Spring Boot). I've made sure to enable the "Build project automatically" option in my IntelliJ settings. Whenever I ...