Search results

Templates

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

Item template

The content of each list item within the ComboBox 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.

Source
Preview
app.component.ts
app.module.ts
main.ts
itemTemplate.html
import { Component } from '@angular/core';
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';
import { Query, DataManager, ODataV4Adaptor } from '@syncfusion/ej2-data'

@Component({
    selector: 'app-container',
    // specifies the template url path
    templateUrl: './itemTemplate.html'
})
export class AppComponent {
    constructor() {
    }
    //bind the DataManager instance to dataSource property
    public data: DataManager = new DataManager({
            url: 'http://services.odata.org/V4/Northwind/Northwind.svc/',
            adaptor: new ODataV4Adaptor,
            crossDomain: true
        });
    // maps the appropriate column to fields property
    public fields: Object = { text: 'FirstName', value: 'EmployeeID' };
    //bind the Query instance to query property
    public query: Query = new Query().from('Employees').select(['FirstName', 'City','EmployeeID']).take(6);
    //set the placeholder to ComboBox input
    public text: string = "Select an employee";
    //sort the result items
    public sorting: string = 'Ascending';
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,FormsModule
    ],
    declarations: [AppComponent, ComboBoxComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Angular ComboBox</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript Toolbar Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet" />
    <script src="https://unpkg.com/core-js/client/shim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.6.25/zone.min.js"></script>
    <script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id="wrapper">
	  <div id='content' style="margin: 40px auto 0; width:250px;">
        <!-- specifies the template string for the ComboBox component-->
        <ejs-combobox id='combobox-template' [dataSource]='data' [fields]='fields' [sortOrder]='sorting' [query]='query' [popupHeight]='height' [placeholder]='text' [itemTemplate]='itemTemplate'>
            <ng-template #itemTemplate="" let-data="">
                <!--set the value to itemTemplate property-->
                <span><span class='name'> {{data.FirstName}}</span><span class ='city'>{{data.City}}</span></span>
            </ng-template>
        </ejs-combobox>
      </div>
    </div>
</body>
</html>

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

Source
Preview
app.component.ts
app.module.ts
main.ts
groupTemplate.html
import { Component } from '@angular/core';
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';
import { Query, Predicate, DataManager, ODataV4Adaptor } from '@syncfusion/ej2-data'

@Component({
    selector: 'app-container',
    // specifies the template url path
    templateUrl: './groupTemplate.html'
})
export class AppComponent {
    constructor() {
    }
    //bind the DataManager instance to dataSource property
    public data: DataManager = new DataManager({
            url: 'http://services.odata.org/V4/Northwind/Northwind.svc/',
            adaptor: new ODataV4Adaptor,
            crossDomain: true
        });
    // form  predicate to fetch the grouped data
    public groupPredicate = new Predicate('City', 'equal','london').or('City','equal','seattle');
    // maps the appropriate column to fields property
    public fields: Object = { text: 'FirstName', value: 'EmployeeID', groupBy:'City' };
    //bind the Query instance to query property
    public query: Query = new Query().from('Employees').select(['FirstName', 'City','EmployeeID']).take(5).where(this.groupPredicate);
    //set the placeholder to ComboBox input
    public text: string = "Select an employee";
    //sort the result items
    public sorting: string = 'Ascending';
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,FormsModule
    ],
    declarations: [AppComponent, ComboBoxComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Angular ComboBox</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript Toolbar Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet" />
    <script src="https://unpkg.com/core-js/client/shim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.6.25/zone.min.js"></script>
    <script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id="wrapper">
	  <div id='content' style="margin: 40px auto 0; width:250px;">
        <!-- specifies the template string for the ComboBox component-->
        <ejs-combobox id='comboelement' #samples [dataSource]='data' [fields]='fields' [sortOrder]='sorting' [placeholder]='text' [groupTemplate]='groupTemplate' [query]='query'>
            <ng-template #groupTemplate="" let-data="">
                <!--set the value to groupTemplate property-->
                <strong>{{data.City}}</strong>
            </ng-template>
        </ejs-combobox>
      </div>
    </div>
</body>
</html>

Header template

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

Source
Preview
app.component.ts
app.module.ts
main.ts
headerTemplate.html
import { Component } from '@angular/core';
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';
import { Query, DataManager, ODataV4Adaptor } from '@syncfusion/ej2-data';

@Component({
    selector: 'app-container',
    // specifies the template url path
    templateUrl: './headerTemplate.html'
})
export class AppComponent {
    constructor() {
    }
    //bind the DataManager instance to dataSource property
    public data: DataManager = new DataManager({
            url: 'http://services.odata.org/V4/Northwind/Northwind.svc/',
            adaptor: new ODataV4Adaptor,
            crossDomain: true
        });
    // maps the appropriate column to fields property
    public fields: Object = { text: 'FirstName', value: 'EmployeeID' };
    //bind the Query instance to query property
    public query: Query = new Query().from('Employees').select(['FirstName', 'City','EmployeeID']).take(6);
    //set the placeholder to ComboBox input
    public text: string = "Select an employee";
    //sort the result items
    public sorting: string = 'Ascending';
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,FormsModule
    ],
    declarations: [AppComponent, ComboBoxComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Angular ComboBox</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript Toolbar Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet" />
    <script src="https://unpkg.com/core-js/client/shim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.6.25/zone.min.js"></script>
    <script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id="wrapper">
	  <div id='content' style="margin: 40px auto 0; width:250px;">
        <!-- specifies the template string for the ComboBox component-->
        <ejs-combobox id='comboelement' #samples [dataSource]='data' [fields]='fields' [sortOrder]='sorting' [placeholder]='text' [query]='query' [headerTemplate]='headerTemplate' [itemTemplate]='itemTemplate'>
            <ng-template #itemTemplate="" let-data="">
                <!--set the value to itemTemplate property-->
                <span class='item'><span class='name'> {{data.FirstName}}</span><span class ='city'>{{data.City}}</span></span>
            </ng-template>
            <ng-template #headerTemplate="" let-data="">
                <!--set the value to headerTemplate property-->
                <span class='head'><span class='name'>Name</span><span class='city'>City</span></span>
            </ng-template>
        </ejs-combobox>
      </div>
    </div>
</body>
</html>

The ComboBox 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 footerTemplate property.

In the following sample, footer element displays the total number of list items present in the ComboBox.

Source
Preview
app.component.ts
app.module.ts
main.ts
footerTemplate.html
import { Component, ViewChild } from '@angular/core';
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';

@Component({
    selector: 'app-container',
    // specifies the template url path
    templateUrl: './footerTemplate.html'
})
export class AppComponent {
    @ViewChild('samples')
    // create a object for ComboBox
    public sportsObj: ComboBoxComponent;
    constructor() {
    }
    // defined the array of data
    public data: Object[] = ['Badminton', 'Basketball', 'Cricket', 'Hockey', 'Golf'];
    // set placeholder text to ComboBox input element
    public text: string = 'Select a game';
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,FormsModule
    ],
    declarations: [AppComponent, ComboBoxComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Angular ComboBox</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript Toolbar Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet" />
    <script src="https://unpkg.com/core-js/client/shim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.6.25/zone.min.js"></script>
    <script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id="wrapper">
	  <div id='content' style="margin: 40px auto 0; width:250px;">
        <!-- specifies the template string for the ComboBox component-->
        <ejs-combobox id='comboelement' #samples [dataSource]='data' [placeholder]='text' [footerTemplate]='footerTemplate'>
            <ng-template #footerTemplate="" let-data="">
                <!--set the value to footerTemplate property-->
                <span class='foot'> Total list item: 5</span>
            </ng-template>
        </ejs-combobox>
      </div>
    </div>
</body>
</html>

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.

Source
Preview
app.component.ts
app.module.ts
main.ts
index.css
import { Component } from '@angular/core';

@Component({
    selector: 'app-container',
    // specifies the template string for the ComboBox component
    template:  `<ejs-combobox id='comboelement' [dataSource]='data' placeholder='Find a item'>
                    <ng-template #noRecordsTemplate>
                        <span class='norecord'> NO DATA AVAILABLE</span>
                    </ng-template>
                 </ejs-combobox>`
})
export class AppComponent {
    // defined the empty array data
    public data: string[] = [];
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,FormsModule
    ],
    declarations: [AppComponent, ComboBoxComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
#container {
    visibility: hidden;
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  top: 45%;
  left: 45%;
}

#wrapper {
    width: 250px;
    margin: 0 auto;
}
.norecord:before{
    content: '\e7c3';
    font-family: 'e-icons';
    font-size: 18px;
    margin-left: -25px;
    margin-top: -3px;
    position: absolute;
}

.action-failure:before{
    content: '\e7c4';
    font-family: 'e-icons';
    font-size: 18px;
    margin-top: -4px;
    position: absolute;
    margin-left: -25px;
}

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.

Source
Preview
app.component.ts
app.module.ts
main.ts
index.css
import { Component } from '@angular/core';
//import data manager related classes
import { Query, DataManager, ODataV4Adaptor } from '@syncfusion/ej2-data';

@Component({
    selector: 'app-container',
    // specifies the template string for the ComboBox component
    template:  `<ejs-combobox id='comboelement' [dataSource]='data' [query]='query' [fields]='fields'      placeholder='Find an employee'>
                    <ng-template #actionFailureTemplate>
                        <span class='action-failure'> Data fetch get fails</span>
                    </ng-template>
                 </ejs-combobox>`
})
export class AppComponent {
    //bind the data manager instance to dataSource property
    public data: DataManager = new DataManager({
            // Here, use the wrong url to display the action failure template
            url: 'http://services.odata.org/V4/Northwind/Northwind.svcs/',
            adaptor: new ODataV4Adaptor,
            crossDomain: true
    });
    //bind the Query instance to query property
    public query: Query =  new Query().from('Employees').select(['FirstName']).take(6);

    // maps the appropriate column to fields property
    public fields: Object =  { text: 'FirstName', value: 'EmployeeID' };
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ComboBoxComponent } from '@syncfusion/ej2-ng-dropdowns';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,FormsModule
    ],
    declarations: [AppComponent, ComboBoxComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
#container {
    visibility: hidden;
}

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  top: 45%;
  left: 45%;
}

#wrapper {
    width: 250px;
    margin: 0 auto;
}
.norecord:before{
    content: '\e7c3';
    font-family: 'e-icons';
    font-size: 18px;
    margin-left: -25px;
    margin-top: -3px;
    position: absolute;
}

.action-failure:before{
    content: '\e7c4';
    font-family: 'e-icons';
    font-size: 18px;
    margin-top: -4px;
    position: absolute;
    margin-left: -25px;
}