Templates in React Auto complete component

8 Dec 202324 minutes to read

The AutoComplete has been provided with several options to customize each list items, group title, header and footer elements.

To get started with React AutoComplete templates, you can check on this video:

Item template

The content of each list item within the AutoComplete can be customized with the help of itemTemplate property.

In the below sample, each list item is split into two columns to showcase relevant data’s.

[Class-component]

// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName' };
    // sort the resulted items
    sortOrder = 'Ascending';
    render() {
        return (
        // specifies the tag for render the AutoComplete component
        <AutoCompleteComponent id="atcelement" query={this.query} itemTemplate={this.itemTemplate} dataSource={this.employeeData} fields={this.fields} sortOrder={this.sortOrder} placeholder="Find an employee"/>);
    }
    // set the value to itemTemplate property
    itemTemplate(data) {
        return (<span><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName' };
    // sort the resulted items
    private sortOrder: string = 'Ascending';

    public render() {
        return (
             // specifies the tag for render the AutoComplete component
            <AutoCompleteComponent id="atcelement" query={this.query} itemTemplate={this.itemTemplate} dataSource={this.employeeData} fields={this.fields} sortOrder={this.sortOrder} placeholder="Find an employee"/>
        );
    }

    // set the value to itemTemplate property
    private itemTemplate(data: any): JSX.Element {
      return (
        <span><span className='name'>{data.FirstName}</span><span className ='city'>{data.City}</span></span>
        );
      }
}
ReactDOM.render(<App />, document.getElementById('sample'));

[Functional-component]

// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName' };
    // sort the resulted items
    const sortOrder = 'Ascending';
    return (
    // specifies the tag for render the AutoComplete component
    <AutoCompleteComponent id="atcelement" query={query} itemTemplate={itemTemplate} dataSource={employeeData} fields={fields} sortOrder={sortOrder} placeholder="Find an employee"/>);
    // set the value to itemTemplate property
    function itemTemplate(data) {
        return (<span><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName' };
    // sort the resulted items
    const sortOrder: string = 'Ascending';

    return (
    // specifies the tag for render the AutoComplete component
          <AutoCompleteComponent id="atcelement" query={query} itemTemplate={itemTemplate} dataSource={employeeData} fields={fields} sortOrder={sortOrder} placeholder="Find an employee"/>
    );

    // set the value to itemTemplate property
    function itemTemplate(data: any): JSX.Element {
      return (
        <span><span className='name'>{data.FirstName}</span><span className ='city'>{data.City}</span></span>
        );
      }
}
ReactDOM.render(<App />, document.getElementById('sample'));

Group template

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 below sample,employees are grouped according to their city.

[Class-component]

// import DataManager related classes
import { DataManager, ODataV4Adaptor, Predicate, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName', groupBy: 'City' };
    // sort the resulted items
    sortOrder = 'Ascending';
    render() {
        return (
        // specifies the tag for render the AutoComplete component
        <AutoCompleteComponent id="atcelement" query={this.query} groupTemplate={this.groupTemplate} dataSource={this.employeeData} sortOrder={this.sortOrder} fields={this.fields} placeholder="Find an employee"/>);
    }
    // set the value to groupTemplate
    groupTemplate(data) {
        return (<strong>{data.City}</strong>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Predicate, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName', groupBy: 'City' };
  // sort the resulted items
  private sortOrder: string = 'Ascending';


  public render() {
    return (
      // specifies the tag for render the AutoComplete component
      <AutoCompleteComponent id="atcelement" query={this.query} groupTemplate={this.groupTemplate} dataSource={this.employeeData} sortOrder={this.sortOrder} fields={this.fields} placeholder="Find an employee" />
    );
  }

  // set the value to groupTemplate
  private groupTemplate(data: any): JSX.Element {
    return (
      <strong>{data.City}</strong>
    );
  }
}
ReactDOM.render(<App />, document.getElementById('sample'));

[Functional-component]

// import DataManager related classes
import { DataManager, ODataV4Adaptor, Predicate, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName', groupBy: 'City' };
    // sort the resulted items
    const sortOrder = 'Ascending';
    return (
    // specifies the tag for render the AutoComplete component
    <AutoCompleteComponent id="atcelement" query={query} groupTemplate={groupTemplate} dataSource={employeeData} sortOrder={sortOrder} fields={fields} placeholder="Find an employee"/>);
    // set the value to groupTemplate
    function groupTemplate(data) {
        return (<strong>{data.City}</strong>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Predicate, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName', groupBy: 'City' };
  // sort the resulted items
  const sortOrder: string = 'Ascending';

  return (
  // specifies the tag for render the AutoComplete component
      <AutoCompleteComponent id="atcelement" query={query} groupTemplate={groupTemplate} dataSource={employeeData} sortOrder={sortOrder} fields={fields} placeholder="Find an employee" />
  );

  // set the value to groupTemplate
  function groupTemplate(data: any): JSX.Element {
    return (
      <strong>{data.City}</strong>
    );
  }
}
ReactDOM.render(<App />, document.getElementById('sample'));

Header template

The header element is shown statically at the top of the suggestion list items within the AutoComplete 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.

[Class-component]

// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName' };
    // sort the resulted items
    sortOrder = 'Ascending';
    render() {
        return (
        // specifies the tag for render the AutoComplete component
        <AutoCompleteComponent id="atcelement" query={this.query} headerTemplate={this.headerTemplate} dataSource={this.employeeData} sortOrder={this.sortOrder} itemTemplate={this.itemTemplate} fields={this.fields} placeholder="Find an employee"/>);
    }
    // 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>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName' };
  // sort the resulted items
  private sortOrder: string = 'Ascending';

  public render() {
    return (
      // specifies the tag for render the AutoComplete component
      <AutoCompleteComponent id="atcelement" query={this.query} headerTemplate={this.headerTemplate} dataSource={this.employeeData} sortOrder={this.sortOrder} itemTemplate={this.itemTemplate} fields={this.fields} placeholder="Find an employee" />
    );
  }

  // set the value to header template
  private 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
  private itemTemplate(data: any): JSX.Element {
    return (
      <span className='item' ><span className='name'>{data.FirstName}</span><span className='city'>{data.City}</span></span>
    );
  }
}
ReactDOM.render(<App />, document.getElementById('sample'));

[Functional-component]

// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName' };
    // sort the resulted items
    const sortOrder = 'Ascending';
    return (
    // specifies the tag for render the AutoComplete component
    <AutoCompleteComponent id="atcelement" query={query} headerTemplate={headerTemplate} dataSource={employeeData} sortOrder={sortOrder} itemTemplate={itemTemplate} fields={fields} placeholder="Find an employee"/>);
    // 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>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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 = { value: 'FirstName' };
  // sort the resulted items
  const sortOrder: string = 'Ascending';

    return (
      // specifies the tag for render the AutoComplete component
      <AutoCompleteComponent id="atcelement" query={query} headerTemplate={headerTemplate} dataSource={employeeData} sortOrder={sortOrder} itemTemplate={itemTemplate} fields={fields} placeholder="Find an employee" />
    );

  // 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>
    );
  }
}
ReactDOM.render(<App />, document.getElementById('sample'));

The AutoComplete has options to show a footer element at the bottom of the list items in the suggestion 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 AutoComplete.

[Class-component]

import { AutoCompleteComponent } 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
    atcObject;
    sportsData = ['Badminton', 'Basketball', 'Cricket', 'Football', 'Golf', 'Gymnastics', 'Hockey', 'Rugby', 'Snooker', 'Tennis'];
    onOpen = (e) => {
        const count = this.atcObject.getItems().length;
        // set the value to footerTemplate property
        const ele = document.getElementsByClassName('foot')[0];
        ele.innerHTML = "Total list item: " + count;
    };
    render() {
        return (
        // specifies the tag for render the AutoComplete component
        <AutoCompleteComponent id="atcelement" ref={(autocomplete) => { this.atcObject = autocomplete; }} footerTemplate={this.footerTemplate} dataSource={this.sportsData} placeholder="Find a game" open={this.onOpen = this.onOpen.bind(this)}/>);
    }
    // set the footer template
    footerTemplate() {
        return (<span className='foot'/>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
import { AutoCompleteComponent } 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 atcObject: any;
    private sportsData: string[] = ['Badminton', 'Basketball', 'Cricket', 'Football', 'Golf', 'Gymnastics', 'Hockey', 'Rugby', 'Snooker', 'Tennis'];
    public onOpen = (e: any) => {
      const count = this.atcObject.getItems().length;
      // set the value to footerTemplate property
      const ele = document.getElementsByClassName('foot')[0];
      ele.innerHTML =  "Total list item: " + count;
    };


   public render() {
        return (
              // specifies the tag for render the AutoComplete component
            <AutoCompleteComponent id="atcelement" ref={(autocomplete) => { this.atcObject = autocomplete }} footerTemplate={this.footerTemplate} dataSource={this.sportsData} placeholder="Find a game" open={ this.onOpen =this.onOpen.bind(this)}/>
        );
    }

    // set the footer template
    private footerTemplate(): JSX.Element {
      return (
             <span className='foot'/>
        );
      }
}
ReactDOM.render(<App />, document.getElementById('sample'));

[Functional-component]

import { AutoCompleteComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
    // define the array of data
    let atcObject;
    const sportsData = ['Badminton', 'Basketball', 'Cricket', 'Football', 'Golf', 'Gymnastics', 'Hockey', 'Rugby', 'Snooker', 'Tennis'];
    function onOpen(e) {
        const count = this.atcObject.getItems().length;
        // set the value to footerTemplate property
        const ele = document.getElementsByClassName('foot')[0];
        ele.innerHTML = "Total list item: " + count;
    }
    ;
    return (
    // specifies the tag for render the AutoComplete component
    <AutoCompleteComponent id="atcelement" ref={(autocomplete) => { atcObject = autocomplete; }} footerTemplate={footerTemplate} dataSource={sportsData} placeholder="Find a game" open={onOpen = onOpen.bind(this)}/>);
    // set the footer template
    function footerTemplate() {
        return (<span className='foot'/>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
import { AutoCompleteComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';

function App() {

    // define the array of data
    let atcObject: any;
    const sportsData: string[] = ['Badminton', 'Basketball', 'Cricket', 'Football', 'Golf', 'Gymnastics', 'Hockey', 'Rugby', 'Snooker', 'Tennis'];
    function onOpen(e: any){
      const count = this.atcObject.getItems().length;
      // set the value to footerTemplate property
      const ele = document.getElementsByClassName('foot')[0];
      ele.innerHTML =  "Total list item: " + count;
    };

    return (
    // specifies the tag for render the AutoComplete component
        <AutoCompleteComponent id="atcelement" ref={(autocomplete) => {atcObject = autocomplete }} footerTemplate={footerTemplate} dataSource={sportsData} placeholder="Find a game" open={onOpen =onOpen.bind(this)}/>
    );

    // set the footer template
    function footerTemplate(): JSX.Element {
      return (
             <span className='foot'/>
        );
      }
}
ReactDOM.render(<App />, document.getElementById('sample'));

No Records template

The AutoComplete is provided with support to custom design the suggestion 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 { AutoCompleteComponent } 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 = [];
    render() {
        return (
        // specifies the tag for render the AutoComplete component
        <AutoCompleteComponent id="atcelement" noRecordsTemplate={this.noRecordsTemplate = this.noRecordsTemplate.bind(this)} dataSource={this.data} placeholder="Find an item"/>);
    }
    // set the value to noRecords template
    noRecordsTemplate() {
        return (<span className='norecord'> NO DATA AVAILABLE</span>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
import { AutoCompleteComponent } 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: { [key: string]: Object }[] = [];


   public render() {
        return (
              // specifies the tag for render the AutoComplete component
            <AutoCompleteComponent id="atcelement" noRecordsTemplate={this.noRecordsTemplate = this.noRecordsTemplate.bind(this)} dataSource={this.data} placeholder="Find an item"/>
        );
    }

    // set the value to noRecords template
    private noRecordsTemplate(): JSX.Element {
      return (
            <span className='norecord'> NO DATA AVAILABLE</span>
        );
      }
}
ReactDOM.render(<App />, document.getElementById('sample'));

[Functional-component]

import { AutoCompleteComponent } 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 = [];
    return (
    // specifies the tag for render the AutoComplete component
    <AutoCompleteComponent id="atcelement" noRecordsTemplate={noRecordsTemplate = noRecordsTemplate.bind(this)} dataSource={data} placeholder="Find an item"/>);
    // set the value to noRecords template
    function noRecordsTemplate() {
        return (<span className='norecord'> NO DATA AVAILABLE</span>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
import { AutoCompleteComponent } 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: { [key: string]: Object }[] = [];

    return (
    // specifies the tag for render the AutoComplete component
        <AutoCompleteComponent id="atcelement" noRecordsTemplate={noRecordsTemplate = noRecordsTemplate.bind(this)} dataSource={data} placeholder="Find an item"/>
    );

    // set the value to noRecords template
    function noRecordsTemplate(): JSX.Element {
      return (
            <span className='norecord'> NO DATA AVAILABLE</span>
        );
      }
}
ReactDOM.render(<App />, document.getElementById('sample'));

Action Failure template

There is also an option to custom design the suggestion 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 AutoComplete displays the notification.

[Class-component]

// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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: 'https://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 = { value: 'ContactName' };
    render() {
        return (
        // specifies the tag for render the AutoComplete component
        <AutoCompleteComponent id="atcelement" query={this.query} actionFailureTemplate={this.template = this.template.bind(this)} dataSource={this.customerData} fields={this.fields} placeholder="Find a customer"/>);
    }
    // set the value to action failure template
    template() {
        return (<span className='action-failure'> Data fetch get fails</span>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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: 'https://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 = { value: 'ContactName' };

  public render() {
    return (
      // specifies the tag for render the AutoComplete component
      <AutoCompleteComponent id="atcelement" query={this.query} actionFailureTemplate={this.template = this.template.bind(this)} dataSource={this.customerData} fields={this.fields} placeholder="Find a customer" />
    );
  }

  // set the value to action failure template
  private template(): JSX.Element {
    return (
      <span className='action-failure'> Data fetch get fails</span>
    );
  }
}
ReactDOM.render(<App />, document.getElementById('sample'));

[Functional-component]

// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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: 'https://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 = { value: 'ContactName' };
    return (
    // specifies the tag for render the AutoComplete component
    <AutoCompleteComponent id="atcelement" query={query} actionFailureTemplate={template = template.bind(this)} dataSource={customerData} fields={fields} placeholder="Find a customer"/>);
    // set the value to action failure template
    function template() {
        return (<span className='action-failure'> Data fetch get fails</span>);
    }
}
ReactDOM.render(<App />, document.getElementById('sample'));
// import DataManager related classes
import { DataManager, ODataV4Adaptor, Query } from '@syncfusion/ej2-data';
import { AutoCompleteComponent } 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: 'https://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 = { value: 'ContactName' };

    return (
      // specifies the tag for render the AutoComplete component
      <AutoCompleteComponent id="atcelement" query={query} actionFailureTemplate={template = template.bind(this)} dataSource={customerData} fields={fields} placeholder="Find a customer" />
    );

  // set the value to action failure template
  function template(): JSX.Element {
    return (
      <span className='action-failure'> Data fetch get fails</span>
    );
  }
}
ReactDOM.render(<App />, document.getElementById('sample'));

See Also