0

I have implemented a simple table in angular 2 using the angular material.

I have implemented transferring selected rows functionality from the first table to the second table and deleting the selected rows from the second table.

As I select rows from the first table and click on button Move To Second Table , the selected rows are transferred to the second table but are not getting spliced from the first table, although I have spliced the selected rows in the transferSelectedRows() method.

please access my sample app here...

2
  • 1
    you don't splice it from the table, you do splice it from selection... Commented Mar 29, 2018 at 12:59
  • yes i spliced from selection ,,, but not getting spliced.....! Commented Mar 29, 2018 at 13:01

1 Answer 1

2

Here are the changes you need to do in your component side (Please also read the comments)

Component Side :

uncheckedData = this.data; // to maintain data for table 1

transferSelectedRows() {
    this.selection.selected.forEach(item => {
        let index: number = this.uncheckedData.findIndex(d => d === item);

        this.checkedData.push(this.uncheckedData[index]); // adding to table 2
        this.uncheckedData.splice(index,1); // remove data from table 1

    });

    this.selection = new SelectionModel<Element>(true, []);
    this.dataSource = new MatTableDataSource<Element>(this.uncheckedData);
    this.checkedDataSource = new MatTableDataSource<Element>(this.checkedData);
    this.dataSource.paginator = this.paginator;
    this.checkedDataSource.paginator = this.checkedpaginator;
}

WORKING DEMO

Sign up to request clarification or add additional context in comments.

7 Comments

hmm yes ........... even i need to move it from 2-->1 ........ i will try it.. if any problem exist i will come back again ..... thanks a lot..
@Heena , Glad that hepled you , Happy coding BTW.
can you also tell me how to push from 2-->1
@Heena , please check the demo again I have updated the demo
@Heena Check again , it will be added last so you have to go to 2nd page to check that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.