Search results

Sorting in JavaScript Mention control

25 Jan 2023 / 1 minute to read

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.
Source
Preview
app.ts
index.html
Copied to clipboard
import { Mention } from '@syncfusion/ej2-dropdowns';

// defined the array of complex data
let sportsData: { [key: string]: Object }[] = [
{ ID: 'game1', Game: 'Badminton' },
{ ID: 'game2', Game: 'Football' },
{ ID: 'game3', Game: 'Tennis' },
{ ID: 'game4', Game: 'Hockey' },
{ ID: 'game5', Game: 'Basketball' }
];

//initiates the control
let mentionObject: Mention = new Mention({
//set the data to dataSource property
dataSource: sportsData,
// maps the appropriate column to fields property
fields: { text: 'Game', value: 'ID' },
//sort the resulted items
sortOrder: 'Descending'
});

//render the control
mentionObject.appendTo('#mentionElement');
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
            
    <title>Essential JS 2 Mention</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="styles.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.4.38/ej2-base/styles/bootstrap5.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.4.38/ej2-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.4.38/ej2-dropdowns/styles/bootstrap5.css" rel="stylesheet" />
    <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='loader'>LOADING....</div>
    <div id='container' style="width:200px;">
        <!--element which is the Mention target to list the suggestions-->
        <label style="font-size: 15px; font-weight: 600;">Comments</label>
        <div id="mentionElement" style="min-height: 100px; border: 1px solid #D7D7D7; border-radius: 4px; padding: 8px; font-size: 14px; width: 600px;"></div>
    </div>
</body>

</html>