Obtaining row data from a table upon selection of an input checkbox with the help of Angular.js

Can someone assist me with fetching row data when a checkbox is selected using angular.js? Here is the code I am working on:

<tbody id="detailsstockid">
  <tr ng-repeat="p in viewIncompleteData">
    <td>
       {{$index+1}}<input type="checkbox" ng-model="checkboxModel.value1">   
    </td>
    <td>
       {{p.Product_name}}
    </td>
    <td>
       {{p.Discount}}
    </td>
    <td>
       {{p.Offer}}
    </td>
    <td>
       {{p.unit_cost_price}}
    </td>
    <td>
       {{p.unit_sale_price}}
    </td>
    <td>
       {{p.quantity}}
    </td>
    <td> 
    </td>
  </tr> 
</tbody>

<div style="text-align:center; padding-top:10px;" ng-show="updateButton">
   <input type="button" class="btn btn-success" ng-click="UpdateProductstockData();"  id="addProfileData" value="Add Total"/>
</div> 

When the user clicks on the Add Total button, the validation will be checked to see if any checkboxes are selected. If a checkbox is selected, the corresponding row data will be fetched inside the click event function. Can anyone provide guidance on this?

Answer №1

<tbody id="detailsstockid">
    <tr ng-repeat="p in viewIncompleteData">
    <!-- A new property has been added to the scope variable viewIncompleteData -->
    <td>{{$index+1}}<input type="checkbox" ng-model="p.isChecked">  </td> 
    <td>{{p.Product_name}}</td>
    <td>{{p.Discount}}</td>
    <td>{{p.Offer}}</td>
    <td>{{p.unit_cost_price}}</td>
    <td>{{p.unit_sale_price}}</td>
    <td>{{p.quantity}}</td>
    <td> 
  </td>
    </tr>   
    </tbody>

<div style="text-align:center; padding-top:10px;" ng-show="updateButton">
<input type="button" class="btn btn-success" ng-click="UpdateProductstockData();"  id="addProfileData" value="Add Total"/>
 </div>

Now, you can use viewIncompleteData[i].isChecked to identify which items are checked.

$scope.UpdateProductstockData = function(){
    angular.forEach($scope.viewIncompleteData, function(value, index){
        if(value.isChecked){
            // This row is selected
        }
    });
}

I hope this information is helpful for you.

Answer №2

In my opinion, it would be beneficial to use an array to keep track of the values of checkboxes in their respective columns (such as using ng-model="checkboxModel.value1[$index]"). When the ADD TOTAL button is clicked, you can trigger a function like the one below:

function fetchCheckedData(){
 for(var i=0;i<$scope.viewIncompleteData.length;i++){
  if(checkboxModel.value1[i]==true){
   var data=$scope.viewIncompleteData[i];
  }
 }
}

This function will fetch the row data when a checkbox is checked.

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

Keep sensitive information confidential by refraining from displaying values in the URL while using

When attempting to log in using Spring Security with an AJAX call, I noticed that the username and password are being displayed in the URL. For example: /?j_username=s&j_password=s I have been trying to identify my mistake for quite some time now but ...

In Internet Explorer 9, the cursor unexpectedly moves up above the element

