The filtering 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.
filterable property – Determines whether the Filtering is enabled.height property – Sets or gets the listbox's height.itemHeight property – Sets or gets the height of the jqxListBox Items.renderer property – Callback function which is called when an item is rendered.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.clearFilter method – Clears the widget's filter when filtering is applied.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, viewChild } from '@angular/core';
import { jqxListBoxComponent } from 'jqwidgets-ng/jqxlistbox';
import { CommonModule } from '@angular/common';
import { jqxListBoxModule } from 'jqwidgets-ng/jqxlistbox';
import { jqxButtonModule } from 'jqwidgets-ng/jqxbuttons';
@Component({
imports: [CommonModule, jqxListBoxModule, jqxButtonModule],
selector: 'app-root',
templateUrl: './app.html'
})
export class App {
readonly myListBox = viewChild.required<jqxListBoxComponent>('listbox');
shirtFileNames: string[] =
[
'2-sided-dodgers-bankrupt-t-shirt-ash', 'black-retro-rock-band-guitar-controller',
'bright-green-gettin-lucky-in-kentucky', 'brown-loading-bar-computer-geek', 'cool-story-bro',
'fear-the-beard', 'honey-badger-don-t-care', 'misfits-sf-giants-white', 'scott-pilgrim-red-rock-band'
];
shirts: string[] =
[
'2 sided dodgers<br>bankrupt<br>t shirt ash', 'black retro<br>rock band<br>guitar controller',
'bright green<br>gettin lucky<br>in kentucky', 'brown loading<br>bar computer geek', 'cool story bro',
'fear the beard', 'honey badger<br>don t care', 'misfits sf<br>giants white', 'scott pilgrim<br>red rock<br>band'
];
renderer = (index: number, label: any, value: any): string => {
let datarecord = this.shirtFileNames[index];
let imgurl = './../../../images/t-shirts/' + datarecord.toLowerCase() + '.png';
let img = '<img height="70" width="70" src="' + imgurl + '"/>';
let table = '<table style="min-width: 130px;"><tr><td style="width: 80px;">' + img + '</td><td>' + label + '</td></tr></table>';
return table;
}
click(event: any): void {
this.myListBox().clearFilter();
};
}
<jqxListBox #listbox
[filterable]="true"
[selectedIndex]="0"
[source]="shirts"
[itemHeight]="90"
[renderer]="renderer"
[width]="250"
[height]="300">
</jqxListBox>
<div style="margin-top: 10px;">
<jqxButton #clearFilter
(onClick)="click($event)">
Clear Filter
</jqxButton>
</div>