Having trouble getting help?
Contact Support
Contact Support
Enable or disable items in Angular List box component
27 Apr 20243 minutes to read
To enable or disable items in the list box, enableItems
method can be used. In the following example, the Bugatti Veyron Super Sport
and SSC Ultimate Aero
items are disabled by default and by clicking Enable Items
buttons, the disabled items will be enabled.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { ListBoxComponent, ListBoxAllModule } from '@syncfusion/ej2-angular-dropdowns'
import { ButtonComponent } from '@syncfusion/ej2-angular-buttons'
import { Component } from '@angular/core';
import { getInstance } from '@syncfusion/ej2-base';
import { ListBox } from '@syncfusion/ej2-dropdowns';
@Component({
imports: [
FormsModule, ReactiveFormsModule, ListBoxAllModule
],
standalone: true,
selector: 'app-container',
template: `<div class="e-section-control">
<button id="enableitem" (click)="btnclick()" class="e-btn">ENABLE ITEMS</button>
<ejs-listbox id="listbox" [dataSource]="data" (created)="created()"></ejs-listbox></div>`
})
export class AppComponent {
public data: { [key: string]: Object }[] = [
{ text: 'Hennessey Venom', id: 'list-01' },
{ text: 'Bugatti Chiron', id: 'list-02' },
{ text: 'Bugatti Veyron Super Sport', id: 'list-03' },
{ text: 'SSC Ultimate Aero', id: 'list-04' },
{ text: 'Koenigsegg CCR', id: 'list-05' },
{ text: 'McLaren F1', id: 'list-06' },
{ text: 'Aston Martin One- 77', id: 'list-07' },
{ text: 'Jaguar XJ220', id: 'list-08' },
{ text: 'McLaren P1', id: 'list-09' },
{ text: 'Ferrari LaFerrari', id: 'list-10' }
];
created():void{
let listboxobj:ListBox = getInstance((document as any).getElementById("listbox"), ListBox) as ListBox;
listboxobj.enableItems(['Bugatti Veyron Super Sport', 'SSC Ultimate Aero'], false);
}
btnclick():void{
let listboxobj:ListBox = getInstance((document as any).getElementById("listbox"), ListBox) as ListBox;
listboxobj.enableItems(['Bugatti Veyron Super Sport', 'SSC Ultimate Aero'], true);
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));