0.0.4 • Published 4 years ago

ngu-multiselect-dropdown v0.0.4

Weekly downloads
26
License
-
Repository
-
Last release
4 years ago

Angular Multiselect Dropdown

Angular multiselect dropdown component for web applications. Easy to integrate and use. It can be bind to any custom data source and custom filter.

Getting Started

Features

  • dropdown with single/multiple selction option
  • bind to any custom data source
  • search item with custom placeholder text
  • limit selection
  • select/de-select all items

Installation

npm install ngu-multiselect-dropdown
import { NuMultiSelectDropDownModule } from 'ngu-multiselect-dropdown';
// ...

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

Usage

import { Component, OnInit } from '@angular/core';
import { IDropdownSettings } from 'ngu-multiselect-dropdown';

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:IDropdownSettings = {
      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);
  }
}
<nu-multiselect-dropdown
  [placeholder]="'custom placeholder'"
  [data]="dropdownList"
  [(ngModel)]="selectedItems"
  [settings]="dropdownSettings"
  (onSelect)="onItemSelect($event)"
  (onSelectAll)="onSelectAll($event)"
>
</nu-multiselect-dropdown>

Settings

SettingTypeDescriptionDefault Value
singleSelectionBooleanMode of this component. If set true user can select more than one option.false
placeholderStringText to be show in the dropdown, when no items are selected.'Select'
disabledBooleanDisable the dropdownfalse
dataArrayArray of items from which to select. Should be an array of objects with id and text properties. You can also use custom properties. In that case you need to map idField and textField properties. As convenience, you may also pass an array of strings, in which case the same string is used for both the ID and the text(no mapping is required)n/a
idFieldStringmap id field in case of custom array of object'id'
textFieldStringmap text field in case of custom array of object'text'
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
allowSearchFilterBooleanEnable filter option for the list.false
searchPlaceholderTextStringcustom search placeholderSearch
clearSearchFilterBooleanclear search filter on dropdown closetrue
maxHeightNumberSet maximum height of the dropdown list in px.197
itemsShowLimitNumberLimit the number of items to show in the input field. If not set will show all selected.All
limitSelectionNumberLimit the selection of number of items from the dropdown list. Once the limit is reached, all unselected items gets disabled.none
searchPlaceholderTextStringCustom text for the search placeholder text. Default value would be 'Search''Search'
noDataAvailablePlaceholderTextStringCustom text when no data is available.'No data available'
closeDropDownOnSelectionBooleanCloses the dropdown when item is selected. applicable only in cas of single selectionfalse
defaultOpenBooleanopen state of dropdownfalse
allowRemoteDataSearchBooleanallow search remote api if no data is present.false

Callback Methods

  • onSelect - Return the selected item when an item is checked. Example : (onSelect)="onItemSelect($event)"
  • onSelectAll - Return the all items. Example : (onSelectAll)="onSelectAll($event)".
  • onDeSelect - Return the unselected item when an item is unchecked. Example : (onDeSelect)="onItemDeSelect($event)"
  • onFilterChange - Return the key press. Example : (onFilterChange)="onFilterChange($event)"
  • onDropDownClose- Example : (onDropDownClose)="onDropDownClose()"

Development

This project was generated with Angular CLI version 8.3.15.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI README.