Skip to content

Commit f74a11b

Browse files
tsteffesCuppaLabs
authored andcommitted
add event emitter to select all the filtered items (#326)
1 parent 156348d commit f74a11b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

projects/angular2-multiselect-dropdown-lib/src/lib/multiselect.component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export class AngularMultiSelect implements OnInit, ControlValueAccessor, OnChang
6464
@Output('onScrollToEnd')
6565
onScrollToEnd: EventEmitter<any> = new EventEmitter<any>();
6666

67+
@Output('onFilterSelectAll')
68+
onFilterSelectAll: EventEmitter<Array<any>> = new EventEmitter<Array<any>>();
69+
70+
@Output('onFilterDeSelectAll')
71+
onFilterDeSelectAll: EventEmitter<Array<any>> = new EventEmitter<Array<any>>();
72+
6773
@ContentChild(Item) itemTempl: Item;
6874
@ContentChild(Badge) badgeTempl: Badge;
6975
@ContentChild(Search) searchTempl: Search;
@@ -370,11 +376,13 @@ export class AngularMultiSelect implements OnInit, ControlValueAccessor, OnChang
370376
}
371377
toggleFilterSelectAll() {
372378
if (!this.isFilterSelectAll) {
379+
let added = [];
373380
if (this.settings.groupBy) {
374381
this.groupedData.forEach((item: any) => {
375382
item.value.forEach((el: any) => {
376383
if (!this.isSelected(el)) {
377384
this.addSelected(el);
385+
added.push(el);
378386
}
379387
});
380388
});
@@ -383,19 +391,23 @@ export class AngularMultiSelect implements OnInit, ControlValueAccessor, OnChang
383391
this.ds.getFilteredData().forEach((item: any) => {
384392
if (!this.isSelected(item)) {
385393
this.addSelected(item);
394+
added.push(item);
386395
}
387396

388397
});
389398
}
390399

391400
this.isFilterSelectAll = true;
401+
this.onFilterSelectAll.emit(added);
392402
}
393403
else {
404+
let removed = [];
394405
if (this.settings.groupBy) {
395406
this.groupedData.forEach((item: any) => {
396407
item.value.forEach((el: any) => {
397408
if (this.isSelected(el)) {
398409
this.removeSelected(el);
410+
removed.push(el);
399411
}
400412
});
401413
});
@@ -404,11 +416,13 @@ export class AngularMultiSelect implements OnInit, ControlValueAccessor, OnChang
404416
this.ds.getFilteredData().forEach((item: any) => {
405417
if (this.isSelected(item)) {
406418
this.removeSelected(item);
419+
removed.push(item);
407420
}
408421

409422
});
410423
}
411424
this.isFilterSelectAll = false;
425+
this.onFilterDeSelectAll.emit(removed);
412426
}
413427
}
414428
toggleInfiniteFilterSelectAll() {

0 commit comments

Comments
 (0)