Copying data from a table to another in Angular 2 with the help of Angular Material

Incorporated a simple table in angular 2 using angular material. I have two mat-tables where selected rows from the first table are transferred to the second table by clicking Move To Table 2, and vice versa when clicking Move To Table 1.

When selecting and Moving To Table 2, the row from the first table is spliced and transferred successfully. However, when I repeat the process for the second row, the previously transferred row reappears in my second table.

Check out an example here

Below is my output:

Initially, transferring the first row removes it from the first table and moves it to the second table. https://i.sstatic.net/63gti.png

However, when transferring the second row, the previously moved row reappears in the second table. https://i.sstatic.net/no3R8.png

Answer №1

The reason for this issue is because the selection is not being cleared after the transfer from one table to another.

To fix this problem, make sure to clear the selection once the move is complete.

Simply add the following line of code at the end of the moveToTableTwo() function:


moveToTableTwo(){
   ...
   this.selection.clear();
}

Answer №2

After attempting to deselect the items, I encountered an issue moving them back to table 1. Here is the alternative solution that solved the problem:

moveItemsToTableOne(){
   ...
   this.selection.clear();
}

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

Tips on how to create a loop without using a collection in Angular 2

I have a specific quantity and I need to repeat an action that many times. for (var _i = 0; _i < length; _i++) I am trying to replicate this logic in the html template. If I use ngFor, I would typically require a collection, but in this case I only ha ...

How can I access internal.Writable within the basic-ftp NodeJS module using TypeScript?

After examining the API documentation of the basic-ftp module, I came across the following: downloadTo(writableStream | localPath, remotePath, startAt = 0): Promise<FTPResponse> However, when utilizing the module in a TypeScript project, the method ...

Angular 6 is throwing an error stating that the element 'app-action-button' is not recognized

I'm facing an issue while trying to incorporate a component that is shared between modules. Unfortunately, all my attempts have resulted in the same error. Despite searching for solutions in similar questions, I have been unable to resolve this error ...

Elements constrained by themselves in a rest parameter with generic types

When using Typescript, it is possible to infer tuple types for generic rest parameters that are constrained by an array type. However, in my specific case, this functionality does not seem to work as expected. I am attempting to pass a series of pairs co ...

Manipulate form components within ngAfterViewInit

I am looking for a way to programmatically access form controls and disable specific controls based on certain conditions. The issue I am facing is that the form in my code snippet does not contain any controls: Component export class OfferDialogComponen ...

What are some ways to enhance Rxjs syntax?

save(): void { combineLatest(this.selectedSorting$, this.selectedFilters$) .pipe( map((data) => { let obj = {}; if (data[0]) { obj['fil ...

When you click on the mat-tab label, it will act as a link and directly open the

I am facing an issue where I have 4 mat-tabs and I want to add one more tab. This additional tab will act as a label that, when clicked, opens a provided link. I have tried the following code but it is not working: <mat-tab label="Statistik ...

Why are the tabs in Angular displaying differently when the tab titles exceed 8 characters with Bootstrap 5?

Angular 14 Bootstrap 5 I developed a custom tabs component with pipes between the tabs that works flawlessly. However, I encountered an issue where the tabs slightly shift when the tab title exceeds 8 characters. Despite my efforts, I cannot pinpoint the ...

What is the best way to stop webpack from generating typescript errors for modules that are not being used?

The directory structure is set up as follows: └── src ├── tsconfig.json ├── core │ ├── [...].ts └── ui ├── [...].tsx └── tsconfig.json Within the frontend, I am importing a limi ...

Creating a new instance of a class with a different type that adheres to the specifications

I am looking to create various objects that need to adhere to a predefined type, but each object should have its own unique structure. Additionally, I want the ability to ensure conformance to the predefined type at the point of object creation. Let' ...

How to store angular 2 table information generated using ngFor

I am currently working on a project where I need to create an editable table using data retrieved from the back end. My goal now is to save any updated data. I attempted to use formControl, but it seems to only save the data in the last column. Below is a ...

Exploring the use of MediaSource for seamless audio playback

Currently working on integrating an audio player into my Angular web application by following a tutorial from Google Developers and seeking guidance from a thread on Can't seek video when playing from MediaSource. The unique aspect of my implementati ...

Difficulty encountered when utilizing stockfish.js in conjunction with TypeScript

After executing npm install stockfish, I created a simple file named getBestMove.ts which contains the following code: import stockfish from 'stockfish'; const fen = '3r1r1k/pp2Nqbp/3Rb2p/2P1pp2/7P/N1P3P1/PP2QP2/R3K3 w - - 2 30' inter ...

Specifying the return type of a function as a combination of the types of the input arguments

Is there a way to safely implement the given function in TypeScript without using unsafe casts or an extensive number of function overloads with various input permutations? interface Wrapped<T> { type: string; data: T; } interface WrappedA&l ...

Potential solution for communication issue between Angular CLI and Flask due to cross-origin error

Initially, the user id and password are submitted from the UI (angular) to Flask: public send_login(user){ console.log(user) return this.http.post(this.apiURL+'/login',JSON.stringify(user),this.httpOptions) .pip ...

An error has occurred: TypeError - The class constructor $b802fbb11c9bd2dc$export$2e2bcd8739ae039 must be called with 'new'

I am attempting to integrate emoji-mart into my application, but I keep encountering a persistent error. Here is the snippet of code causing the issue: import data from '@emoji-mart/data' import { Picker } from 'emoji-mart' {showEmoji ...

Ignoring the NGRX Store selector override during testing appears to be happening

When overriding the selector to return null, the data is still returned as per the override set during initialization. Attempting to use setState did not yield results either. Testing the else condition in the following code block: this.store.pipe(select( ...

Using RxJS and the combineLatest function can be hit or miss in terms of reliability

When you call this function multiple times with the values of observables obs1 and obs2 being the same each time, the returned array may not always be the same. getUniqueProducts(obs1: Observable<any>, obs2: Observable<any>): Observable<any& ...

When ng-test is executed in an Angular service, the function array.some is not found

After retrieving allUsers from the cache and initializing it, I then set the boolean value of specialUserExists based on a condition in allUsers using allUsers.some() (reference to the Array.prototype.some() method). service.ts @Injectable({ providedIn: ...

Angular8 Material Grid displaying headers and tiles, experiencing slight resizing issue with mat-grid-tile content

Exploring Angular8 Material: Grid Layout with Headers and Tiles Currently, I am delving into the workings of the grid system within Angular Material. I am dynamically fetching components and organizing them within a grid. While the grid list and tiles are ...