1

I have implemented a simple table in angular 2 using angular material ..Implemented two methods , first is transferSelectedRows which on selecting rows from table pushes the row data to Selected Rows section.

Second method is removeSelectedRows where on selecting the rows and clicking Remove Selected Rows button should delete the corresponding list items.But I am unable to delete the items from the mat-selection-list...

Can anybody please help me out ...!

please access my sample example here ..https://stackblitz.com/edit/angular-nwjqsj-au6ho8?file=index.html

Below shown is the output of my sample angular 2 app.

enter image description here

11

1 Answer 1

0

You can modify your removeSelectedRows() to filter the selected items in the table:

removeSelectedRows() {
    this.selection.selected.forEach(item => {
      this.selectedRows = this.selectedRows.filter(element => element !== item);
    });
  }
Sign up to request clarification or add additional context in comments.

5 Comments

I am getting the following error in my terminal.Type 'any[ ]' is not assignable to type 'SelectionModel<Element>'
I'm on the phone right now so it's tricky to see it, but modifying how you declare selectedRows to selectedRows: Element[] = [] (line 21) should fix the issue.
Sorry I misinterpreted your question, I had missed the checkboxes on the right. Let me re-elaborate my answer
@Heena Have yo got solution?
@RameshRajendran ... Hello Sir ,,,, Check this please ...stackoverflow.com/questions/49609355/…

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.