Search results

Templates

The MultiSelect has been provided with several options to customize each list item, group title, selected value, header, and footer elements. It uses the Essential JS 2 Template engine to compile and render the elements properly.

Item template

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.

tagHelper
itemtemplate.cs
<div class="col-lg-12 control-section" style="height: 400px;">
    <div class='control-wrapper' style="margin: 0 auto;width:300px;">
       <ejs-multiselect id="template" query="new ej.data.Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6)" placeholder="Select an employees" popupHeight="270px"
                        itemTemplate="@Html.Raw("<div><span class='name'>${FirstName}</span><span class ='city'>${City}</span></div>")"
                        mode="Box">
            <e-multiselect-fields value="OrderID" text="CustomerID"></e-multiselect-fields>
            <e-datamanager url="http://services.odata.org/V4/Northwind/Northwind.svc/" adaptor="ODataV4Adaptor" crossDomain="true"></e-datamanager>

        </ejs-multiselect>
    </div>
</div>

<style>
    #container {
    visibility: hidden;
}

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

.name {
    float: left
}

.city {
    float: right
}
</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class MultiSelectController : Controller
    {
        public IActionResult Itemtemplate()
        {
            return View();
        }       
    }
}

Value template

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.

tagHelper
valuetemplate.cs
<div class="col-lg-12 control-section" style="height: 400px;">
    <div class='control-wrapper' style="margin: 0 auto;width:300px;">
        <ejs-multiselect id="template" query="new ej.data.Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6)" placeholder="Select an employees" popupHeight="270px"
                       itemTemplate="@Html.Raw("<div><span class='name'>${FirstName}</span><span class ='city'>${City}</span></div>")"
                        valueTemplate="@Html.Raw("<div><span class='name'>${FirstName}</span><span class ='city'>${City}</span></div>")"
                        mode="Box">
            <e-multiselect-fields value="EmployeeID" text="FirstName"></e-multiselect-fields>
            <e-datamanager url="http://services.odata.org/V4/Northwind/Northwind.svc/" adaptor="ODataV4Adaptor" crossDomain="true"></e-datamanager>

        </ejs-multiselect>
    </div>
</div>
<style>
    #container {
    visibility: hidden;
}

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

.name {
    float: left
}

.city {
    float: right
}
</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class MultiSelectController : Controller
    {
        public IActionResult valuetemplate()
        {
            return View();
        }       
    }
}

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.

tagHelper
grouptemplate.cs
<div class="col-lg-12 control-section" style="height: 400px;">
    <div class='control-wrapper' style="margin: 0 auto;width:300px;">
            <ejs-multiselect id="template" query="new ej.data.Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(5).where(new ej.data.Predicate('City', 'equal','london').or('City','equal','seattle'))" placeholder="Select an employees" popupHeight="270px"
                 groupTemplate="@Html.Raw("<strong>${City}</strong>")"
                        mode="Box">
            <e-multiselect-fields groupBy="City" value="EmployeeID" text="FirstName"></e-multiselect-fields>
            <e-datamanager url="http://services.odata.org/V4/Northwind/Northwind.svc/" adaptor="ODataV4Adaptor" crossDomain="true"></e-datamanager>

        </ejs-multiselect>
    </div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class MultiSelectController : Controller
    {
        public IActionResult grouptemplate()
        {
            return View();
        }       
    }
}

Header template

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.

tagHelper
headertemplate.cs
<div class="col-lg-12 control-section" style="height: 400px;">
    <div class='control-wrapper' style="margin: 0 auto;width:300px;">
        <ejs-multiselect id="template" query="new ej.data.Query().from('Employees').select(['FirstName', 'City', 'EmployeeID']).take(6)" placeholder="Select an employees" popupHeight="270px"
                        headerTemplate="@Html.Raw("<span class='head'><span class='name'>Name</span><span class='city'>City</span></span>")"
                        itemTemplate="@Html.Raw("<span class='item' ><span class='name'>${FirstName}</span><span class='city'>${City}</span></span>")"
                        mode="Box">
            <e-multiselect-fields value="EmployeeID" text="FirstName"></e-multiselect-fields>
            <e-datamanager url="http://services.odata.org/V4/Northwind/Northwind.svc/" adaptor="ODataV4Adaptor" crossDomain="true"></e-datamanager>

        </ejs-multiselect>
    </div>
</div>
<style>
    #container {
  visibility: hidden;
}

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

.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>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class MultiSelectController : Controller
    {
        public IActionResult headertemplate()
        {
            return View();
        }       
    }
}

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.

tagHelper
footertemplate.cs
<ejs-multiselect id="template" dataSource="@ViewBag.data" placeholder="Select games" popupHeight="270px"
                footerTemplate="@Html.Raw("<span class='foot'> Total list items: " + 4 + "</span>")"
                mode="Box">
</ejs-multiselect>

<style>
    #container {
  visibility: hidden;
}

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

.foot{
    text-indent: 1.2em;
    display: block;
    font-size: 15px;
    line-height: 40px;
    border-top: 1px solid #e0e0e0;
}
</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class MultiSelectController : Controller
    {
        public IActionResult footertemplate()
        {
            ViewBag.data = new string[] { "Badminton", "Basketball", "Cricket", "Football"" };
            return View();
        }
    }
}

No records template

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.

tagHelper
norecordstemplate.cs
<div>
    <ejs-multiselect id="games" dataSource="@ViewBag.data" placeholder="Favorite Sports" noRecordsTemplate="@Html.Raw("<span class='norecord'> NO DATA AVAILABLE</span>")" mode="Default">
        <e-multiselect-fields value="id" text="sports"></e-multiselect-fields>
    </ejs-multiselect>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class MultiSelectController : Controller
    {
        public IActionResult norecords()
        {
            ViewBag.data = new string[] { };
            return View();
        }
    }
}

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 MultiSelect displays the notification.

tagHelper
actionfailuretemplate.cs
<div class="col-lg-12 control-section" style="height: 400px;">
    <div class='control-wrapper' style="margin: 0 auto;width:300px;">
        <ejs-multiselect id="template" query="new ej.data.Query().from('Employees').select(['FirstName']).take(6)" placeholder="Select an employees" popupHeight="270px"
                        actionFailureTemplate="@Html.Raw("<span class='action-failure'> Data fetch get fails</span>")"
                        mode="Box">
            <e-multiselect-fields value="EmployeeID" text="FirstName"></e-multiselect-fields>
            <e-datamanager url="http://services.odata.org/V4/Northwind/Northwind.svcs/" adaptor="ODataV4Adaptor" crossDomain="true"></e-datamanager>

        </ejs-multiselect>
    </div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class MultiSelectController : Controller
    {
        public IActionResult actionfailure()
        {
            return View();
        }
    }
}