多选插件Angular 2 MultiSelect Dropdown

本文介绍了Angular 2 MultiSelect Dropdown的使用,包括 Github 仓库和官网链接,提供了安装和使用步骤。建议通过GitHub下载并参考示例进行功能实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Github:githubhttps://github.com/CuppaLabs/angular2-multiselect-dropdow

 官网:http://cuppalabs.github.io/components/multiselectDropdown/#Getting-Starte

安装:

  npm install angular2-multiselect-dropdown

 直接去github上clone一个样本要直观的多,运行一下就能明白大多功能的具体实现方法,也可根据需求做些许改动。

 使用:

 在app.module.ts中导入AngularMultiSelectModule 到NgModule

import { AngularMultiSelectModule } from 'angular2-multiselect-dropdown/angular2-multiselect-dropdown';

@NgModule({
 // ...
 imports: [
    AngularMultiSelectModule,
  ]
 // ...
})

在组件中声明要使用下拉组件的组件数据变量和选项。

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

export class AppComponent implements OnInit {
    dropdownList  [];
    selectedItems  [];
    dropdownSettings  {};
    ngOnInit(){
        this.dropdownList = [
                              {"id":1,"itemName":"India"},
                              {"id":2,"itemName":"Singapore"},
                              {"id":3,"itemName":"Australia"},
                              {"id":4,"itemName":"Canada"},
                              {"id":5,"itemName":"South Korea"},
                              {"id":6,"itemName":"Germany"},
                              {"id":7,"itemName":"France"},
                              {"id":8,"itemName":"Russia"},
                              {"id":9,"itemName":"Italy"},
                              {"id":10,"itemName":"Sweden"}
                            ];
        this.selectedItems = [
                                {"id":2,"itemName":"Singapore"},
                                {"id":3,"itemName":"Australia"},
                                {"id":4,"itemName":"Canada"},
                                {"id":5,"itemName":"South Korea"}
                            ];
       this.dropdownSettings= { singleSelection:false, //是否是单选
                                text:"Select Countries",  //未做选择时框内文字                                
                                selectAllText:'Select All',//全选按钮未勾选时显示文字
                                unSelectAllText:'UnSelect All',//全选按钮勾选时显示文字
                                enableSearchFilter:true,//是否添加搜索功能
                                classes:"myclass custom-class"//添加类名
                                };            
    }
    onItemSelect(item:any){
        console.log(item);
        console.log(this.selectedItems);
    }
    OnItemDeSelect(item:any){
        console.log(item);
        console.log(this.selectedItems);
    }
    onSelectAll(items:any){
        console.log(items);
    }
    onDeSelectAll(items:any){
        console.log(items);
    }
}

在组件中添加相应模块

<angular2-multiselect [data]="dropdownList" [(ngModel)]="selectedItems" 
    [settings]="dropdownSettings" 
    (onSelect)="onItemSelect($event)" 
    (onDeSelect)="OnItemDeSelect($event)"
    (onSelectAll)="onSelectAll($event)"
    (onDeSelectAll)="onDeSelectAll($event)">
</angular2-multiselect>

 

选项配置表:

SettingTypeDescriptionDefault
singleSelectionBooleanTo set the dropdown for single item selection only.false
textStringText to be show in the dropdown, when no items are selected.‘Select’
enableCheckAllBooleanEnable the option to select all items in listfalse
selectAllTextStringText to display as the label of select all optionSelect All
unSelectAllTextStringText to display as the label of unSelect optionUnSelect All
enableSearchFilterBooleanEnable filter option for the list.false
enableFilterSelectAllBooleanA ‘select all’ checkbox to select all filtered results.true
filterSelectAllTextStringText to display as the label of select all optionSelect all filtered results
filterUnSelectAllTextStringText to display as the label of unSelect optionUnSelect all filtered results
maxHeightNumberSet maximum height of the dropdown list in px.300
badgeShowLimitNumberLimit the number of badges/items to show in the input field. If not set will show all selected.All
classesStringCustom classes to the dropdown component. Classes are added to the dropdown selector tag. To add multiple classes, the value should be space separated class names.’’
limitSelectionNumberLimit the selection of number of items from the dropdown list. Once the limit is reached, all unselected items gets disabled.none
disabledBooleanDisable the dropdownfalse
searchPlaceholderTextStringCustom text for the search placeholder text. Default value would be ‘Search’‘Search’
groupByStringName of the field by which the list should be grouped.none
searchAutofocusBooleanAutofocus search input fieldtrue
labelKeyStringThe property name which should be rendered as label in the dropdownitemName
primaryKeyStringThe property by which the object is identified. Default is ‘id’.id
positionStringSet the position of the dropdown list to ‘top’ or ‘bottom’bottom
noDataLabelStringLabel text when no data is available in the list‘No Data Available’
searchByArraySearch the list by certain properties of the list item. Ex: [“itemName, “id”,”name”]. Deafult is , it will search the list by all the properties of list item[]
lazyLoadingBooleanEnable lazy loading. Used to render large datasets.false
showCheckboxBooleanShow or hide checkboxes in the listtrue

更新2019.1.7

建议直接在github上下载,根据demo来获得想要实现的功能。

之前的方法,在后来发现有缺陷,搜索后选择所有匹配的选项这一功能无法启用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值