Within my MVC3 application, I have implemented a feature to change the cursor when hovering over an element. Below is the JavaScript code that accomplishes this: $('#print').hover(function () { var cursorUrl = 'url(@Url.Content("~/Cont ...

Rails and JavaScript: Changes made to the HTML on the page no longer trigger the UJS .change() function

I have successfully implemented a rendering partial with UJS, but there's a problem: The partial is able to update the form's markup that triggers the onchange action. However, the JavaScript on this newly updated markup stops working. As a res ...

Mobify enables the activation of jQuery Tabs on carousels

Looking to implement a tab menu above my Carousel that will correspond to different packages within the carousel when clicked. Additionally, I want the tabs to adjust accordingly when the carousel is swiped, ensuring that the active tab reflects the curre ...

Connecting a Kendo Dropdown menu to external data sources for seamless integration

I need help with binding data to a dropdown list for my local service. Whenever I try to download the data, I keep getting an error message: Uncaught SyntaxError: Unexpected token: Does anyone have any ideas on how to resolve this issue? This is my JS ...

Is it possible to instantiate a Backbone view by referencing its string name that is stored within a JavaScript object?

I am currently working on a visual builder that utilizes different views for each component. Each view is defined as shown below: $(function() { var parallaxView = new Backbone.view.extend({ .... }); var parallaxView = new Backbone.view.e ...

Styling div elements to match the dimensions of table rows in CSS

When it comes to CSS, I wouldn't call myself an expert; My question is: is there a way for a div tag to inherit dimensions from specific table rows based on their class or id? For instance: Imagine we have a table with multiple rows, but we don&apos ...

Implemented a deletion feature in the list, however, certain items that have been checked are not being removed

I am currently participating in the Wes Boros JS 30 challenge, where we created a list of our favorite foods. As part of the challenge, we were tasked with implementing a 'select all' function, an 'unselect all' function, and a 'de ...

What are the potential reasons for a function in React not being identified as a function?

I recently started learning React and decided to follow this YouTube tutorial on creating a TO DO LIST using React. https://www.youtube.com/watch?v=E1E08i2UJGI Everything seems to be in place, but when I try to interact with my form by typing something an ...

arrange objects based on their position using javascript

In my JavaScript code, I am trying to position objects above each other relative to a center point at coordinates 0,0. The number of objects, their sizes, and the spacing between them are all variable. This image illustrates my situation best (hopefully ; ...

"How to effectively utilize the AgnularJS ng-model directive in your code

What is the purpose of using the ng-model directive in this AngularJS example? Although the code works without it, simply removing the ng-model directive and setting the myCol variable to a valid background color value will suffice. So why include the ng ...

Invoking a function within an Angular component

I am facing a problem - is there a way to invoke a function from the name.component.html file without using a button click, and without needing to go through the .ts file or service? ...

Retrieve documents from a nearby directory using an online platform

I have a gridview in an aspx page that needs to display all the xml files from a folder on the client machine. Is there a way to retrieve the contents of a folder using the directory path? I currently have code that works when running it locally, but I am ...

The Ray Intersect function in THREE.js encounters issues when a div element is introduced

I have encountered an issue with my Three.js script. It works perfectly fine when there is only one target div on the page holding renderer.domElement. However, when I add another div with fixed height and width above the target div, the ray.intersectObjec ...

Jquery functions are failing to work in a fresh window

I am facing an issue with my project codes where I need to open a new window, display its contents, and then replace a specific div with some content. However, the JavaScript functions in the new window are not working. How can I enable JavaScript function ...

Implementing angularjs into grails version 2.3.4

I have a page named index.gsp and I want to include my angularjs library files: <head> <meta name="layout" content="main" /> <title>Title Page</title> <!-- loading angularjs --> <r:require module="angular" /> </hea ...

Can anyone recommend a reliable continuous integration pipeline for StrongLoop and GitHub integration?

How can you effectively develop websites using strongloop and github/bitbucket, ensuring smooth transitions from development to testing to production? I understand the key components of a successful workflow, but I'm interested in hearing about strat ...

Issue with Tailwind classes not applying correctly upon refreshing the page in production settings

Challenge Description: Encountering an issue with my nextjs project that utilizes tailwindcss. The login page initially loads with the required classes for the UI, but upon refreshing the page, the classes disappear from the DOM, causing a broken UI. Her ...

Utilizing JSON information acquired through AJAX within a distinct function

Sorry if this question has been asked before, I tried following suggestions from another post but they didn't work for me. What I'm trying to do is fetch some JSON data, save a part of it in a variable, and then use that variable in a different f ...

What steps should I take to address the issue with my navbar?

I've written some code that creates a hamburger icon on mobile devices. When the user clicks it, a wave effect covers the screen, but I'm facing an issue where the wave doesn't cover the input field. My query is: how can I make the input fi ...