The MultiSelect has been provided with several options to customize each list item, group title, selected value, header, and footer elements.
The content of each list item within the MultiSelect can be customized with the help of itemTemplate property.
In the following sample, each list item is split into two columns to display relevant data’s.
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
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 {
constructor() {
super(...arguments);
// bind the DataManager instance to dataSource property
this.employeeData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// bind the Query instance to query property
this.query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
this.fields = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
this.sortOrder = 'Ascending';
}
// set the value to itemTemplate property
itemTemplate(data) {
return (<span><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>);
}
render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" query={this.query} itemTemplate={this.itemTemplate = this.itemTemplate.bind(this)} dataSource={this.employeeData} sortOrder={this.sortOrder} fields={this.fields} placeholder="Select an employee"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React MultiSelect</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-buttons/styles/material.css" rel="stylesheet" />
<link href="./styles.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
</head>
<body>
<div id='sample' style="width:250px; margin: 20px auto 0;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>
.city {
right: 15px;
position: absolute;
}
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
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<{}, {}> {
// bind the DataManager instance to dataSource property
private employeeData: DataManager = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// bind the Query instance to query property
private query: Query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
private fields: object = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
private sortOrder: SortOrder = 'Ascending';
// set the value to itemTemplate property
public itemTemplate(data: any): JSX.Element {
return (
<span><span className='name'>{data.FirstName}</span><span className ='city'>{data.City}</span></span>
);
}
public render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" query={this.query} itemTemplate={this.itemTemplate = this.itemTemplate.bind(this)} dataSource={this.employeeData} sortOrder={this.sortOrder} fields={this.fields} placeholder="Select an employee" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
The currently selected value that is displayed by default on the MultiSelect input element can be customized using the valueTemplate property.
In the following sample, the selected value is displayed as a combined text of both FirstName
and City
in the MultiSelect input, which is separated by a hyphen.
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
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 {
constructor() {
super(...arguments);
// bind the DataManager instance to dataSource property
this.employeeData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// bind the Query instance to query property
this.query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
this.fields = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
this.sortOrder = 'Ascending';
}
// set the value to itemTemplate property
itemTemplate(data) {
return (<span><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>);
}
// set the value to valueTemplate property
valueTemplate(data) {
return (<span>${data.FirstName} - ${data.City}</span>);
}
render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" valueTemplate={this.valueTemplate} query={this.query} itemTemplate={this.itemTemplate} sortOrder={this.sortOrder} dataSource={this.employeeData} fields={this.fields} placeholder="Select an employee"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React MultiSelect</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-buttons/styles/material.css" rel="stylesheet" />
<link href="./styles.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
</head>
<body>
<div id='sample' style="width:250px; margin: 20px auto 0;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>
.city {
right: 15px;
position: absolute;
}
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
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<{}, {}> {
// bind the DataManager instance to dataSource property
private employeeData: DataManager = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// bind the Query instance to query property
private query: Query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
private fields: object = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
private sortOrder: SortOrder = 'Ascending';
// set the value to itemTemplate property
public itemTemplate(data: any): JSX.Element {
return (
<span><span className='name'>{data.FirstName}</span><span className ='city'>{data.City}</span></span>
);
}
// set the value to valueTemplate property
public valueTemplate(data: any): JSX.Element {
return (
<span>${data.FirstName} - ${data.City}</span>
);
}
public render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" valueTemplate={this.valueTemplate} query={this.query} itemTemplate={this.itemTemplate} sortOrder={this.sortOrder} dataSource={this.employeeData} fields={this.fields} placeholder="Select an employee" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
The group header title under which appropriate sub-items are categorized can also be customize with the help of groupTemplate property. This template is common for both inline and floating group header template.
In the following sample, employees are grouped according to their city.
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Predicate, Query } from '@syncfusion/ej2-data';
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 {
constructor() {
super(...arguments);
// bind the DataManager instance to dataSource property
this.employeeData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// form predicate to fetch the grouped data
this.groupPredicate = new Predicate('City', 'equal', 'london').or('City', 'equal', 'seattle');
// bind the Query instance to query property
this.query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6).where(this.groupPredicate);
// maps the appropriate column to fields property
this.fields = { text: 'FirstName', value: 'EmployeeID', groupBy: 'City' };
// sort the resulted items
this.sortOrder = 'Ascending';
}
// set the value to groupTemplate
groupTemplate(data) {
return (<strong>{data.City}</strong>);
}
render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" query={this.query} groupTemplate={this.groupTemplate = this.groupTemplate.bind(this)} dataSource={this.employeeData} sortOrder={this.sortOrder} fields={this.fields} placeholder="Select an employee"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React MultiSelect</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-buttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
</head>
<body>
<div id='sample' style="margin: 20px auto 0; width:250px;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Predicate, Query } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
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<{}, {}> {
// bind the DataManager instance to dataSource property
private employeeData: DataManager = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// form predicate to fetch the grouped data
private groupPredicate = new Predicate('City', 'equal', 'london').or('City', 'equal', 'seattle');
// bind the Query instance to query property
private query: Query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6).where(this.groupPredicate);
// maps the appropriate column to fields property
private fields: object = { text: 'FirstName', value: 'EmployeeID', groupBy: 'City' };
// sort the resulted items
private sortOrder: SortOrder = 'Ascending';
// set the value to groupTemplate
public groupTemplate(data: any): JSX.Element {
return (
<strong>{data.City}</strong>
);
}
public render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" query={this.query} groupTemplate={this.groupTemplate = this.groupTemplate.bind(this)} dataSource={this.employeeData} sortOrder={this.sortOrder} fields={this.fields} placeholder="Select an employee" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
The header element is shown statically at the top of the popup list items within the MultiSelect, and any custom element can be placed as a header element using the headerTemplate property.
In the following sample, the list items and its headers are designed and displayed as two columns similar to multiple columns of the grid.
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
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 {
constructor() {
super(...arguments);
// bind the DataManager instance to dataSource property
this.employeeData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// bind the Query instance to query property
this.query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
this.fields = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
this.sortOrder = 'Ascending';
}
// set the value to header template
headerTemplate(data) {
return (<span className='head'><span className='name'>Name</span><span className='city'>City</span></span>);
}
// set the value to item template
itemTemplate(data) {
return (<span className='item'><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>);
}
render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" query={this.query} headerTemplate={this.headerTemplate} dataSource={this.employeeData} sortOrder={this.sortOrder} itemTemplate={this.itemTemplate} fields={this.fields} placeholder="Select an employee"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React MultiSelect</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-buttons/styles/material.css" rel="stylesheet" />
<link href="./styles.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
</head>
<body>
<div id='sample' style="width:250px; margin: 20px auto 0;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>
.head,
.item {
display: table;
width: 100%;
margin: auto;
}
.head {
height: 40px;
font-size: 15px;
font-weight: 600;
}
.name,
.city {
display: table-cell;
vertical-align: middle;
width: 50%;
}
.head .name {
text-indent: 16px;
}
.head .city {
text-indent: 10px;
}
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
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<{}, {}> {
// bind the DataManager instance to dataSource property
private employeeData: DataManager = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// bind the Query instance to query property
private query: Query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
private fields: object = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
private sortOrder: SortOrder = 'Ascending';
// set the value to header template
public headerTemplate(data: any): JSX.Element {
return (
<span className='head'><span className='name'>Name</span><span className='city'>City</span></span>
);
}
// set the value to item template
public itemTemplate(data: any): JSX.Element {
return (
<span className='item' ><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>
);
}
public render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" query={this.query} headerTemplate={this.headerTemplate} dataSource={this.employeeData} sortOrder={this.sortOrder} itemTemplate={this.itemTemplate} fields={this.fields} placeholder="Select an employee" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
The MultiSelect has options to show a footer element at the bottom of the list items in the popup list. Here, you can place any custom element as a footer element using the footerTemplate property.
In the following sample, footer element displays the total number of list items present in the MultiSelect.
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 {
constructor() {
super(...arguments);
// define the array of data
this.sportsData = ["BasketBall", "Cricket", "Football", "Golf"];
}
// set the value to footer template
footerTemplate() {
return (<span className='foot'/>);
}
render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" footerTemplate={this.footerTemplate} dataSource={this.sportsData} placeholder="Select a game"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React MultiSelect</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-buttons/styles/material.css" rel="stylesheet" />
<link href="./styles.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
</head>
<body>
<div id='sample' style="margin: 20px auto 0; width:250px;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>
.foot {
text-indent: 1.2em;
display: block;
font-size: 15px;
line-height: 40px;
border-top: 1px solid #e0e0e0;
}
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 sportsData: string[] = ["BasketBall", "Cricket", "Football", "Golf"];
// set the value to footer template
public footerTemplate(): JSX.Element {
return (
<span className='foot'/>
);
}
public render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" footerTemplate={this.footerTemplate} dataSource={this.sportsData} placeholder="Select a game" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
The MultiSelect is provided with support to custom design the popup list content when no data is found and no matches found on search with the help of noRecordsTemplate property.
In the following sample, popup list content displays the notification of no data available.
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 {
constructor() {
super(...arguments);
// define the array of data
this.data = [];
}
// set the value to noRecords template
noRecordsTemplate(data) {
return (<span className='norecord'> NO DATA AVAILABLE</span>);
}
render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" noRecordsTemplate={this.noRecordsTemplate = this.noRecordsTemplate.bind(this)} dataSource={this.data} placeholder="Select an item"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React MultiSelect</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-buttons/styles/material.css" rel="stylesheet" />
<link href="./styles.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
</head>
<body>
<div id='sample' style="margin: 20px auto 0; width:250px;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>
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 data: string[] = [];
// set the value to noRecords template
public noRecordsTemplate(data: any): JSX.Element {
return (
<span className='norecord'> NO DATA AVAILABLE</span>
);
}
public render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" noRecordsTemplate={this.noRecordsTemplate = this.noRecordsTemplate.bind(this)} dataSource={this.data} placeholder="Select an item" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
There is also an option to custom design the popup list content when the data fetch request fails at the remote server. This can be achieved using the actionFailureTemplate property.
In the following sample, when the data fetch request fails, the MultiSelect displays the notification.
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
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 {
constructor() {
super(...arguments);
// bind the DataManager instance to dataSource property
this.customerData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'http://services.odata.org/V4/Northwind/Northwind.svcs/'
});
// bind the Query instance to query property
this.query = new Query().from('Customers').select(['ContactName', 'CustomerID']).take(6);
// maps the appropriate column to fields property
this.fields = { text: 'ContactName', value: 'CustomerID' };
}
// set the value to action failure template
failureTemplate(data) {
return (<span className='action-failure'> Data fetch get fails</span>);
}
render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" query={this.query} actionFailureTemplate={this.failureTemplate = this.failureTemplate.bind(this)} dataSource={this.customerData} fields={this.fields} placeholder="Select a customer"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React MultiSelect</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.2.36/ej2-react-buttons/styles/material.css" rel="stylesheet" />
<link href="./styles.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
</head>
<body>
<div id='sample' style="margin: 20px auto 0; width:250px;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
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<{}, {}> {
// bind the DataManager instance to dataSource property
private customerData: DataManager = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'http://services.odata.org/V4/Northwind/Northwind.svcs/'
});
// bind the Query instance to query property
private query: Query = new Query().from('Customers').select(['ContactName', 'CustomerID']).take(6);
// maps the appropriate column to fields property
private fields: object = { text: 'ContactName', value: 'CustomerID' };
// set the value to action failure template
public failureTemplate(data: any): JSX.Element {
return (
<span className='action-failure'> Data fetch get fails</span>
);
}
public render() {
return (
// specifies the tag for render the MultiSelect component
<MultiSelectComponent id="mtselement" query={this.query} actionFailureTemplate={this.failureTemplate = this.failureTemplate.bind(this)} dataSource={this.customerData} fields={this.fields} placeholder="Select a customer" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));