Shift and Ctrl in Angular ListBox.
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.
height property – Sets or gets the listbox's height.multipleextended property – Enables/disables the multiple selection using Shift and Ctrl keys.selectedIndex property – Sets or gets the selected index.source property – Sets or gets the item's source.width property – Sets or gets the listbox's width.change event – This event is triggered when the user selects an item.focus method – Sets the focus to the jqxListBox.getSelectedItems method – Gets the selected ListBox items.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.
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().focus();
}
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();
};
}
<jqxListBox #jqxListBox
(onChange)="change($event)"
[source]="source"
[selectedIndex]="1"
[multipleextended]="true"
[width]="200"
[height]="250">
</jqxListBox>
<div style="margin-top: 30px; font-size: 13px; font-family: Verdana;" #selectionLog></div>