Creating an HTML table with colspan and rowspan using ng-repeat from a deeply nested JSON dataset

I'm working on creating a table layout shown in the attached image: Composite Class Routine

Check out my progress so far in this Plunker demo:

https://plnkr.co/edit/4WiWKDIM2bNfnmRjFo91?p=preview

The JSON data I'm using is as follows:

$scope.routines = [
    {
        "WEEKDAY_ID": 1,
        "WEEKDAY": "Sunday",
        "aSemester": [
            {
                "SEMESTER_ID": 1,
                "SEMESTER_NAME": "1st",
                "aClassTime": [
                    {
                        "COURSE_ID": 1,
                        "COURSE_CODE": "CSTE-1001",
                        "CLASS_DURATION": 3,
                        "CLASSTIME_ID": 1,
                        "CLASSTIME": "9.00-9.50",
                        "DEPT_ID": 1,
                        "DEPT_NAME": "Computer Science",
                        "BUILDING_NAME": "Academic-1",
                        "ROOM_NO": 101,
                        "LAB_GROUP": null,
                        "INSTRUCTOR_ID": 10,
                        "INSTRUCTOR_NAME": "Abhijit Chakraborty",
                        "SHORT_CODE": "AC"
                    },
                    ...
                ]
            },
            ...
        ]
    }
];

Here's the HTML structure I've been experimenting with:

<table id="routines" class="table table-bordered table-responsive table-condensed">
<thead>
  <tr>
    <th>Day</th>
    <th>Semester</th>
    <th ng-repeat="c in classtimes">{{c.CLASSTIME}}</th>
  </tr>
</thead>

<tbody ng-repeat="r in routines">
   <tr ng-repeat="s in r.aSemester">
     <td rowspan="{{r.aSemester.length}}">{{r.WEEKDAY}}</td>
     <td>{{s.SEMESTER_NAME}}</td>
     <td colspan={{c.CLASS_DURATION}} 
         ng-repeat="c in s.aClassTime">
        {{c.COURSE_CODE}}
      </td>
   </tr>
</tbody>

Please feel free to provide any guidance or feedback. Thank you!

Answer №1

Make the following changes in your table body

<tbody>
  <tr ng-repeat-start="r in routines">
    <td rowspan="{{r.aSemester.length+1}}">{{r.WEEKDAY}}</td>

  </tr>
  <tr ng-repeat="aSem in r.aSemester">
    <td>{{aSem.SEMESTER_NAME}}</td>
    <td ng-repeat="c in classtimes">
      <span ng-repeat="classTime in aSem.aClassTime">
        <span ng-if="classTime.CLASSTIME_ID==c.CLASSTIME_ID">
          {{classTime.COURSE_CODE}}
        </span>
      </span>
      </td>
  </tr>
  <tr ng-repeat-end ></tr>
</tbody>

This should provide the solution you're looking for.

Plunkr https://plnkr.co/edit/QFUouMmSKtBiAWMdGpCC?p=preview

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

Dynamic row addition in Material Design Lite table causes format to break

Here's the HTML markup for creating a checkbox using material-design-lite: <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="checkbox"> <input type="checkbox" id="checkbox" class="mdl-checkbox__input" /> <span c ...

What is the best method for creating a loop script within a widget using script?

