The Angular ListBox widget supports multiple selection. You can enable this functionality by setting the 'multiple' property to true.
Loading...

Angular ListBox: Multiple Selection

Angular ListBox's multiple selection function.

A live Angular example of jqxListBox, the jQWidgets ListBox component, with its complete source code below. It is one of 18 jqxListBox demos for Angular.

jqxListBox API used in this demo

Source code

To run it in your own app, install the package with npm install jqwidgets-ng, add these files to a standalone Angular CLI app, and add jqx.base.css and a theme to the styles in angular.json. Getting started with jqxListBox shows the setup step by step.

app.ts

import { Component, AfterViewInit, ElementRef, viewChild } from '@angular/core';

import { jqxListBoxComponent } from 'jqwidgets-ng/jqxlistbox';
import { CommonModule } from '@angular/common';
import { jqxListBoxModule } from 'jqwidgets-ng/jqxlistbox';

@Component({
    imports: [CommonModule, jqxListBoxModule],
    selector: 'app-root',
    templateUrl: './app.html'
})

export class App implements AfterViewInit {
    readonly myListBox = viewChild.required<jqxListBoxComponent>('jqxListBox');
    readonly selectionLog = viewChild.required<ElementRef>('selectionLog');

    ngAfterViewInit() {
        this.myListBox().selectIndex(2);
        this.myListBox().selectIndex(5);
        this.myListBox().selectIndex(7);
    }

    source: string[] = [
        "Affogato",
        "Americano",
        "Bicerin",
        "Breve",
        "Café Bombón",
        "Café au lait",
        "Caffé Corretto",
        "Café Crema",
        "Caffé Latte",
        "Caffé macchiato",
        "Café mélange",
        "Coffee milk",
        "Cafe mocha",
        "Cappuccino",
        "Carajillo",
        "Cortado",
        "Cuban espresso",
        "Espresso",
        "Eiskaffee",
        "The Flat White",
        "Frappuccino",
        "Galao",
        "Greek frappé coffee",
        "Iced Coffee",
        "Indian filter coffee",
        "Instant coffee",
        "Irish coffee",
        "Liqueur coffee"
    ];

    displaySelectedItems() {
        let items = this.myListBox().getSelectedItems();
        let selection = 'Selected Items: ';
        for (let i = 0; i < items.length; i++) {
            selection += items[i].label + (i < items.length - 1 ? ', ' : '');
        }
        this.selectionLog().nativeElement.innerHTML = selection;
    }

    change(event: any): void {
        this.displaySelectedItems();
    };
}

app.html

<jqxListBox #jqxListBox
              (onChange)="change($event)"
              [source]="source"
              [multiple]="true"
              [width]="200"
              [height]="250">
  </jqxListBox>

<div style="margin-top: 30px; font-size: 13px; font-family: Verdana;" #selectionLog></div>

Learn more

More Angular ListBox demos