Icons support in Angular Combo box component
27 Apr 20242 minutes to read
You can render icons to the list items by mapping the iconCss fields. This iconCss
field create a span in the list item with mapped class name to allow styling as per your need.
In the following sample, icon classes are mapped with iconCss
field.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { ComboBoxModule } from '@syncfusion/ej2-angular-dropdowns'
import { Component } from '@angular/core';
@Component({
imports: [
FormsModule, ComboBoxModule
],
standalone: true,
selector: 'app-root',
// specifies the template string for the ComboBox component.
template: `<ejs-combobox id='comboelement' #samples [dataSource]='data' [fields]='fields' [placeholder]='text'></ejs-combobox>`
})
export class AppComponent {
constructor() {
}
// defined the array of data
public data: { [key: string]: Object }[] = [
{ Class: 'asc-sort', Type: 'Sort A to Z', Id: '1' },
{ Class: 'dsc-sort', Type: 'Sort Z to A ', Id: '2' },
{ Class: 'filter', Type: 'Filter', Id: '3' },
{ Class: 'clear', Type: 'Clear', Id: '4' }];
// map the icon column to iconCSS field.
public fields: Object = { text: 'Type', iconCss: 'Class', value: 'Id' };
//set the placeholder to ComboBox input
public text: string = 'Select a format';
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));