How can I help you?
Templates in React Combo box component
21 Feb 202624 minutes to read
The ComboBox provides comprehensive template support to customize list items, group titles, headers, and footer elements.
To get started with React ComboBox templates, you can check this video:
Item template
Customize the content of each list item using the itemTemplate property. This allows you to create custom layouts for displaying data in each item.
In the following example, each list item displays data in a two-column layout.
[Class-component]
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { ComboBoxComponent } 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
employeeData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// bind the Query instance to query property
query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
fields = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
sortOrder = 'Ascending';
// set the value to itemTemplate property
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 ComboBox component
<ComboBoxComponent id="comboelement" query={this.query} itemTemplate={this.itemTemplate} dataSource={this.employeeData} fields={this.fields} sortOrder={this.sortOrder} placeholder="Select an employee"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
import { ComboBoxComponent } 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 className='item' ><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>
);
}
public render() {
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" query={this.query} itemTemplate={this.itemTemplate} dataSource={this.employeeData} fields={this.fields} sortOrder={this.sortOrder} placeholder="Select an employee" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));[Functional-component]
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// bind the DataManager instance to dataSource property
const employeeData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// bind the Query instance to query property
const query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
const fields = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
const sortOrder = 'Ascending';
// set the value to itemTemplate property
function itemTemplate(data) {
return (<span className='item'><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" query={query} itemTemplate={itemTemplate} dataSource={employeeData} fields={fields} sortOrder={sortOrder} placeholder="Select an employee"/>);
}
ReactDOM.render(<App />, document.getElementById('sample'));import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// bind the DataManager instance to dataSource property
const 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
const query: Query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
const fields: object = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
const sortOrder: SortOrder = 'Ascending';
// set the value to itemTemplate property
function itemTemplate(data: any): JSX.Element {
return (
<span className='item' ><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>
);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" query={query} itemTemplate={itemTemplate} dataSource={employeeData} fields={fields} sortOrder={sortOrder} placeholder="Select an employee" />
);
}
ReactDOM.render(<App />, document.getElementById('sample'));Group template
Customize group header titles using the groupTemplate property. This template applies to both inline and floating group headers, allowing consistent group header styling.
In the following example, employees are grouped by their city.
[Class-component]
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Predicate, Query } from '@syncfusion/ej2-data';
import { ComboBoxComponent } 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
employeeData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// form predicate to fetch the grouped data
groupPredicate = new Predicate('City', 'equal', 'london').or('City', 'equal', 'seattle');
// bind the Query instance to query property
query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6).where(this.groupPredicate);
// maps the appropriate column to fields property
fields = { text: 'FirstName', value: 'EmployeeID', groupBy: 'City' };
// sort the resulted items
sortOrder = 'Ascending';
// set the value to groupTemplate
groupTemplate(data) {
return (<strong>{data.City}</strong>);
}
render() {
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" query={this.query} groupTemplate={this.groupTemplate} dataSource={this.employeeData} fields={this.fields} sortOrder={this.sortOrder} placeholder="Select an employee"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));// import DataManager related classes
import { DataManager, ODataV4Adaptor, Predicate, Query } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
import { ComboBoxComponent } 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 ComboBox component
<ComboBoxComponent id="comboelement" query={this.query} groupTemplate={this.groupTemplate} dataSource={this.employeeData} fields={this.fields} sortOrder={this.sortOrder} placeholder="Select an employee" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));[Functional-component]
import { DataManager, ODataV4Adaptor, Predicate, Query } from '@syncfusion/ej2-data';
import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// bind the DataManager instance to dataSource property
const employeeData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// form predicate to fetch the grouped data
const groupPredicate = new Predicate('City', 'equal', 'london').or('City', 'equal', 'seattle');
// bind the Query instance to query property
const query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6).where(groupPredicate);
// maps the appropriate column to fields property
const fields = { text: 'FirstName', value: 'EmployeeID', groupBy: 'City' };
// sort the resulted items
const sortOrder = 'Ascending';
// set the value to groupTemplate
function groupTemplate(data) {
return (<strong>{data.City}</strong>);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" query={query} groupTemplate={groupTemplate} dataSource={employeeData} fields={fields} sortOrder={sortOrder} placeholder="Select an employee"/>);
}
ReactDOM.render(<App />, document.getElementById('sample'));import { DataManager, ODataV4Adaptor, Predicate, Query } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// bind the DataManager instance to dataSource property
const 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
const groupPredicate = new Predicate('City', 'equal', 'london').or('City', 'equal', 'seattle');
// bind the Query instance to query property
const query: Query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6).where(groupPredicate);
// maps the appropriate column to fields property
const fields: object = { text: 'FirstName', value: 'EmployeeID', groupBy: 'City' };
// sort the resulted items
const sortOrder: SortOrder = 'Ascending';
// set the value to groupTemplate
function groupTemplate(data: any): JSX.Element {
return (
<strong>{data.City}</strong>
);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" query={query} groupTemplate={groupTemplate} dataSource={employeeData} fields={fields} sortOrder={sortOrder} placeholder="Select an employee" />
);
}
ReactDOM.render(<App />, document.getElementById('sample'));Header template
Add a static header to the top of the popup list using the headerTemplate property. This allows you to place custom elements such as titles, filters, or other controls in the header area.
In the following example, list items and their headers display in a two-column layout similar to a data grid.
[Class-component]
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { ComboBoxComponent } 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
employeeData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// bind the Query instance to query property
query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
fields = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
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 ComboBox component
<ComboBoxComponent id="comboelement" 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'));// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
import { ComboBoxComponent } 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 ComboBox component
<ComboBoxComponent id="comboelement" 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'));[Functional-component]
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// bind the DataManager instance to dataSource property
const employeeData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'https://services.odata.org/V4/Northwind/Northwind.svc/'
});
// bind the Query instance to query property
const query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
const fields = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
const sortOrder = 'Ascending';
// set the value to header template
function headerTemplate(data) {
return (<span className='head'><span className='name'>Name</span><span className='city'>City</span></span>);
}
// set the value to item template
function itemTemplate(data) {
return (<span className='item'><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" query={query} headerTemplate={headerTemplate} dataSource={employeeData} sortOrder={sortOrder} itemTemplate={itemTemplate} fields={fields} placeholder="Select an employee"/>);
}
ReactDOM.render(<App />, document.getElementById('sample'));// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { SortOrder } from '@syncfusion/ej2-lists';
import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// bind the DataManager instance to dataSource property
const 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
const query: Query = new Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6);
// maps the appropriate column to fields property
const fields: object = { text: 'FirstName', value: 'EmployeeID' };
// sort the resulted items
const sortOrder: SortOrder = 'Ascending';
// set the value to header template
function 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
function itemTemplate(data: any): JSX.Element {
return (
<span className='item' ><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>
);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" query={query} headerTemplate={headerTemplate} dataSource={employeeData} sortOrder={sortOrder} itemTemplate={itemTemplate} fields={fields} placeholder="Select an employee" />
);
}
ReactDOM.render(<App />, document.getElementById('sample'));Footer template
Add a footer element at the bottom of the popup list using the footerTemplate property. This allows you to place custom elements such as summaries, totals, or action buttons.
In the following example, the footer displays the total number of list items in the ComboBox.
[Class-component]
import { ComboBoxComponent } 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
sportsData = ["BasketBall", "Cricket", "Football", "Golf"];
// set the value to footer template
footerTemplate(data) {
return (<span className='foot'/>);
}
render() {
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" footerTemplate={this.footerTemplate} dataSource={this.sportsData} placeholder="Select a game"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));import { ComboBoxComponent } 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(data: any): JSX.Element {
return (
<span className='foot'/>
);
}
public render() {
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" footerTemplate={this.footerTemplate} dataSource={this.sportsData} placeholder="Select a game" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));[Functional-component]
import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// define the array of data
const sportsData = ["BasketBall", "Cricket", "Football", "Golf"];
// set the value to footer template
function footerTemplate(data) {
return (<span className='foot'/>);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" footerTemplate={footerTemplate} dataSource={sportsData} placeholder="Select a game"/>);
}
ReactDOM.render(<App />, document.getElementById('sample'));import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// define the array of data
const sportsData: string[] = ["BasketBall", "Cricket", "Football", "Golf"];
// set the value to footer template
function footerTemplate(data: any): JSX.Element {
return (
<span className='foot'/>
);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" footerTemplate={footerTemplate} dataSource={sportsData} placeholder="Select a game" />
);
}
ReactDOM.render(<App />, document.getElementById('sample'));No records template
The ComboBox 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.
[Class-component]
import { ComboBoxComponent } 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
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 ComboBox component
<ComboBoxComponent id="comboelement" noRecordsTemplate={this.noRecordsTemplate = this.noRecordsTemplate.bind(this)} dataSource={this.data} placeholder="Select an item"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));import { ComboBoxComponent } 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 ComboBox component
<ComboBoxComponent id="comboelement" noRecordsTemplate={this.noRecordsTemplate = this.noRecordsTemplate.bind(this)} dataSource={this.data} placeholder="Select an item" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));[Functional-component]
import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// define the array of data
const data = [];
// set the value to noRecords template
function noRecordsTemplate(data) {
return (<span className='norecord'> NO DATA AVAILABLE</span>);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" noRecordsTemplate={noRecordsTemplate = noRecordsTemplate.bind(this)} dataSource={data} placeholder="Select an item"/>);
}
ReactDOM.render(<App />, document.getElementById('sample'));import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// define the array of data
const data: string[] = [];
// set the value to noRecords template
function noRecordsTemplate(data: any): JSX.Element {
return (
<span className='norecord'> NO DATA AVAILABLE</span>
);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" noRecordsTemplate={noRecordsTemplate = noRecordsTemplate.bind(this)} dataSource={data} placeholder="Select an item" />
);
}
ReactDOM.render(<App />, document.getElementById('sample'));Action failure template
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 ComboBox displays the notification.
[Class-component]
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { ComboBoxComponent } 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
customerData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'http://services.odata.org/V4/Northwind/Northwind.svcs/'
});
// bind the Query instance to query property
query = new Query().from('Customers').select(['ContactName', 'CustomerID']).take(6);
// maps the appropriate column to fields property
fields = { text: 'ContactName', value: 'CustomerID' };
// set the value to action failure template
template(data) {
return (<span className='action-failure'> Data fetch get fails</span>);
}
render() {
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" actionFailureTemplate={this.template = this.template.bind(this)} query={this.query} dataSource={this.customerData} fields={this.fields} placeholder="Select a customer"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { ComboBoxComponent } 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 template(data: any): JSX.Element {
return (
<span className='action-failure'> Data fetch get fails</span>
);
}
public render() {
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" actionFailureTemplate={this.template = this.template.bind(this)} query={this.query} dataSource={this.customerData} fields={this.fields} placeholder="Select a customer" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));[Functional-component]
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// bind the DataManager instance to dataSource property
const customerData = new DataManager({
adaptor: new ODataV4Adaptor,
crossDomain: true,
url: 'http://services.odata.org/V4/Northwind/Northwind.svcs/'
});
// bind the Query instance to query property
const query = new Query().from('Customers').select(['ContactName', 'CustomerID']).take(6);
// maps the appropriate column to fields property
const fields = { text: 'ContactName', value: 'CustomerID' };
// set the value to action failure template
function template(data) {
return (<span className='action-failure'> Data fetch get fails</span>);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" actionFailureTemplate={template = template.bind(this)} query={query} dataSource={customerData} fields={fields} placeholder="Select a customer"/>);
}
ReactDOM.render(<App />, document.getElementById('sample'));// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { ComboBoxComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// bind the DataManager instance to dataSource property
const 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
const query: Query = new Query().from('Customers').select(['ContactName', 'CustomerID']).take(6);
// maps the appropriate column to fields property
const fields: object = { text: 'ContactName', value: 'CustomerID' };
// set the value to action failure template
function template(data: any): JSX.Element {
return (
<span className='action-failure'> Data fetch get fails</span>
);
}
return (
// specifies the tag for render the ComboBox component
<ComboBoxComponent id="comboelement" actionFailureTemplate={template = template.bind(this)} query={query} dataSource={customerData} fields={fields} placeholder="Select a customer" />
);
}
ReactDOM.render(<App />, document.getElementById('sample'));