I am trying to implement a loop within a widget, however, the widget contains an internal script: <!DOCTYPE html> <html><head></head><body> <script> list=["AMAR3","BBDC4", "BEEF3", "BPAN4", "BRFS3", "B3SA3", "CVCB3" ...

The grid layout in Bootstrap 4 does not seem to be compatible with dompdf

I am in the process of using dompdf for rendering a PDF file. Our application is built on Bootstrap 4 framework, and I want to incorporate it into the twig template used for generating our documents. However, I have encountered an issue with the Bootstrap ...

Activate Popover with Hover and simply click anywhere to dismiss

Currently utilizing Bootstrap 4 and intrigued by the popover feature that activates on hover and closes when clicked anywhere. I'm also interested in making links functional within the popover. Any suggestions or tips on how to achieve this? $(doc ...

Receiving an error stating “angular is not defined” when attempting to use an external controller file in AngularJS

I have the following controller defined in an external file, but when I try to run my node server, I get an 'angular is not defined' error. vaultcontroller.js angular.module('demoapp.vaultcontroller', []) .controller('vau ...

Elements that are hidden or not displayed are still able to receive mouse over events

I am in the process of learning how to handle events within svgs and I have encountered a strange issue. Currently, I am working on an infovis project where I create an interface to display various column-graphs. This part is functioning well so far. Ho ...

When using ClientHttpRequestInterceptor with Spring RestTemplate's postForObject method, the object response may sometimes be null

When attempting to consume a REST service by posting some data with Spring's RestTemplate, I am receiving a null response despite being able to see the request and response payloads. [Update] I have implemented an interceptor using ClientHttpRequestI ...

Having trouble with the functionality of Bootstrap's nav-tabs 'show' feature?

I'm having some issues with adding a search box to my glossary. The glossary is created using nested unordered lists (ul) within another ul that has classes of "nav-tabs" and "bootstrap". In the JavaScript code, I am using the following snippet: $j(& ...

Leveraging the power of font awesome icons as background images within React applications

I am facing an issue with my dropdown menu. I have styled the caret using CSS background-image property, but now I would like to use a Font Awesome icon instead. I attempted to implement two different styles for the background image with no success. The d ...

What is the best way to place text alongside a shape?

I'm attempting to place text beside the circular shape. HTML <div class="row"> <div class="col-sm-2"> <span><div class="circle"></div></span><p>available</p> </div> </div> C ...

Which type of encoding does json.dumps utilize?

While utilizing json.dumps in Python 3.8, I noticed that special characters are getting "escaped", like so: >>> import json >>> json.dumps({'Crêpes': 5}) '{"Cr\\u00eapes": 5}' I am curious to know ...

What steps should I follow to incorporate a customized class into my Windows Forms 2.0 project?

Exploration I encountered an issue while trying to incorporate a customized class into my project for the purpose of deserializing and manipulating JSON data stored in a text file. Here's the code snippet that represents the class: Imports Newtonsoft ...

Harnessing the power of Selenium to locate an anchor tag containing HTML elements with specific classes

I have a specific element on my webpage that I need to extract the text "Add New Member" using Selenium. Here is the HTML code for the element: <a ng-if="userCanEdit" class="btn btn-primary ng-scope" ui-sref="orgs-add" href="#/orgs/add"> <i& ...

The Jquery animate function is not compatible with the transform property

I am facing an issue with the Jquery animate function. Despite trying various solutions, I have been unable to get it to work. Below is the HTML code that I have used: <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

"Stunning Broth: Retrieve elements from a list without the need for comma

I am attempting to extract a list of cities from a webpage using Beautiful Soup The current output is: MonroeMatthewsWaxhawIndian Trail, Matthews What I want is: Monroe, Matthews, Waxhaw, Indian Trail, Matthews This is the HTML: <div id="current_tab ...

Align the tops of the tables

I currently have three tables in my HTML code. When all three tables are filled with data (10 rows each), they appear correctly aligned as shown in the first picture. However, if any of the tables do not have the maximum capacity of 10 rows reached, they ...

How to achieve a Dropbox-inspired footer effect using CSS?

Take a look at dropbox's website here: Have you noticed how the footer with "Learn more" remains fixed at the bottom regardless of window resizing until you click or scroll down? position: absolute; bottom: 50px; left: 0; width: 100%; text-align: ce ...

Creating a p5.js circle on top of an HTML image: A step-by-step guide

Currently, I am integrating an image into my web application using standard JavaScript and HTML. The image represents a basic map, and my objective is to utilize p5.js to draw on it. <div id="map"> <img src="Assets/MENA.jpg" ...

Sending data from a form to a PHP script via a variable transfer

i have a form structured like this: <form action="del.php" method="post" enctype="multipart/form-data"> Number of field to display:<input type="text" name="limit" /><br /><br /> Top category: <select name="topcat"> <opt ...

Using a single datalist in HTML5 to define options for multiple input elements

When working with HTML5, I discovered that you can create multiple input elements that share the same option list like this: <datalist id="list1"> <option value="A"> <option value="B"> </datalist> input1: <input list="l ...