AngularJS and numerous parallel indexed tables side by side

I need help with displaying two tables, one for profiles and the other for rates. The rates are connected to profiles through the rate name in the JSON data. Is there a way to show these two tables side by side? And when a row is selected in the profile table, can we automatically display the associated rate names in the rates table?

Sample JSON data:

[
  {
    "profileName": "Phone3Bit",
    "profileDescription": "A profile example of 3 bit rates",
    "segmentsToKeep": 15,
    "segmentLength": 10,
    "lmsOutputStreams": [
      "5Mbit",
      "3Mbit",
      "2Mbit"
    ]
  },
  {
    "profileName": "PhoneHD1",
    "profileDescription": "3 bit rate profile for phones",
    "segmentsToKeep": 15,
    "segmentLength": 10,
    "lmsOutputStreams": [
      "4Mbit",
      "3Mbit",
      "2Mbit"
    ]
  }
]

Angular code snippet:

    $http({
        method: 'GET',
        url: 'http://192.168.0.3:8080/profiles.json',
        headers: {
            'Accept': 'application/json'
        }
    }).then(function successCallback(response) {
        console.log('ProfileCtrl - $http success!');
        $scope.profiles = response.data;
        console.log('ProfileCtrl - data: ', response.data);
        console.log('ProfileCtrl - status: ', response.status);
        console.log('ProfileCtrl - headers: ', response.headers);
        console.log('ProfileCtrl - config: ', response.config);
    }, function errorCallback(response) {
            console.log('ProfileCtrl - $http failure!');
    });
<div class="row">
     
    <!-- Profile Table -->
    <!-- Profile Table -->
    <!-- Profile Table -->
     
  <div class="col-lg-6">
    <rd-widget>
      <rd-widget-header icon="fa-users" title="Profiles">
          <input type="text" placeholder="Search" class="form-control input-sm" />
  </rd-widget-header>
      <rd-widget-body classes="medium no-padding">
        <div class="table-responsive">
          <table class ="table">
          <thead>
              <tr><th>Name</th><th>Description</th><th>Segments To Keep</th><th>Segment Length</th></tr>
          </thead>
          <tr ng-repeat="profile in profiles | orderBy : 'profile.profileName'">
              <td ng-if="$odd" style="background-color:#f1f1f1">{{ profile.profileName }}</td>
              <td ng-if="$even">{{ profile.profileName }}</td>
              <td ng-if="$odd" style="background-color:#f1f1f1">{{ profile.profileDescription }}</td>
              <td ng-if="$even">{{ profile.profileDescription }}</td>
              <td ng-if="$odd" style="background-color:#f1f1f1">{{ profile.segmentsToKeep }}</td>
              <td ng-if="$even">{{ profile.segmentsToKeep }}</td>
              <td ng-if="$odd" style="background-color:#f1f1f1">{{ profile.segmentLength }}</td>
              <td ng-if="$even">{{ profile.segmentLength }}</td>
          </tr>
          </table>
        </div>
      </rd-widget-body>
      <rd-widget-footer>
        <button class="btn btn-sm btn-info">Add</button>
        <div class="clearfix"></div>
      </rd-widget-footer>
    </rd-widget>
  </div>
     
    <!-- Rate Table -->
    <!-- Rate Table -->
    <!-- Rate Table -->
     
  <div class="col-lg-6">
    <rd-widget>
      <rd-widget-header icon="fa-users" title="Rates">
          <input type="text" placeholder="Search" class="form-control input-sm" />
  </rd-widget-header>
      <rd-widget-body classes="medium no-padding">
        <div class="table-responsive">
          <table class ="table">
          <thead>
              <tr><th>Name</th><th>Description</th><th>Segments To Keep</th><th>Segment Length</th></tr>
          </thead>
          <tr ng-repeat="rate in profiles.lmsOutputStreams track by $index'">
              <td ng-if="$odd" style="background-color:#f1f1f1">{{ $index }}</td>
              <td ng-if="$even">{{ $index }}</td>
          </tr>
          </table>
        </div>
      </rd-widget-body>
      <rd-widget-footer>
          <br>
            <div class="clearfix"></div>
        <p></p>
      </rd-widget-footer>
    </rd-widget>
  </div>
</div>
</div>

Answer №1

To achieve what you are looking for, you will need a 'selectedProfile' object to display the rates associated with that profile.

Here is an example:

// Add ng-click to pass the selected profile to the controller in the first table
<tr ng-repeat="profile in profiles | orderBy : 'profile.profileName'"
    ng-click="selectProfile(profile)">

// Display rates for the selectedProfile in the second table
<tr ng-repeat="rate in selectedProfile.lmsOutputStreams track by $index'">

In your controller:

$scope.selectProfile = function(profile){
   $scope.selectedProfile = profile;
}

It's worth noting that using unnecessary 'ng-if' directives just for styling purposes can lead to performance issues due to the extra angular watches being created. You can achieve the same styling effects using simple CSS without impacting performance.

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

Utilizing JQuery UI autocomplete for dynamically loaded textbox using AJAX

