2.0.4 • Published 5 years ago

@zokelion/ngx-multiselect v2.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

NgxMultiselect

Angular recursive select tree

What is it ?

NgxMultiSelect is a recursive select tree. You can select one or multiple item in tree and they're returned in an array of items. NgxMultiSelect can be configured for changing button's label.

Installation

npm install @zokelion/ngx-multiselect --save

Usage

Basic

NgxMultiselect generate a tree based on an list of items. the component should be declared in your html code like this :

<ngx-multiselect
    (itemSelected)="getSelectedItem($event)"
    [items]="items"
    [selectAllButtonLabel]="'Select All'"
    [unselectAllButtonLabel]="'Unselect All'"
    [defaultToggleButtonLabel]="'No Items Selected'"
    [placeholder]="'Search Items'"
    [toggleBtnClass]="'btn-primary w-75'"
    [toggleContentClass]="'w-100'"
    [enableAnimation]="true"
    [useClassicCheckbox]="false"
    [enableResearch]="true"
    [disabled]="false"
></ngx-multiselect>

This is a simple interface that describes any parameters for a multiSelect component.

NameTyperequiredDescriptionDefault
(itemSelected)ItemSelectedEvent✔️function who was called by the event for getting the list of selected items, in the example below the function was called getSelectedItem()NO
itemsitem[]parameter item list[]
selectAllButtonLabelstringbutton label for select all items'Select All'
unselectAllButtonLabelstringbutton label for unselect all items'Unselect All'
defaultToggleButtonLabelstringlabel of toggle button in case of none items are selected'No Items Selected'
placeholderstringplaceholder of research input'Search Items'
toggleBtnClassstringinput for your custom css classes on the toggle button'btn-primary w-75'
toggleContentClassstringinput for your custom css classes on the content of the toggle'w-100'
enableAnimationbooleanenable or not the animation of the toggle contenttrue
useClassicCheckboxbooleanuse simple font-awesome icon instead of animate checkboxfalse
enableResearchbooleandisplay the research inputfalse
disabledbooleandisable or not the toggle buttonfalse

In order to use the event class import it in your component and declare a new function in your component like this :

    // import to be able to use the event
    import { ItemClickedEvent } from '@zokelion/ngx-multiselect/models/item-clicked-event.model';
    // import this model for the type of your list
    import { Item } from '@zokelion/ngx-multiselect/models/item.model';

    // function for getting and using the list
    public getSelectedItem(eventItem: ItemSelectedEvent): void {
        this.selectedItems = eventItem.selectedItems;
    }

For the generation of the tree the list must be composed of items based on this model :

export class Item {
    id?: number;
    name: string;
    isSelected: boolean;
    children: Item[];
    cssClasses: string;
    cssSelectedClasse: string;
}

Detail of Item property :

NameTyperequiredDescription
idItemSelectedEventitem.id is optionnal but it is usefull when you use an api.
namestring✔️name of item
isSelectedboolean✔️indicates weither or not this item is ticked.
childrenitem[]✔️childrens of the item
cssClassesstring✔️css classe(s) to use on your item
cssSelectedClassesstring✔️css classe(s) to use on your item when it's selected

Example of items list:

// this list is an example
this.items.push({
    id: 1,
    name: 'World',
    isSelected: false,
    children: [
        {
            id: 2,
            name: 'America',
            isSelected: false,
            children: [
                {
                    id: 3,
                    name: 'Canada',
                    isSelected: false,
                    children: [],
                    cssClasses: '',
                    cssSelectedClasses: 'bg-success text-light'
                },
                {
                    id: 4,
                    name: 'United-States',
                    isSelected: false,
                    children: [
                        {
                            id: 14,
                            name: 'Arizona',
                            isSelected: false,
                            children: [],
                            cssClasses: '',
                            cssSelectedClasses: 'bg-success text-light'
                        },
                        {
                            id: 15,
                            name: 'Washington',
                            isSelected: true,
                            children: [],
                            cssClasses: '',
                            cssSelectedClasses: 'bg-success text-light'
                        }
                    ],
                    cssClasses: '',
                    cssSelectedClasses: 'bg-success text-light'
                },
                {
                    id: 5,
                    name: 'Mexico',
                    isSelected: true,
                    children: [],
                    cssClasses: '',
                    cssSelectedClasses: 'bg-success text-light'
                }
            ],
            cssClasses: '',
            cssSelectedClasses: 'bg-success text-light'
        },
        {
            id: 6,
            name: 'Europe',
            isSelected: true,
            children: [
                {
                    id: 7,
                    name: 'France',
                    isSelected: true,
                    children: [],
                    cssClasses: '',
                    cssSelectedClasses: 'bg-success text-light'
                },
                {
                    id: 8,
                    name: 'Deutschland',
                    isSelected: true,
                    children: [],
                    cssClasses: '',
                    cssSelectedClasses: 'bg-success text-light'
                }
            ],
            cssClasses: '',
            cssSelectedClasses: 'bg-success text-light'
        },
        {
            id: 9,
            name: 'Asia',
            isSelected: false,
            children: [
                {
                    id: 10,
                    name: 'China',
                    isSelected: false,
                    children: [],
                    cssClasses: '',
                    cssSelectedClasses: 'bg-success text-light'
                },
                {
                    id: 11,
                    name: 'Japan',
                    isSelected: true,
                    children: [],
                    cssClasses: '',
                    cssSelectedClasses: 'bg-success text-light'
                }
            ],
            cssClasses: '',
            cssSelectedClasses: 'bg-success text-light'
        },
        {
            id: 12,
            name: 'Oceania',
            isSelected: true,
            children: [
                {
                    id: 13,
                    name: 'Australia',
                    isSelected: true,
                    children: [],
                    cssClasses: '',
                    cssSelectedClasses: 'bg-success text-light'
                }
            ],
            cssClasses: '',
            cssSelectedClasses: 'bg-success text-light'
        }
    ],
    cssClasses: '',
    cssSelectedClasses: 'bg-success text-light'
});

Configuration

Labels can be customized depending on your language. We're using English by default. The labels of this components have default value but the following params can be customize :

<ngx-multiselect
    [selectAllButtonLabel]="'Select All'"
    [unselectAllButtonLabel]="'Unselect All'"
    [defaultToggleButtonLabel]="'No Items Selected'"
    [placeholder]="'Search Items'"
    [toggleBtnClass]="'btn-primary w-75'"
    [toggleContentClass]="'w-100'"
    [enableAnimation]="true"
    [useClassicCheckbox]="false"
    [enableResearch]="true"
    [disabled]="false"
></ngx-multiselect>
2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.0

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago