How to show icons in React MultiSelect Dropdown
29 Aug 20264 minutes to read
You can add icons to the list items by mapping the iconCss field. This iconCss field creates a span in the list item with the mapped class name for styling as needed. The mapped class must be defined in your application’s CSS (for example, in index.css or App.css) with the appropriate icon styles, such as a font-icon or a background image, so the span renders the intended icon.
In the following sample, icon classes are mapped with the iconCss field.
import { MultiSelectComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
export default class App extends React.Component {
// define the array of data
sortFormatData = [
{ 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.
fields = { text: 'type', iconCss: 'class', value: 'id' };
render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" dataSource={this.sortFormatData} fields={this.fields} placeholder="Select a format"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));import { MultiSelectComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
export default class App extends React.Component<{}, {}> {
// define the array of data
private sortFormatData: { [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.
private fields: object = { text: 'type', iconCss: 'class', value: 'id' };
public render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" dataSource={this.sortFormatData} fields={this.fields} placeholder="Select a format" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));Each list item displays an icon based on the class mapped through the iconCss field.