<div id='toolbox'> <div class='placeholder'></div> </div> In my project, I am using a click event to dynamically load a text box into the placeholder. $('#toolbox .placeholder').load('http:// ...

Retrieving the NorthEast and SouthWest regions with AngularJS

Check out my code on the fiddle page linked below. I am having trouble with the South West and North East coordinates for the map and markers. View the code fiddle here I attempted to solve this issue, but it did not work as expected. var bounds = map ...

Is it possible to remove an angular object from an array without affecting its $$hashKey?

Having a discussion that involves adding a Master Carton to an array of Master Cartons. A repeater displays one or more Master Cartons: <div ng-repeat="carton in dimensionsModalVm.masterCartons"> <div class="form-grou ...

Disappear solely upon clicking on the menu

Currently, I am working on implementing navigation for menu items. The functionality I want to achieve is that when a user hovers over a menu item, it extends, and when they move the mouse away, it retracts. I have been able to make the menu stay in the ex ...

The click event is triggering before it is able to be removed by the code preceding the trigger

Here's a scenario I recently experienced that involves some code written using JQuery. It's more of a statement than a question, but I'm curious if others have encountered this as well: <input type="submit" value="Delete" o ...

Loading WordPress posts using Ajax

Struggling with getting an Ajax post loader to work properly. Following the jQuery code from a previous StackOverflow post titled "Load More Posts" with Ajax in WordPress, but still facing issues. Trying to implement an isotope list for ajax loading more p ...

Is there a way to customize CKEditor to prevent it from continuously adding <p></p> tags within the textarea automatically?

As I was going through the CKEditor tutorial, I implemented the following: $( '#editor' ).ckeditor(function(){}); //it's working great!! However, after submitting the form, I noticed that by default, the textarea displays <p></p ...

Transforming an array of JavaScript objects into arrays of key-value pairs based on a specific property with ES6 syntax

Consider an array of objects like this: myArray = [ {name: 'First', parent: 1, delta: 2}, {name: 'Second', parent: 1, delta: 1}, {name: 'Third', parent: 2, delta: 1} ]; The goal is to transform this array into an objec ...

Evaluating the functionality of Express Js Server with mocha and chai

I'm currently struggling to properly close the server connection in my Express server when testing it with Mocha and Chai. It seems that even after the test is completed, the server connection remains open and hangs. Index.js const express = require( ...

Ways to synchronize countdown timer on different tabs using the same link

Is there a method available to synchronize a React countdown timer across two separate tabs, for example: 1:46          ||   1:52 first tab     ||   second tab Appreciate any help! ...

Combining broken down values within a loop

Take a look at this image, then review the code I've provided: function addNumbers() { var inputList = document.getElementById("listInput").value.split(" "); for(i = 0; i <= inputList.length; i+=1) { document.getElementById("resul ...

Show occurrences of an array categorized by date using JSON format

I'm interested in analyzing a JSON array to find the occurrences of a specific item by date. Let me demonstrate with the following JSON example: "data": [ { "tags": [ "foo", "bar", "hello", "world", " ...

Tips for triggering jquery code when a variable containing a CSS attribute is modified

I have a specific requirement where I need to reset the scrollleft value to 0 on my wrapper whenever a particular CSS property changes. Although I am new to using jQuery and haven't worked with variables much, I believe I need to create a variable to ...

How can CORS be activated? Is it through the server or Javascript, and where does this

Currently, I am testing my ReactJS website on localhost:3333 and my ASP.NET Web API 2 on localhost:54690. I am utilizing axios for my AJAX requests, but encountering an error when making a request. XMLHttpRequest cannot load http://localhost:54690/api/ ...

Searching in real time using Ionic 1.x

I'm currently working on implementing a real-time search feature for my extensive product database. I attempted to replicate the provided example, and while my web service is functioning properly, I am unable to view any selectable items. Seeking gui ...

Empty req.body object in Node.js

I came across this code snippet: const bodyParser = require("body-parser"); const express = require("express"); const app = express(); app.use(express.json()); app.use(bodyParser.json()); app.post("/api/foo", (request, response) => { let foo = { ...

The 'else' statement within a for loop modifies the value within an array

Hey there, I have encountered a peculiar issue with the else clause in my conditional statement. It seems to be rewriting the value in the array even when it has already found a match. Any thoughts on why this could be happening? Check out the code snippet ...

Passing information from a directive to a controller using AngularJS

I am looking to display the progress of a file upload using a file reader. Here is the HTML code snippet I have: <md-progress-linear id="file-progress-indicator" md-mode="determinate" value="{{progress}}"></md-progress-linear> and below is m ...

Having trouble configuring individual route files in Express JS

I'm having trouble separating my login route from the default app.js and route/index.js files. When I try to access localhost:3000/login, I keep getting a 404 Not Found error. I've searched on StackOverflow for similar questions and tried follow ...

The jQuery script designed to verify the page height doesn't appear to be functioning as intended

Below is a snippet of jQuery code that I'm working with: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> hasVBar=""; hasHBar=""; $(docume ...