Sorting datasource in Mention

7 Nov 20223 minutes to read

Sort order type

You can display the suggestion list items in a specific order. It has possible types as Ascending, Descending, and None in the SortOrder property.

  • None - The data source is not sorted.
  • Ascending - The data source is sorted in ascending order.
  • Descending - The data source is sorted in descending order.
@model List<string>
@{
    char nameMentionChar = '@';
    List<SportsData> data = new SportsData().SportsList();
}
<div id="mentionElement" placeholder="Type @Html.Raw("mention") and tag sport"></div>

@Html.EJS().Mention("Sorting").MentionChar(nameMentionChar).Target("#mentionElement").Fields(new Syncfusion.EJ2.DropDowns.MentionFieldSettings { Text = "Game" , Value = "ID" }).DataSource((IEnumerable<object>)data).SortOrder(Syncfusion.EJ2.DropDowns.SortOrder.Descending).Render()

<style>

    div#mentionElement[placeholder]:empty:before {
        content: attr(placeholder);
    }

    #mentionElement{
        min-height: 100px; 
        border: 1px solid #D7D7D7;
        border-radius: 4px; 
        padding: 8px; 
        font-size: 14px; 
        width: 600px;
    }
    
</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication1.Models
{
    public class SportsData
    {
        public string ID { get; set; }
        public string Game { get; set; }
        public List<SportsData> SportsList()
        {
            List<SportsData> sports = new List<SportsData>()
            {
                new SportsData { ID = "game1", Game = "Badminton" },
                new SportsData { ID = "game2", Game = "Football" },
                new SportsData { ID = "game3", Game = "Tennis" },
                new SportsData { ID = "game4", Game = "Hockey" },
                new SportsData { ID = "game5", Game = "Basketball" },
            };
            return sports;
        }
    }
}

ASP.NET MVC Mention sorting