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

Compare the selected values of radio buttons with an array and find matches

I have multiple radio button groups, where each selection in a group corresponds to predefined values in an array. For example, selecting option 1 in Group 1 will increment values A and B by 1, while selecting option 2 will increment B, C, and D. The goal ...

Activate the popup for sharing or bookmarking by clicking on a regular link

I am currently utilizing a Share/Bookmark script: <div class="singles-right"> <a href="#" class="bookmark"></a> <script type="text/javascript" src="http://static.addinto.com/ai/ai2_bkmk.js"></script> <a href="#" clas ...

Scroll horizontally within the div before scrolling down the page

After reviewing other questions, it's important to note that the scroll I am looking for is horizontal, not vertical. My goal is to have a div on a page automatically start scrolling when it reaches the center or becomes visible, and then allow the pa ...

Retrieving components of an array

I am looking to extract elements from an array, then store them in a new array and compare them to another array. The challenge is that I do not want to extract the elements in a specific order. I have tried using the .slice function for extracting element ...

Retrieve a specific value from an array within Firestore

I am facing an issue where I can only retrieve the values I need from the array by adding a specific string like "اقلام" or "سبورة". However, I want the value to be passed as a prop from another component or screen. Is there a way to resolve this ...

What is the best way to encapsulate a function that uses `this.item.findElement()` from Selenium in a separate file?

I'm currently working on setting up a Selenium Webdriver and Cucumber.js test environment using Node.js. In the homePageSteps.js file, I have a check to verify if a banner exists on a page: Then('there should be a banner', async function() ...

Next.js - utilizing dynamic API routes within nested folders

Currently, I am working on developing a basic API that reads a local JSON file. My goal is to create a dynamic API that can adjust based on the specific calls it receives. Within my API folder structure, I have: api --book ---[id].js ----content -----[id ...

Creating a customized date picker design with Material UI

Instead of displaying the date in DD/MM/YYYY format, I would like to show "Today" text. For example, when using a datepicker, the browser may display a date like 20/1/2009. However, I want it to show "Today" instead of that specific date. ...

What causes TypeScript's ReadonlyArrays to become mutable once they are transpiled to JavaScript?

Currently, I am in the process of learning Typescript by referring to the resources provided in the official documentation. Specifically, while going through the Interfaces section, I came across the following statement: TypeScript includes a special t ...

Efficiently Transmitting JSON Data via HTTP Requests

I have the following: Route file "prontuarios.js": module.exports = function(app){ getProntuarios = function(request, response, next){ var sqlCustom = request.query; var connection = app.infra.connectionFac ...

Is there a way to prevent this React function from continually re-rendering?

I recently created a small project on Codesandbox using React. The project involves a spaceship that should move around the screen based on arrow key inputs. I have implemented a function that detects key presses, specifically arrow keys, and updates the ...

Is it possible to add a vertical scrollbar to the vertical navigation pills on a Bootstrap

Is it possible to create a vertical scroll bar for my nav pills when they exceed the screen size? /* * * ========================================== * CUSTOM UTIL CLASSES * ========================================== */ .nav-pills-custom .nav-link { c ...

Having trouble with ng-model in Angular Select (attempting to set default selection)?

Here is the code I am using: <div ng-repeat="department in storeData.departments"> <p>{{department.currentManager.fullName}}</p> <select ng-model="department.currentManager" ng-options="user.fullName for user in department.us ...

Managing input jQuery with special characters such as 'ä', 'ö', 'ü' poses a unique challenge

Hey there, I'm running into a bit of trouble with my code and I can't figure out why it's not working. Here's a brief overview: I created my own auto-suggest feature similar to jQuery UI autosuggest. Unfortunately, I'm unable t ...

Improve the translation animation on an element containing numerous child nodes

Looking for ways to enhance the smoothness of the transition in the "infinity list" animation. While it's just a demo at the moment, the real app will have various elements emerging from each "pin". The main performance bottleneck seems to stem from t ...

A guide on verifying a phone number using just one character

I am looking to validate a phone number with only one character being allowed. For example, the format should be XXX-XXXXXXX where "-" is the only allowed character. Below is my validation function: function validatePhoneNumber() { if(addform.staff_m ...

Checking localStorage before sending a request with ngResource

Is there a way to check localStorage before ngResource sends a request? I want my resource object to first look in local storage before making a call to the server. Ideally, I'd like to save the initial response from the server in local storage so tha ...

What could be causing the poor performance of WebGPU in my benchmark when compared to WebGL?

After running my benchmark code on the Latest Chrome Canary on Win11 and disabling vsync with unlocked fps, I noticed that WebGPU has around 1/3 the FPS of WebGL. I'm struggling to understand the reason behind this performance difference. Here is the ...

What is the best method for adding a header to a dynamically created table using JavaScript?

After receiving JSON data in my JavaScript, I have successfully converted it into an HTML table. Everything seems to be working fine, but I'm wondering how I can add a header to my table? Below is the code snippet: <script> $(document ...

Alter the website link in an HTML file as well as in the corresponding CSS and JavaScript

Is it possible for JQuery to alter URLs within a CSS or Javascript resource before they are loaded into the browser, or even as they load in the browser? URLs typically point to resources such as images and fonts. I have been considering this idea becaus ...