Nested Row Creation in an Angular Loop

This task seems to be more simple once you follow the correct steps. I am working with a bootstrap table and aiming to insert a row inside another row upon clicking a button. Currently, the new row is being added directly to the table. Although tables are new to me, I am learning as I go.

           <thead>
                <tr>
                    <th>Products</th>
                    <th>Quantity</th>
                    <th></th>
                </tr>
            </thead> 

A helpful Plunker example showcasing my issue is available at http://plnkr.co/edit/FMICwZC22KwzcYBGESAz?p=preview based on suggestions by @Coldstar

My Attempts So Far:

1) Trying a Nested Table but it was unsuccessful. 2) Adjusting the placement of my <tr> elements.

Your assistance would be greatly appreciated.

Expected Outcome:

I aim to insert a row after each product entry in the list.

->Row representing Product 1
 -->Nested Row for Delivery within Row of Product 1
->Row representing Product 2
 -->Nested Row for Delivery within Row of Product 2

Answer №1

Here is a suggested solution:

<table class="table table-striped">
    <tr ng-repeat="product in deliveryData">
        <td>{{product.productName}}</td>
        <td><a href ng-click="addItem($index)" class="btn btn-primary">Add delivery address</a></td>
        <td>
            <table class="table table-striped">
                <tr ng-repeat="delivery in product.deliveries">
                    <td>{{delivery.description}}</td>
                    <td>{{delivery.quantity}}</td>
                    <td><a href ng-click="removeDelivery($parent.$index, $index)" class="btn btn-primary">Remove</a></td>
                </tr>
            </table>
        </td>
    </tr>
</table>

In the controller: (Be aware that $scope.delivery should ideally come from a static form for future reference to avoid using the copy() function)

    $scope.delivery = {
        description: 'Hello World',
        quantity: 2
    };

    $scope.deliveryData = [
        {
            productName: 'Product A', quantity: '20', deliveries: []
        },
        {
            productName: 'Product B', quantity: '10', deliveries: []
        }
    ];


    $scope.addItem = function ($index) {
        var d = angular.copy($scope.delivery);
        $scope.deliveryData[$index].deliveries.push(d);
    };

    $scope.removeDelivery = function (par, chi) {
        $scope.deliveryData[par].deliveries.splice(chi, 1);
    };

Answer №2

To harness the full power of bootstrap, consider using the following structure:

<div class="container">
    <div class="row">
        <div class="col-md-5">
        </div>
    </div>
</div>

Bootstrap's divs are much simpler to style and allow for dynamic content within a row. This functionality is referred to as the grid system in bootstrap and can be explored further at the following links:

http://getbootstrap.com/examples/grid/

http://getbootstrap.com/css/#grid

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

Troubleshooting: Sticky navigation menu shifts unexpectedly to the right upon sticking

Whenever the scroll bar on my website at travismorenz.com reaches the sticky menu, it slightly shifts the menu over a few pixels. This issue can be observed by scrolling down slowly and watching the menu. The sticky menu functionality is achieved using th ...

Delete the current code within the specified div element

Objective: The goal is to ensure that any HTML syntax code or data inside the specified <div id="feedEntries"></div> element is removed, leaving it empty. Issue: What specific syntax is required to remove all content within <div id="fe ...

Troubleshooting the Google OAuth 2.0 SAMEORIGIN Issue

Trying to bypass the SAMEORIGIN error while using Google's JavaScript API is a timeless challenge. Here is an example of what I have tried: let clientId = 'CLIENT_ID'; let apiKey = 'API_KEY'; let scopes = 'https://www.google ...

What is the best way to upload several files using the jansy-bootstrap file upload feature?

I have implemented a custom control using Jansy Bootstrap to replace the asp.net FileUpload functionality. I was able to retrieve the file using HttpPostedFile by following guidance from this helpful answer: HttpPostedFile image = Request.Files["myFile"]; ...

Updating the image source using JQuery dynamically

