Reputation: 1315
I am using ng-multiselect dropdown in my angular code. While all the onSelect, onSelectAll, onDeSelect methods are working fine, onDeselctAll method doesn't receive the array of items deselected. I checked in the official site but it was of no use : https://www.npmjs.com/package/ng-multiselect-dropdown. Any idea where I might be going wrong? PFB the code snippet:
.html file
<ng-multiselect-dropdown *ngIf="filteredSids.length > 0"
[data]="filteredSids"
[disabled]="false"
[(ngModel)]="selectedSids"
(onSelect)="selectedSIDs($event); onItemSelect($event)"
(onSelectAll)="onSelectAll($event)"
(onDeSelect)="onItemDeSelect($event)"
(onDeSelectAll)="onDeSelectAll($event)"
[settings]="dropdownSettings"
formControlName="sidControl">
</ng-multiselect-dropdown>
.ts file
onSelectAll(selectedSIDList: Array<string>): void {
selectedSIDList.forEach(sid => {
this.selectedSIDs(sid);
this.onItemSelect(sid);
});
}
onItemDeSelect(deselectedSID: any): void {
this.selectedSIDList = this.selectedSIDList.filter(s => s != deselectedSID);
this.selectedSIDList.forEach(sid => {
this.onItemSelect(sid);
});
}
onDeSelectAll(items: any){
console.log(items); // items is an empty array
}
Upvotes: 5
Views: 12118
Reputation: 340
<ng-multiselect-dropdown
[placeholder]="'Select Categories'"
[settings]="dropdownSettings"
[data]="collectionList"
[(ngModel)]="selectedCollection"
(onSelect)="onItemSelect($event)"
(onSelectAll)="onSelectAll($event)"
(onDeSelectAll)="onItemDeSelect($event)">
</ng-multiselect-dropdown>
Then in .ts file add function
onItemDeSelect(items: any){
this.selectedCollection = []
this.getProductList()
}
Upvotes: 0
Reputation: 3138
According to the source code, receiving an empty array is the correct behaviour:
this.selectedItems = [];
this.onDeSelectAll.emit(this.emittedValue(this.selectedItems));
If you want to track the items that are being deselected, you need to find a different way.
Upvotes: 5