简体   繁体   中英

angular2-multiselect dropdown selects all boxes on clicking 1 checbkox

 <angular2-multiselect [data]="dataList | OrderBy : 'clientName'" [(ngModel)]="selectedItems[dataList.clientId]" [settings]="dropdownSettings" name="multiSelect" (onSelect)="onItemSelect($event, dataList.clientId)" (onDeSelect)="OnItemDeSelect($event,dataList.clientId)" (onSelectAll)="onSelectAll($event)" (onDeSelectAll)="onDeSelectAll($event)" disabled> <c-item> <ng-template let-item="item"> <label style="color: #333;min-width: 160px;">{{item.clientName}}- {{item.clientId}}</label> </ng-template> </c-item> </angular2-multiselect>

dataList is the list that is coming from backend evrything is working fine except the checkbox in dropDown..i am not able to select 1 checkbox as it selects all on clicking 1 cb also.

You can accomplish with "ng-multiselect-dropdown"

Installation :

npm install ng-multiselect-dropdown

And then include it in your module (see app.module.ts):

import { NgMultiSelectDropDownModule } from 'ng-multiselect-dropdown';
// ...

@NgModule({
imports: [
NgMultiSelectDropDownModule.forRoot()
// ...
]
// ...
})
export class AppModule {}

Usage

import { Component, OnInit } from '@angular/core';

export class AppComponent implements OnInit {
dropdownList = [];
selectedItems = [];
dropdownSettings = {};
ngOnInit() {
this.dropdownList = [
  { item_id: 1, item_text: 'Mumbai' },
  { item_id: 2, item_text: 'Bangaluru' },
  { item_id: 3, item_text: 'Pune' },
  { item_id: 4, item_text: 'Navsari' },
  { item_id: 5, item_text: 'New Delhi' }
];
this.selectedItems = [
  { item_id: 3, item_text: 'Pune' },
  { item_id: 4, item_text: 'Navsari' }
];
this.dropdownSettings = {
  singleSelection: false,
  idField: 'item_id',
  textField: 'item_text',
  selectAllText: 'Select All',
  unSelectAllText: 'UnSelect All',
  itemsShowLimit: 3,
  allowSearchFilter: true
};
}
onItemSelect(item: any) {
console.log(item);
}
onSelectAll(items: any) {
console.log(items);
}
}

HTML Code :

<ng-multiselect-dropdown
[placeholder]="'custom placeholder'"
[data]="dropdownList"
[(ngModel)]="selectedItems"
[settings]="dropdownSettings"
(onSelect)="onItemSelect($event)"
(onSelectAll)="onSelectAll($event)"
>
</ng-multiselect-dropdown>

For more details please check the URL - https://www.npmjs.com/package/ng-multiselect-dropdown

u have to add primaryKey in settings, like:

this.dropdownSettings = { 
                          singleSelection: false, 
                          text:"Select Countries",
                          selectAllText:'Select All',
                          unSelectAllText:'UnSelect All',
                          enableSearchFilter: true,
                          classes:"myclass custom-class",
                          **primaryKey**:**"your_identifier"**,
                        };   

Related to: https://github.com/CuppaLabs/angular2-multiselect-dropdown/issues/252

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM