Rajasekhar
Rajasekhar

Reputation: 2455

Unable to Select all checkboxes with Angular

Populated Angular dataTable and trying to select all checkboxes but unable to select, tried with below code. Could you please suggest me the solution. Please refer below Stackblitz for working demo

isChecked = false;
checkuncheckall() {
    if (this.isChecked == true) {
        this.isChecked = false;
    } else {
        this.isChecked = true;
    }
}

Stackblitz

Upvotes: 0

Views: 1421

Answers (1)

Zunayed Shahriar
Zunayed Shahriar

Reputation: 2723

Solved your problem. Forked at Stackblitz.

Changes:

  1. Added all data selection at checkuncheckall function:
if (this.persons && this.persons.length) {
  this.persons.forEach(f => (f.check = this.isChecked == true));
}
  1. Remove checkbox from your table column settings:
columns: [
    { name: "" },
    { data: "index" },
    { title: "Dropdown" },
    { title: "ExtraColumn" },
    { data: "firstname" },
    { data: "lastname" }
]

Upvotes: 2

Related Questions