When the checkAll checkbox is clicked, transfer its elements to a new array object and delete them from the original array

I am looking to add a new functionality where clicking on the "select All" checkbox will move the selected items to a new array and remove them from the current one.

Although I tried using the splice function, I was unsuccessful in deleting all items from the first table.

Please help Here is a sample plnkr that I have put together. When I click on "select All" in the first table, I want all its items to be added to the "New Table" and simultaneously removed from the "First Table (named Old Table)

Answer ā„–1

By utilizing the pushlist function in your code, you can effectively clear the array and populate it with all entries stored in $scope.merged.

$scope.pushlist = function(data){
    for(var item of data){
        $scope.merged.push({"name":item.name});
    }
    data.length=0
};

Answer ā„–2

Utilize angular.copy in order to create a duplicate of the object

var app = angular.module("myApp", []);

app.controller("SecondCtrl", function($scope) {
  $scope.merged = [];
  $scope.data = [{
    "name": "ABC",
    "selected": false
  }, {
    "name": "HJK",
    "selected": false
  }, {
    "name": "PQR",
    "selected": false
  }, {
    "name": "LMN",
    "selected": false
  }];

  $scope.selectall = function(checkAll) {
    if (checkAll) {
      $scope.merged = angular.copy($scope.data);
      $scope.data.length = 0;
    } else {
      $scope.data = angular.copy($scope.merged);
      $scope.merged.length = 0;
    }
  };
});
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.js"></script>
<div ng-app="myApp" ng-controller="SecondCtrl">
  <div>
    <h1>Old Table</h1>
    <table>
      <thead>
        <th>
          <input type="checkbox" ng-click="selectall(checkAll)" ng-model="checkAll">Select All</th>
        <th>Name</th>
      </thead>
      <tbody>
        <tr ng-repeat="item in data">
          <td>
            <input type="checkbox" ng-model="item.selected">
          </td>

          <td>{{item.name}}</td>
        </tr>
      </tbody>
    </table>
  </div>
  <hr>
  <div>
    <h2>New Table</h2>
    <table ng-show="merged">
      <thead>
        <th>Name</th>
      </thead>
      <tbody>
        <tr ng-repeat="item in merged">
          <td>{{item.name}}</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

Fiddle Demo

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

What is the method for invoking a component with an event in Vuetify?

Currently, I am working on implementing a SnackBar component on my website. The requirement is that the snackbar should appear when the user clicks the submit button. How can I pass my snackbar component to the button inside my Add.vue file? I want to be a ...

Using Javascript to enable a button to perform multiple actions on an element

In my current setup, there are buttons that can adjust the height, color, and opacity of a box. For example- document.getelementbyID("growbutton").addEventlistener("click", function growFunction() { document.getelementbyID("box&q ...

Adjusting a parameter according to the width of the browser window?

Using Masonry, I have implemented code that adjusts the columnWidth to 320 when the screen or browser window width is less than 1035px. When the width exceeds 1035px, the columnWidth should be 240. However, the current code keeps the columnWidth at 320 re ...

Calculate the UV coordinates for a trio of CSG meshes

During a university project, I created a ThreeCSG subtraction in ThreeJS. The challenge I am facing now is applying a texture to this mesh due to the missing UV coordinates after processing. The project requirement mandates that it must be a ThreeCSG objec ...

Iceweasel 31.2 is having trouble executing basic CSS code

Currently working on a website for a family member, I have created a section that starts off hidden (display: none) and fades in when the user clicks anywhere on the page. The functionality is smooth on Chromium, however, when testing it on Iceweasel 31. ...

Why is AngularJS displaying the markers instead of the routes on Google Maps?

I placed my marker on the map and expected to see connecting routes between them, but only the markers are visible without any routes. This is quite confusing. var cities = [ { place : 'Universal Studio', ...

When using a for loop in HTML5 Canvas, the result of the toDataURL function will consistently remain

Check out this JSFiddle. The goal is to select images and then encode them in base64 using canvas to store them in sessionStorage for later uploading. However, despite looping through each image, the base64 encoded output remains the same every time. Even ...

The best way to upload a file using the blueimp file upload plugin in a single attempt

I've implemented the bluimp jQuery-File-Upload-plugin on my website. Everything works fine when selecting and uploading files, but I'm facing an issue where if I try to upload additional files without refreshing the page, the previously uploaded ...

Node.js user update complete

I am currently working on enabling users to edit their profiles. However, the code I have set up does not seem to be functioning as expected. The form I am using looks like this: <form action="/dashboard/users/edit/:id" method="put"> And my route ...

JavaScript countdown timers should maintain their progress even after the page is reloaded

I am encountering an issue with a timer on my checkout page. We have a 2-step checkout process, and after completing step 1, the webpage reloads to step 2, causing the timer to restart. I need the timer to continue counting without resetting. Below is the ...

The initial output of the object yields an undefined value

Issue Description (View Code on Fiddle): The issue with this code is that the first printed result returns 'undefined'. Why does this happen and how can it be fixed? Code Snippet: var animals = { dogs: 0, cats: 0, birds: 0, fis ...

Is it possible to customize the mounting element of NextJS or apply additional classes to the __next div?

In a nutshell, I'm currently working on a project where my aim is to make the content "fill" the vertical space below the static header. Previously, in React with tailwind, I achieved this like so: <body class="flex flex-col h-screen text-gray ...

The jsonData fails to display on the console without any errors, it simply refuses to print

.controller('StocksCtrl',['$scope','$stateParams','$http', function($scope, $stateParams) { //Retrieving stock data from Yahoo Finance API $http.get("http://finance.yahoo.com/webservice/v1/symbols/YHOO/quo ...

Safari IOS causing issues with Vue 2.6 functionality

I have implemented a button that, when clicked or pressed, triggers a click event on an input type=file, allowing the user to upload a file. This functionality works seamlessly on all platforms, but there is an issue with Safari/iOS Safari. In Safari, when ...

Unlocking the potential of promises in AngularJS

Is there a way to modify this code in order to achieve the desired output? I need to utilize the AgentReply object once it has been populated with data. The issue is that within the switch case, the object holds data, but outside of it, the object become ...

Saving data from an AJAX POST request using XMLHttpRequest in JavaScript and PHP to a text file is causing

Iā€™m facing an issue with transmitting data from an HTML textbox to JavaScript and then using AJAX to send the data to PHP for saving in a text file. The problem lies in the fact that while AJAX successfully directs itself to PHP, the latter fails to rece ...

Is it possible to incorporate a React app as a component within a static HTML page?

Looking to integrate the react-csv-viewer component into a static HTML page without deploying it on a local server. I've tried following the instructions from the React tutorial, but am struggling with the build process. My goal is simple - to use th ...

Is there a way for me to identify a click within a region where a jQuery plugin is already actively monitoring clicks?

I have successfully implemented the jQuery Bar Rating Plugin on my website. The plugin works perfectly, allowing users to turn a select list into clickable images. However, I am facing a challenge in revealing a hidden field on the page when a user selects ...

Adjust the color of the input range slider using javascript

Is there a way to modify the color of my slider using <input type="range" id="input"> I attempted changing it with color, background-color, and bg-color but none seem to work... UPDATE: I am looking to alter it with javascript. Maybe something al ...

Dot/Bracket Notation: flexible key assignments

I have an item that contains various image URLs accessed through data[index].gallery.first.mobile/tablet/desktop "gallery": { "first": { "mobile": "./assets/product-xx99-mark-two-headphones/mobile/image-gallery-1.j ...