Icons support in Angular Multi select component
27 Sep 20233 minutes to read
You can render icons to the list items by mapping the iconCss fields. This iconCss
fields create a span in the list item with mapped class name to allow styling as per your need. fields. This iconCss
fields 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 { Component } from '@angular/core';
@Component({
selector: 'app-root',
// specifies the template string for the MultiSelect component
template: `<ejs-multiselect id='multiselectelement' [dataSource]='data' [fields]='fields' [placeholder]='text'></ejs-multiselect>`
})
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 MultiSelect input
public text: string = 'Select a format';
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { MultiSelectModule } from '@syncfusion/ej2-angular-dropdowns';
/**
* Module
*/
@NgModule({
imports: [
BrowserModule,FormsModule, MultiSelectModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);