Search results

Templates

The ComboBox has been provided with several options to customize each list item, group title, selected value, 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.

@using Syncfusion.EJ2.Blazor.Data
@using Syncfusion.EJ2.Blazor.DropDowns

<EjsComboBox TValue="string" ModelType="@Data" Placeholder="Select a customer" Query="@Query">
    <ComboBoxTemplates>
        <ItemTemplate>
            <span><span class='name'>@((context as EmployeeData).FirstName)</span><span class='country'>@((context as EmployeeData).Country)</span></span>
        </ItemTemplate>
    </ComboBoxTemplates>
    <EjsDataManager Url="https://ej2services.syncfusion.com/production/web-services/api/Employees" Adaptor="Adaptors.WebApiAdaptor" CrossDomain=true></EjsDataManager>
    <ComboBoxFieldSettings Text="FirstName" Value="Country"></ComboBoxFieldSettings>
</EjsComboBox>

@code {
    public class EmployeeData
    {
        public string FirstName { get; set; }
        public string Country { get; set; }
    }
    public EmployeeData Data = new EmployeeData();
    public string Query = "new ej.data.Query().select(['FirstName', 'Country']).take(6).requiresCount()";
}

<style>
    .country {
        right: 15px;
        position: absolute;
    }
</style>

The output will be as follows.

ComboBox

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 country.

@using Syncfusion.EJ2.Blazor.Data
@using Syncfusion.EJ2.Blazor.DropDowns

<EjsComboBox TValue="string" ModelType="@Data" Placeholder="Select a customer" Query="@Query">
    <ComboBoxTemplates>
        <GroupTemplate>
            <span class="group">@((context as EmployeeData).Country)</span>
        </GroupTemplate>
    </ComboBoxTemplates>
    <EjsDataManager Url="https://ej2services.syncfusion.com/production/web-services/api/Employees" Adaptor="Adaptors.WebApiAdaptor" CrossDomain=true></EjsDataManager>
    <ComboBoxFieldSettings Value="FirstName" GroupBy="Country"></ComboBoxFieldSettings>
</EjsComboBox>

@code {

    public class EmployeeData
    {
        public string FirstName { get; set; }
        public string Country { get; set; }
    }

    public EmployeeData Data = new EmployeeData();
    public string Query = "new ej.data.Query().select(['FirstName', 'Country']).take(6).requiresCount()";
}

<style>
    .group {
        color: slategrey;
    }
</style>

The output will be as follows.

ComboBox

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.

@using Syncfusion.EJ2.Blazor.Data
@using Syncfusion.EJ2.Blazor.DropDowns

<EjsComboBox TValue="string" ModelType="@Data" Placeholder="Select a customer" Query="@Query">
    <ComboBoxTemplates>
        <ItemTemplate>
            <span class='item'><span class='name'>@((context as EmployeeData).FirstName)</span><span class='city'>@((context as EmployeeData).Country)</span></span>
        </ItemTemplate>
        <HeaderTemplate>
            <span class='head'><span class='name'>Name</span><span class='city'>Country</span></span>
        </HeaderTemplate>
    </ComboBoxTemplates>
    <EjsDataManager Url="https://ej2services.syncfusion.com/production/web-services/api/Employees" Adaptor="Adaptors.WebApiAdaptor" CrossDomain=true></EjsDataManager>
    <ComboBoxFieldSettings Value="Country" Text="FirstName" ></ComboBoxFieldSettings>
</EjsComboBox>

@code {
    public class EmployeeData
    {
        public string FirstName { get; set; }
        public string Country { get; set; }
    }
    public EmployeeData Data = new EmployeeData();
    public string Query = "new ej.data.Query().select(['FirstName', 'Country']).take(6).requiresCount()";
}

<style>
    .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;
    }
</style>

The output will be as follows.

ComboBox

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 the FooterTemplate property.

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

@using Syncfusion.EJ2.Blazor.Data
@using Syncfusion.EJ2.Blazor.DropDowns

<EjsComboBox TValue="string" ModelType="@Data" Query="@Query" Placeholder="Select a customer">
    <ComboBoxTemplates>
        <FooterTemplate>
            <span class='footer'>Total list Item: 6 </span>
        </FooterTemplate>
    </ComboBoxTemplates>
    <EjsDataManager Url="https://ej2services.syncfusion.com/production/web-services/api/Employees" Adaptor="Adaptors.WebApiAdaptor" CrossDomain=true></EjsDataManager>
    <ComboBoxFieldSettings Value="Country" Text="FirstName"></ComboBoxFieldSettings>
</EjsComboBox>

@code {

    public class EmployeeData
    {
        public string FirstName { get; set; }
    }
    public EmployeeData Data = new EmployeeData();
    public string Query = "new ej.data.Query().select(['FirstName', 'Country']).take(6).requiresCount()";
}

<style>
    .footer {
        text-indent: 1.2em;
        display: block;
        font-size: 15px;
        line-height: 40px;
        border-top: 1px solid #e0e0e0;
    }
</style>

The output will be as follows.

ComboBox

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.

@using Syncfusion.EJ2.Blazor.DropDowns

<EjsComboBox TValue="string" ModelType="@Data" Placeholder="Select a customer" DataSource="@Country">
    <ComboBoxTemplates>
        <NoRecordsTemplate>
            <span class='norecord'> NO DATA AVAILABLE</span>
        </NoRecordsTemplate>
    </ComboBoxTemplates>
</EjsComboBox>

@code {
public class EmployeeData { }
public EmployeeData Data = new EmployeeData();

public class Countries{ }

List<Countries> Country = new List<Countries>{ };
}

The output will be as follows.

ComboBox

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.

@using Syncfusion.EJ2.Blazor.Data
@using Syncfusion.EJ2.Blazor.DropDowns

<EjsComboBox TValue="string" ModelType="@Data" Placeholder="Select a customer" Query="@Query">
    <ComboBoxTemplates>
        <ActionFailureTemplate>
            <span class='norecord'>Data fetch get fails </span>
        </ActionFailureTemplate>
    </ComboBoxTemplates>
    <EjsDataManager Url="https://services.odata.org/V4/Northwind/Northwind.svcs/Employees" Adaptor="Adaptors.ODataV4Adaptor" CrossDomain=true></EjsDataManager>
    <ComboBoxFieldSettings Value="Country" Text="FirstName"></ComboBoxFieldSettings>
</EjsComboBox>

@code {
    public class EmployeeData
    {
        public string FirstName { get; set; }
    }
    public EmployeeData Data = new EmployeeData();
    public string Query = "new ej.data.Query().select(['FirstName', 'Country']).take(6).requiresCount()";
}

The output will be as follows.

ComboBox