Within my index.php file: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $('.on').click(function ...

Utilizing D3.js v4 to showcase a JSON file on a map

I am attempting to create a map similar to the one created by Mike Bostock. You can access my JSON file (here), which represents Europe divided into NUTS 2 regions. The structure of the JSON file is as follows: { "type": "Topology", "objects": ...

Extract the color of an individual character

There is a code snippet in JavaScript using p5.js that functions as a video filter: const density = ' .:░▒▓█' //const density = ' .tiITesgESG' //let geist; let video let asciiDiv let playing = false let ...

Browsing through json subgroups

Having issues with filtering an array within my JSON file. Filtering the main array works fine, but I'm struggling to filter subarrays. This is the structure of my JSON file: [ { "id": 1354, "name": "name", "type": "simp ...

What is the best way to consolidate multiple JS files into one main file that I can easily reference in my HTML code?

I've dedicated countless hours to watching videos and compiling a comprehensive library of assets, similar to p5.js (I'm especially fond of Dan Shiffman's content). I now have numerous files for various functions - init.js, dom.js, drawing.j ...

Uncovering the Android tablet browser: A guide

I have implemented the code below to detect mobile/tablet browsers. function isMobile() { var index = navigator.appVersion.indexOf("Mobile"); return (index > -1); } Although it works well for desktop browsers and iOS devices (iPhon ...

The method you are trying to call is not defined in Laravel

I recently developed a basic CRUD blog application with tags functionality. I have integrated tags into my pages and implemented the use of Select JS for selecting and editing tags in input fields. Now, my goal is to have the input field pre-populated wit ...

Attempting to retrieve and save data in a variable using React Native

click here for image referenceI am a beginner in react-native and I recently attempted to use fetch to access an API. While I successfully managed to print the result on the console, I encountered difficulty in displaying it on a mobile screen. Below is a ...

Is it possible to determine whether a path leads to a directory or a file?

Is it possible to distinguish between a file and a directory in a given path? I need to log the directory and file separately, and then convert them into a JSON object. const testFolder = './data/'; fs.readdir(testFolder, (err, files) => { ...

Prevent the function from being triggered repeatedly while scrolling

When a user scrolls to the bottom of the page, the following code is meant to load the next page. However, there are instances where it repeats itself due to rapid scrolling or while the AJAX content is still loading. Is there a way to prevent this code f ...

Clearing a textarea in jQuery

I'm experiencing an issue that I can't seem to resolve on my own. Any assistance would be greatly appreciated. My function designed to clear a textbox upon click doesn't seem to be working correctly: $(function() { $('textarea#co ...

Why is React's nested routing failing to render properly?

click here for image portrayal I am currently attempting to integrate react router, specifically a nested router. However, when I click the links on the contact page, no results are being displayed. Any assistance would be greatly appreciated. For more in ...

What is the method for adjusting the increment in noUiSlider?

I am trying to customize a slider using noUiSlider. The range is from 3000 to 300,000 and I want to ensure that the step from 3000 to 5000 is equal to 2000. Additionally, after five it should be equal to 5000. Is there a way to add a separator in the form ...

What is the best way to initiate a slideshow using an external .js file?

Having an issue with my slideshow. When I put the CSS and JavaScript code in the same page, it kind of "works" but quickly goes transparent, which is not ideal for me. I prefer keeping things organized with separate files - one for each. However, when I mo ...

In TypeScript, use a Record<string, any> to convert to {name: string}

I have developed a custom react hook to handle API calls: const useFetch: (string) => Record<string, any> | null = (path: string) => { const [data, setData] = useState<Record<string, any> | null>(null); var requestOptions: Requ ...

JavaScript failing to load specifically on Rails Spree Commerce site

Currently, I am experimenting with Spree commerce to improve my understanding of it. I have obtained an HTML theme () and my intention is to use it as the front-end design of the site, not for the actual store itself. The store will be accessed through /s ...