How to implement multiple select dropdow with grouping in angular 2 application?

Manjit picture Manjit · Dec 8, 2016 · Viewed 9.5k times · Source

How can I implement multiple select drop down with grouping in my angular 2 application? I need the drop down like the images linked in this question How can implement grouping in ng-select of Angular2?. Kindly help me out.....I am stuck on this from last few days

I have tried angular-ngselect like the following but its :

Component Html:

<form [formGroup]="form" class="selector-form">
    <div class="marTop20">
        <ng-select [options]="options1"
                   [multiple]="multiple1"
                   placeholder="Select multiple"
                   formControlName="selectMultiple"
                   (opened)="onMultipleOpened()"
                   (closed)="onMultipleClosed()"
                   (selected)="onMultipleSelected($event)"
                   (deselected)="onMultipleDeselected($event)">
        </ng-select>
    </div>
</form>

Component code in ts file:

export class FilterClientSelectorComponent implements OnInit {
    form: FormGroup;
    multiple1: boolean = true;
    options1: Array<any> = [];
    selection: Array<string>;
    @ViewChild('preMultiple') preMultiple;
    logMultipleString: string = '';

    constructor() {
        let numOptions = 100;
        let opts = new Array(numOptions);
        for (let i = 0; i < numOptions; i++) {
            opts[i] = {
                value: i.toString(),
                label: i.toString(),
                groupname:'a'
            };
        }
        this.options1 = opts.slice(0);
    }
    ngOnInit() {
        this.form = new FormGroup({});
        this.form.addControl('selectMultiple', new FormControl(''));
    }
    private scrollToBottom(elem) {
        elem.scrollTop = elem.scrollHeight;
    }
}

And its giving me multiple select dropdown but not grouping:

Current Output:

enter image description here

Required output:

enter image description here

Answer

Pardeep Jain picture Pardeep Jain · Dec 8, 2016

Try this one primeng's Multi Select Dropdown with number of attributes and features may help you.

http://www.primefaces.org/primeng/#/multiselect

http://www.primefaces.org/primeng/#/picklist